1 /* This file is part of the KDE project
2    Copyright (C) 2005-2017 Jarosław Staniek <staniek@kde.org>
3 
4    This library is free software; you can redistribute it and/or
5    modify it under the terms of the GNU Library General Public
6    License as published by the Free Software Foundation; either
7    version 2 of the License, or (at your option) any later version.
8 
9    This library is distributed in the hope that it will be useful,
10    but WITHOUT ANY WARRANTY; without even the implied warranty of
11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12    Library General Public License for more details.
13 
14    You should have received a copy of the GNU Library General Public License
15    along with this library; see the file COPYING.LIB.  If not, write to
16    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  * Boston, MA 02110-1301, USA.
18 */
19 #ifndef KEXIDATASOURCEPAGE_H
20 #define KEXIDATASOURCEPAGE_H
21 
22 #include "kexiformutils_export.h"
23 #include <config-kexi.h>
24 #include <widget/properties/KexiPropertyPaneViewBase.h>
25 
26 #include <KDbField>
27 #include <KDbUtils>
28 #include <KDbTableOrQuerySchema>
29 
30 #include <KPropertySet>
31 
32 class KexiDataSourceComboBox;
33 class KexiFieldComboBox;
34 class KexiFieldListView;
35 class KexiProject;
36 class QToolButton;
37 class QLabel;
38 
39 //! A page within form designer's property tabbed pane, providing data source editor
40 class KEXIFORMUTILS_EXPORT KexiDataSourcePage : public KexiPropertyPaneViewBase
41 {
42     Q_OBJECT
43 
44 public:
45     explicit KexiDataSourcePage(QWidget *parent);
46     virtual ~KexiDataSourcePage();
47 
48     //! @return name plugin ID of selected item (usually a table or a query). Can return an empty string.
49     QString selectedPluginId() const;
50 
51     //! @return name of selected table or query.
52     QString selectedName() const;
53 
54 public Q_SLOTS:
55     void setProject(KexiProject *prj);
56     void clearFormDataSourceSelection(bool alsoClearComboBox = true);
57     void clearWidgetDataSourceSelection();
58 
59     //! Sets data source of a currently selected form.
60     //! This is performed on form initialization and on activating.
61     void setFormDataSource(const QString& pluginId, const QString& name);
62 
63     //! Receives a pointer to a new property \a set (from KexiFormView::managerPropertyChanged())
64     void assignPropertySet(KPropertySet* propertySet);
65 
66 Q_SIGNALS:
67     //! Signal emitted when helper button 'go to selected data source' is clicked.
68     void jumpToObjectRequested(const QString& mime, const QString& name);
69 
70     //! Signal emitted when form's data source has been changed. It's connected to the Form Manager.
71     void formDataSourceChanged(const QString& mime, const QString& name);
72 
73     /*! Signal emitted when current widget's data source (field/expression)
74      has been changed. It's connected to the Form Manager.
75      \a caption for this field is also provided (e.g. AutoField form widget use it) */
76     void dataSourceFieldOrExpressionChanged(const QString& string, const QString& caption,
77                                             KDbField::Type type);
78 
79     /*! Signal emitted when 'insert fields' button has been clicked */
80     void insertAutoFields(const QString& sourcePartClass, const QString& sourceName,
81                           const QStringList& fields);
82 
83 protected Q_SLOTS:
84     void slotWidgetDataSourceTextChanged(const QString &text);
85     void slotFormDataSourceTextChanged(const QString &text);
86     void slotFormDataSourceChanged();
87     void slotFieldSelected();
88     void slotGotoSelected();
89     void slotInsertSelectedFields();
90     void slotFieldListViewSelectionChanged();
91     void slotFieldDoubleClicked(const QString& sourcePluginId, const QString& sourceName,
92                                 const QString& fieldName);
93 
94 protected:
95     void updateSourceFieldWidgetsAvailability();
96 
97     KexiFieldComboBox *m_widgetDataSourceCombo;
98     QWidget *m_widgetDataSourceComboSpacer;
99     KexiDataSourceComboBox* m_formDataSourceCombo;
100     QWidget *m_formDataSourceComboSpacer;
101     QLabel *m_dataSourceLabel, *m_noDataSourceAvailableLabel, *m_widgetDSLabel;
102     QToolButton *m_gotoButton;
103     QString m_noDataSourceAvailableSingleText;
104     QString m_noDataSourceAvailableMultiText;
105     bool m_insideClearFormDataSourceSelection;
106 #ifdef KEXI_AUTOFIELD_FORM_WIDGET_SUPPORT
107     KexiFieldListView* m_availableFieldsLabel;
108     KexiFieldListView* m_fieldListView;
109     QLabel *m_mousePointerLabel;
110     QLabel *m_availableFieldsDescriptionLabel;
111     QToolButton *m_addField;
112 #else
113     KDbTableOrQuerySchema *m_tableOrQuerySchema; //!< temp.
114 #endif
115 
116     //! Used only in assignPropertySet() to check whether we already have the set assigned
117     QString m_currentObjectName;
118 };
119 
120 #endif
121