1 /* This file is part of the KDE project 2 Copyright (C) 2002, 2003 Lucijan Busch <lucijan@gmx.at> 3 Copyright (C) 2005-2008 Jarosław Staniek <staniek@kde.org> 4 5 This library is free software; you can redistribute it and/or 6 modify it under the terms of the GNU Library General Public 7 License as published by the Free Software Foundation; either 8 version 2 of the License, or (at your option) any later version. 9 10 This library is distributed in the hope that it will be useful, 11 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 Library General Public License for more details. 14 15 You should have received a copy of the GNU Library General Public License 16 along with this library; see the file COPYING.LIB. If not, write to 17 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 18 * Boston, MA 02110-1301, USA. 19 */ 20 21 #ifndef KEXIPARTITEM_H 22 #define KEXIPARTITEM_H 23 24 #include "kexicore_export.h" 25 #include <kexi_global.h> 26 27 #include <QString> 28 #include <QHash> 29 30 namespace KexiPart 31 { 32 33 class Info; 34 35 /*! 36 @short Information about a single object that can be instantiated using Kexi Part 37 38 KexiPart::Item stores: 39 - identifier (low-level name, for example: table name) 40 - part class, eg. "org.kexi-project.table" 41 - caption (visible, i18n'd hight level name, eg. table or query title) 42 */ 43 class KEXICORE_EXPORT Item 44 { 45 public: 46 Item(); 47 ~Item(); 48 identifier()49 int identifier() const { 50 return m_id; 51 } setIdentifier(int id)52 void setIdentifier(int id) { 53 m_id = id; 54 } 55 pluginId()56 QString pluginId() const { 57 return m_class; 58 } setPluginId(const QString & _class)59 void setPluginId(const QString &_class) { 60 m_class = _class; 61 } 62 name()63 QString name() const { 64 return m_name; 65 } setName(const QString & name)66 void setName(const QString &name) { 67 m_name = name; 68 } 69 caption()70 QString caption() const { 71 return m_caption; 72 } setCaption(const QString & c)73 void setCaption(const QString &c) { 74 m_caption = c; 75 } 76 description()77 QString description() const { 78 return m_desc; 79 } setDescription(const QString & d)80 void setDescription(const QString &d) { 81 m_desc = d; 82 } 83 84 /*! \return "neverSaved" flag for this item what mean 85 that is used when new item is created in-memory-only, 86 so we need to indicate for KexiProject about that state. 87 By default this flag is false. 88 Used by KexiMainWindow::newObject(). */ neverSaved()89 bool neverSaved() const { 90 return m_neverSaved; 91 } 92 93 /*! \sa neverSaved(). 94 Used by KexiMainWindow::newObject(). */ setNeverSaved(bool set)95 void setNeverSaved(bool set) { 96 m_neverSaved = set; 97 } 98 isNull()99 bool isNull() const { 100 return m_id == 0; 101 } 102 103 //! \return caption if not empty, else returns name. captionOrName()104 inline QString captionOrName() const { 105 return m_caption.isEmpty() ? m_name : m_caption; 106 } 107 108 private: 109 QString m_class; 110 QString m_name; 111 QString m_caption; 112 QString m_desc; 113 int m_id; 114 bool m_neverSaved; 115 116 class Private; 117 Private * const d; 118 }; 119 120 //! Item dict which destroys KexiPart::Item items on destruction. 121 class KEXICORE_EXPORT ItemDict : public QHash<int, KexiPart::Item*> 122 { 123 public: 124 ItemDict(); 125 ~ItemDict(); 126 }; 127 128 typedef QList<KexiPart::Item*>::iterator ItemListIterator; 129 130 /*! 131 @short Part item list with special sorting method (by item name). 132 133 Such a list is returned by KexiProject::getSortedItems(KexiPart::ItemList *list, KexiPart::Info *i); 134 so you can call sort() on the list to sort it by item name. 135 */ 136 class KEXICORE_EXPORT ItemList : public QList<KexiPart::Item*> 137 { 138 public: 139 ItemList(); 140 141 //! Sorts the list by item names. 142 void sort(); 143 }; 144 145 } 146 147 #endif 148