File indexing completed on 2024-05-12 16:39:38

0001 /* This file is part of the KDE project
0002    Copyright (C) 2002, 2003 Lucijan Busch <lucijan@gmx.at>
0003    Copyright (C) 2005-2008 Jarosław Staniek <staniek@kde.org>
0004 
0005    This library is free software; you can redistribute it and/or
0006    modify it under the terms of the GNU Library General Public
0007    License as published by the Free Software Foundation; either
0008    version 2 of the License, or (at your option) any later version.
0009 
0010    This library is distributed in the hope that it will be useful,
0011    but WITHOUT ANY WARRANTY; without even the implied warranty of
0012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0013    Library General Public License for more details.
0014 
0015    You should have received a copy of the GNU Library General Public License
0016    along with this library; see the file COPYING.LIB.  If not, write to
0017    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0018  * Boston, MA 02110-1301, USA.
0019 */
0020 
0021 #ifndef KEXIPARTITEM_H
0022 #define KEXIPARTITEM_H
0023 
0024 #include "kexicore_export.h"
0025 #include <kexi_global.h>
0026 
0027 #include <QString>
0028 #include <QHash>
0029 
0030 namespace KexiPart
0031 {
0032 
0033 class Info;
0034 
0035 /*!
0036  @short Information about a single object that can be instantiated using Kexi Part
0037 
0038  KexiPart::Item stores:
0039   - identifier (low-level name, for example: table name)
0040   - part class, eg. "org.kexi-project.table"
0041   - caption (visible, i18n'd hight level name, eg. table or query title)
0042 */
0043 class KEXICORE_EXPORT Item
0044 {
0045 public:
0046     Item();
0047     ~Item();
0048 
0049     int identifier() const {
0050         return m_id;
0051     }
0052     void setIdentifier(int id) {
0053         m_id = id;
0054     }
0055 
0056     QString pluginId() const {
0057         return m_class;
0058     }
0059     void setPluginId(const QString &_class) {
0060         m_class = _class;
0061     }
0062 
0063     QString name() const {
0064         return m_name;
0065     }
0066     void setName(const QString &name) {
0067         m_name = name;
0068     }
0069 
0070     QString caption() const {
0071         return m_caption;
0072     }
0073     void setCaption(const QString &c) {
0074         m_caption = c;
0075     }
0076 
0077     QString description() const {
0078         return m_desc;
0079     }
0080     void setDescription(const QString &d) {
0081         m_desc = d;
0082     }
0083 
0084     /*! \return "neverSaved" flag for this item what mean
0085      that is used when new item is created in-memory-only,
0086      so we need to indicate for KexiProject about that state.
0087      By default this flag is false.
0088      Used by KexiMainWindow::newObject(). */
0089     bool neverSaved() const {
0090         return m_neverSaved;
0091     }
0092 
0093     /*! \sa neverSaved().
0094      Used by KexiMainWindow::newObject(). */
0095     void setNeverSaved(bool set) {
0096         m_neverSaved = set;
0097     }
0098 
0099     bool isNull() const {
0100         return m_id == 0;
0101     }
0102 
0103     //! \return caption if not empty, else returns name.
0104     inline QString captionOrName() const {
0105         return m_caption.isEmpty() ? m_name : m_caption;
0106     }
0107 
0108 private:
0109     QString m_class;
0110     QString m_name;
0111     QString m_caption;
0112     QString m_desc;
0113     int m_id;
0114     bool m_neverSaved;
0115 
0116     class Private;
0117     Private * const d;
0118 };
0119 
0120 //! Item dict which destroys KexiPart::Item items on destruction.
0121 class KEXICORE_EXPORT ItemDict : public QHash<int, KexiPart::Item*>
0122 {
0123 public:
0124     ItemDict();
0125     ~ItemDict();
0126 };
0127 
0128 typedef QList<KexiPart::Item*>::iterator ItemListIterator;
0129 
0130 /*!
0131  @short Part item list with special sorting method (by item name).
0132 
0133  Such a list is returned by KexiProject::getSortedItems(KexiPart::ItemList *list, KexiPart::Info *i);
0134  so you can call sort() on the list to sort it by item name.
0135 */
0136 class KEXICORE_EXPORT ItemList : public QList<KexiPart::Item*>
0137 {
0138 public:
0139     ItemList();
0140 
0141     //! Sorts the list by item names.
0142     void sort();
0143 };
0144 
0145 }
0146 
0147 #endif