File indexing completed on 2024-05-12 16:40:53

0001 /* This file is part of the KDE project
0002    Copyright (C) 2005-2016 Jarosław Staniek <staniek@kde.org>
0003 
0004    This library is free software; you can redistribute it and/or
0005    modify it under the terms of the GNU Library General Public
0006    License as published by the Free Software Foundation; either
0007    version 2 of the License, or (at your option) any later version.
0008 
0009    This library is distributed in the hope that it will be useful,
0010    but WITHOUT ANY WARRANTY; without even the implied warranty of
0011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0012    Library General Public License for more details.
0013 
0014    You should have received a copy of the GNU Library General Public License
0015    along with this library; see the file COPYING.LIB.  If not, write to
0016    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0017  * Boston, MA 02110-1301, USA.
0018 */
0019 
0020 #ifndef KEXIDATASOURCECOMBOBOX_H
0021 #define KEXIDATASOURCECOMBOBOX_H
0022 
0023 #include "kexiextwidgets_export.h"
0024 #include <KComboBox>
0025 
0026 class KexiProject;
0027 namespace KexiPart
0028 {
0029 class Item;
0030 }
0031 
0032 /**
0033  * A combo box listing availabe data sources (tables and queries)
0034  * with icons. "Define query..." item can be also prepended.
0035  */
0036 class KEXIEXTWIDGETS_EXPORT KexiDataSourceComboBox : public KComboBox
0037 {
0038     Q_OBJECT
0039 
0040 public:
0041     explicit KexiDataSourceComboBox(QWidget *parent = 0);
0042     virtual ~KexiDataSourceComboBox();
0043 
0044     //! \return global project that is used to retrieve schema informationm for this combo box.
0045     KexiProject* project() const;
0046 
0047     //! \return name plugin ID of selected item (usually a table or a query). Can return an empty string.
0048     //! You should use isSelectionValid() to check validity of the input.
0049     QString selectedPluginId() const;
0050 
0051     //! \return name of selected table or query. Can return an empty string or nonexisting name,
0052     //! so you should use isSelectionValid() to check validity of the input.
0053     QString selectedName() const;
0054 
0055     //! \return true if current selection is valid
0056     bool isSelectionValid() const;
0057 
0058     /*! \return index of item identified by a plugin ID \a pluginId and name \a name.
0059      Returs -1 of no such item exists. */
0060     int findItem(const QString& pluginId, const QString& name);
0061 
0062 public Q_SLOTS:
0063     //! Sets global project that is used to retrieve schema informationm for this combo box.
0064     //! Tables visibility can be set using \a showTables queries visibility using \a showQueries.
0065     void setProject(KexiProject *prj, bool showTables = true, bool showQueries = true);
0066 
0067     /*! Sets item for data source described by \a pluginId and \a name.
0068      If \a pluginId is empty, either "org.kexi-project.table" and "org.kexi-project.query" are tried. */
0069     void setDataSource(const QString& pluginId, const QString& name);
0070 
0071 Q_SIGNALS:
0072     //! Emitted whenever data source changes.
0073     //! Even setting invalid data source or clearing it will emit this signal.
0074     void dataSourceChanged();
0075 
0076 protected Q_SLOTS:
0077     void slotNewItemStored(KexiPart::Item* item);
0078     void slotItemRemoved(const KexiPart::Item& item);
0079     void slotItemRenamed(const KexiPart::Item& item, const QString& oldName);
0080     void slotActivated(int index);
0081     void slotReturnPressed(const QString & text);
0082     void slotTextChanged(const QString &text);
0083 
0084 protected:
0085     virtual void focusOutEvent(QFocusEvent *e) override;
0086 
0087     class Private;
0088     Private * const d;
0089 };
0090 
0091 #endif