Changeset View
Changeset View
Standalone View
Standalone View
src/plugins/forms/kexidatasourcepage.cpp
Show All 13 Lines | 1 | /* This file is part of the KDE project | |||
---|---|---|---|---|---|
14 | You should have received a copy of the GNU Library General Public License | 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 | 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, | 16 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
17 | * Boston, MA 02110-1301, USA. | 17 | * Boston, MA 02110-1301, USA. | ||
18 | */ | 18 | */ | ||
19 | 19 | | |||
20 | #include "kexidatasourcepage.h" | 20 | #include "kexidatasourcepage.h" | ||
21 | #include <KexiIcon.h> | 21 | #include <KexiIcon.h> | ||
22 | #include <KexiStyle.h> | ||||
22 | #include <config-kexi.h> | 23 | #include <config-kexi.h> | ||
23 | #include <widget/properties/KexiPropertyEditorView.h> | 24 | #include <widget/properties/KexiObjectInfoWidget.h> | ||
24 | #include <widget/KexiObjectInfoLabel.h> | | |||
25 | #include <widget/KexiDataSourceComboBox.h> | 25 | #include <widget/KexiDataSourceComboBox.h> | ||
26 | #include <widget/fields/KexiFieldListView.h> | 26 | #include <widget/fields/KexiFieldListView.h> | ||
27 | #include <widget/fields/KexiFieldComboBox.h> | 27 | #include <widget/fields/KexiFieldComboBox.h> | ||
28 | #include <kexiutils/SmallToolButton.h> | 28 | #include <kexiutils/SmallToolButton.h> | ||
29 | #include <kexiutils/KexiFadeWidgetEffect.h> | 29 | #include <kexiutils/KexiFadeWidgetEffect.h> | ||
30 | #include <kexiutils/utils.h> | 30 | #include <kexiutils/utils.h> | ||
31 | #include <kexiproject.h> | 31 | #include <kexiproject.h> | ||
32 | #include <formeditor/commands.h> | 32 | #include <formeditor/commands.h> | ||
33 | 33 | | |||
34 | #include <KDbConnection> | 34 | #include <KDbConnection> | ||
35 | 35 | | |||
36 | #include <KProperty> | 36 | #include <KProperty> | ||
37 | 37 | | |||
38 | #include <KLocalizedString> | 38 | #include <KLocalizedString> | ||
39 | 39 | | |||
40 | #include <QLabel> | 40 | #include <QLabel> | ||
41 | #include <QLineEdit> | 41 | #include <QLineEdit> | ||
42 | #include <QHBoxLayout> | 42 | #include <QHBoxLayout> | ||
43 | #include <QVBoxLayout> | ||||
44 | #include <QGridLayout> | ||||
43 | 45 | | |||
44 | KexiDataSourcePage::KexiDataSourcePage(QWidget *parent) | 46 | KexiDataSourcePage::KexiDataSourcePage(QWidget *parent) | ||
45 | : KexiPropertyPaneViewBase(parent) | 47 | : QWidget(parent) | ||
46 | , m_noDataSourceAvailableSingleText( | 48 | , m_noDataSourceAvailableSingleText( | ||
47 | xi18n("No data source could be assigned for this widget.") ) | 49 | xi18n("[Can't assign to this widget]") ) | ||
48 | , m_noDataSourceAvailableMultiText( | 50 | , m_noDataSourceAvailableMultiText( | ||
49 | xi18n("No data source could be assigned for multiple widgets.") ) | 51 | xi18n("[Can't assign to multiple widgets]") ) | ||
50 | , m_insideClearFormDataSourceSelection(false) | 52 | , m_insideClearFormDataSourceSelection(false) | ||
53 | , m_slotWidgetDataSourceTextChangedEnabled(true) | ||||
51 | #ifndef KEXI_AUTOFIELD_FORM_WIDGET_SUPPORT | 54 | #ifndef KEXI_AUTOFIELD_FORM_WIDGET_SUPPORT | ||
52 | , m_tableOrQuerySchema(0) | 55 | , m_tableOrQuerySchema(0) | ||
53 | #endif | 56 | #endif | ||
54 | { | 57 | { | ||
55 | infoLabel()->setContentsMargins(0, 0, 0, spacing()); | 58 | const KexiStyle::PropertyPane &s = KexiStyle::propertyPane(); | ||
59 | m_mainLyr = s.createVLayout(this); | ||||
56 | 60 | | |||
57 | m_noDataSourceAvailableLabel = new QLabel(m_noDataSourceAvailableSingleText, this); | 61 | s.createTitleLabel(xi18nc("@label Form data source - title", "Data source"), m_mainLyr); | ||
58 | m_noDataSourceAvailableLabel->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Minimum); | | |||
59 | m_noDataSourceAvailableLabel->setContentsMargins(0, 0, 0, spacing()); | | |||
60 | m_noDataSourceAvailableLabel->setAlignment(Qt::AlignBottom | Qt::AlignLeft); | | |||
61 | m_noDataSourceAvailableLabel->setWordWrap(true); | | |||
62 | mainLayout()->addWidget(m_noDataSourceAvailableLabel); | | |||
63 | 62 | | |||
64 | //-Widget's Data Source | 63 | m_formLyr = s.createFormLayout(m_mainLyr); | ||
65 | QHBoxLayout *hlyr = new QHBoxLayout(); | | |||
66 | mainLayout()->addLayout(hlyr); | | |||
67 | #if 0 | | |||
68 | //! @todo unhide this when expression work | | |||
69 | // m_widgetDSLabel = new QLabel(futureI18nc("Table Field, Query Field or Expression", "Source field or expression"), this); | | |||
70 | #else | | |||
71 | m_widgetDSLabel = new QLabel( | | |||
72 | xi18nc("Table Field or Query Field", "Widget's data source:"), this); | | |||
73 | #endif | | |||
74 | m_widgetDSLabel->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed); | | |||
75 | m_widgetDSLabel->setAlignment(Qt::AlignLeft | Qt::AlignBottom); | | |||
76 | hlyr->addWidget(m_widgetDSLabel); | | |||
77 | mainLayout()->addSpacing(KexiUtils::spacingHint()); // needed because unlike m_dataSourceLabel we have no button in hlyr | | |||
78 | | ||||
79 | #if 0 | | |||
80 | m_clearWidgetDSButton = new KexiSmallToolButton( | | |||
81 | koIcon("edit-clear-locationbar-rtl"), QString(), this); | | |||
82 | m_clearWidgetDSButton->setObjectName("clearWidgetDSButton"); | | |||
83 | m_clearWidgetDSButton->setMinimumHeight(m_widgetDSLabel->minimumHeight()); | | |||
84 | m_clearWidgetDSButton->setToolTip(futureI18n("Clear widget's data source")); | | |||
85 | hlyr->addWidget(m_clearWidgetDSButton); | | |||
86 | connect(m_clearWidgetDSButton, SIGNAL(clicked()), | | |||
87 | this, SLOT(clearWidgetDataSourceSelection())); | | |||
88 | #endif | | |||
89 | | ||||
90 | m_widgetDataSourceCombo = new KexiFieldComboBox(this); | | |||
91 | m_widgetDataSourceCombo->setObjectName("sourceFieldCombo"); | | |||
92 | m_widgetDataSourceCombo->setContentsMargins(0, 0, 0, 0); | | |||
93 | m_widgetDSLabel->setBuddy(m_widgetDataSourceCombo); | | |||
94 | connect(m_widgetDataSourceCombo, SIGNAL(editTextChanged(QString)), | | |||
95 | this, SLOT(slotWidgetDataSourceTextChanged(QString))); | | |||
96 | mainLayout()->addWidget(m_widgetDataSourceCombo); | | |||
97 | | ||||
98 | m_widgetDataSourceComboSpacer = addWidgetSpacer(); | | |||
99 | 64 | | |||
100 | //- Form's Data Source | 65 | //- Form's Data Source | ||
101 | hlyr = new QHBoxLayout(); | 66 | //! @todo Port "Go to selected form's data source" | ||
102 | hlyr->setContentsMargins(0, 0, 0, 0); | 67 | #if 0 | ||
103 | mainLayout()->addLayout(hlyr); | | |||
104 | m_dataSourceLabel = new QLabel(xi18n("Form's data source:"), this); | | |||
105 | m_dataSourceLabel->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed); | | |||
106 | m_dataSourceLabel->setAlignment(Qt::AlignLeft | Qt::AlignBottom); | | |||
107 | hlyr->addWidget(m_dataSourceLabel); | | |||
108 | | ||||
109 | m_gotoButton = new KexiSmallToolButton( | 68 | m_gotoButton = new KexiSmallToolButton( | ||
110 | koIcon("go-jump"), QString(), this); | 69 | koIcon("go-jump"), QString(), this); | ||
111 | m_gotoButton->setObjectName("gotoButton"); | 70 | m_gotoButton->setObjectName("gotoButton"); | ||
112 | m_gotoButton->setToolTip(xi18n("Go to selected form's data source")); | 71 | m_gotoButton->setToolTip(xi18n("Go to selected form's data source")); | ||
113 | m_gotoButton->setWhatsThis(xi18n("Goes to selected form's data source")); | 72 | m_gotoButton->setWhatsThis(xi18n("Goes to selected form's data source")); | ||
114 | hlyr->addWidget(m_gotoButton); | 73 | hlyr->addWidget(m_gotoButton); | ||
115 | connect(m_gotoButton, SIGNAL(clicked()), this, SLOT(slotGotoSelected())); | 74 | connect(m_gotoButton, SIGNAL(clicked()), this, SLOT(slotGotoSelected())); | ||
116 | | ||||
117 | #if 0 | | |||
118 | m_clearDSButton = new KexiSmallToolButton( | | |||
119 | koIcon("edit-clear-locationbar-rtl"), QString(), this); | | |||
120 | m_clearDSButton->setObjectName("clearDSButton"); | | |||
121 | m_clearDSButton->setMinimumHeight(m_dataSourceLabel->minimumHeight()); | | |||
122 | m_clearDSButton->setToolTip(futureI18n("Clear form's data source")); | | |||
123 | hlyr->addWidget(m_clearDSButton); | | |||
124 | connect(m_clearDSButton, SIGNAL(clicked()), this, SLOT(clearFormDataSourceSelection())); | | |||
125 | #endif | 75 | #endif | ||
126 | 76 | | |||
127 | m_formDataSourceCombo = new KexiDataSourceComboBox(this); | 77 | m_formDataSourceCombo = new KexiDataSourceComboBox; | ||
128 | m_formDataSourceCombo->setObjectName("dataSourceCombo"); | 78 | m_formDataSourceCombo->setObjectName("dataSourceCombo"); | ||
129 | m_formDataSourceCombo->setContentsMargins(0, 0, 0, 0); | 79 | s.addLabelAndWidget(xi18nc("@label Forms's data source (table or query)", "Form"), | ||
130 | m_dataSourceLabel->setBuddy(m_formDataSourceCombo); | 80 | m_formDataSourceCombo, m_formLyr); | ||
131 | mainLayout()->addWidget(m_formDataSourceCombo); | 81 | | ||
82 | //-Widget's Data Source | ||||
83 | m_widgetDataSourceContainer = new QWidget; | ||||
84 | QVBoxLayout *widgetDataSourceContainerLyr = new QVBoxLayout(m_widgetDataSourceContainer); | ||||
85 | widgetDataSourceContainerLyr->setContentsMargins(0, 0, 0, 0); | ||||
86 | | ||||
87 | m_widgetDataSourceCombo = new KexiFieldComboBox; | ||||
88 | widgetDataSourceContainerLyr->addWidget(m_widgetDataSourceCombo); | ||||
89 | s.alterComboBoxStyle(m_widgetDataSourceCombo); | ||||
90 | m_widgetDataSourceCombo->setObjectName("sourceFieldCombo"); | ||||
91 | connect(m_widgetDataSourceCombo, &KexiFieldComboBox::editTextChanged, | ||||
92 | this, &KexiDataSourcePage::slotWidgetDataSourceTextChanged); | ||||
132 | 93 | | |||
133 | m_formDataSourceComboSpacer = addWidgetSpacer(); | 94 | m_noDataSourceAvailableLabel = s.createWarningLabel(m_noDataSourceAvailableSingleText); | ||
95 | m_noDataSourceAvailableLabel->hide(); | ||||
96 | widgetDataSourceContainerLyr->addWidget(m_noDataSourceAvailableLabel); | ||||
97 | | ||||
98 | s.addLabelAndWidget(xi18nc("@label Widget's data source (table field or query field)", "Widget"), | ||||
99 | m_widgetDataSourceContainer, m_formLyr); | ||||
134 | 100 | | |||
135 | #ifndef KEXI_AUTOFIELD_FORM_WIDGET_SUPPORT | 101 | #ifndef KEXI_AUTOFIELD_FORM_WIDGET_SUPPORT | ||
136 | mainLayout()->addStretch(); | 102 | m_mainLyr->addStretch(); | ||
137 | #else | 103 | #else | ||
138 | //2. Inserting fields | 104 | //2. Inserting fields | ||
139 | 105 | | |||
140 | //helper info | 106 | //helper info | ||
141 | //! @todo allow to hide such helpers by adding global option | 107 | //! @todo allow to hide such helpers by adding global option | ||
142 | hlyr = new QHBoxLayout(); | 108 | hlyr = new QHBoxLayout(); | ||
143 | hlyr->setContentsMargins(0, 0, 0, 0); | 109 | hlyr->setContentsMargins(0, 0, 0, 0); | ||
144 | mainLayout()->addLayout(hlyr); | 110 | m_mainLyr->addLayout(hlyr); | ||
145 | m_mousePointerLabel = new QLabel(this); | 111 | m_mousePointerLabel = new QLabel(this); | ||
146 | hlyr->addWidget(m_mousePointerLabel); | 112 | hlyr->addWidget(m_mousePointerLabel); | ||
147 | m_mousePointerLabel->setPixmap(koIcon("tool-pointer")); | 113 | m_mousePointerLabel->setPixmap(koIcon("tool-pointer")); | ||
148 | m_mousePointerLabel->setFixedWidth(m_mousePointerLabel->pixmap() | 114 | m_mousePointerLabel->setFixedWidth(m_mousePointerLabel->pixmap() | ||
149 | ? m_mousePointerLabel->pixmap()->width() : 0); | 115 | ? m_mousePointerLabel->pixmap()->width() : 0); | ||
150 | m_availableFieldsDescriptionLabel = new QLabel( | 116 | m_availableFieldsDescriptionLabel = new QLabel( | ||
151 | futureI18n("Select fields from the list below and drag them onto" | 117 | futureI18n("Select fields from the list below and drag them onto" | ||
152 | " a form or click the <interface>Insert</interface> button"), this); | 118 | " a form or click the <interface>Insert</interface> button"), this); | ||
153 | m_availableFieldsDescriptionLabel->setAlignment(Qt::AlignLeft); | 119 | m_availableFieldsDescriptionLabel->setAlignment(Qt::AlignLeft); | ||
154 | m_availableFieldsDescriptionLabel->setWordWrap(true); | 120 | m_availableFieldsDescriptionLabel->setWordWrap(true); | ||
155 | hlyr->addWidget(m_availableFieldsDescriptionLabel); | 121 | hlyr->addWidget(m_availableFieldsDescriptionLabel); | ||
156 | 122 | | |||
157 | //Available Fields | 123 | //Available Fields | ||
158 | hlyr = new QHBoxLayout(); | 124 | hlyr = new QHBoxLayout(); | ||
159 | hlyr->setContentsMargins(0, 0, 0, 0); | 125 | hlyr->setContentsMargins(0, 0, 0, 0); | ||
160 | mainLayout()->addLayout(hlyr); | 126 | m_mainLyr->addLayout(hlyr); | ||
161 | m_availableFieldsLabel = new QLabel(futureI18n("Available fields"), this); | 127 | m_availableFieldsLabel = new QLabel(futureI18n("Available fields"), this); | ||
162 | m_availableFieldsLabel->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed); | 128 | m_availableFieldsLabel->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed); | ||
163 | hlyr->addWidget(m_availableFieldsLabel); | 129 | hlyr->addWidget(m_availableFieldsLabel); | ||
164 | 130 | | |||
165 | m_addField = new KexiSmallToolButton( | 131 | m_addField = new KexiSmallToolButton( | ||
166 | KexiIcon("add-field"), futureI18nc("Insert selected field into form", "Insert"), this); | 132 | KexiIcon("add-field"), futureI18nc("Insert selected field into form", "Insert"), this); | ||
167 | m_addField->setObjectName("addFieldButton"); | 133 | m_addField->setObjectName("addFieldButton"); | ||
168 | m_addField->setFocusPolicy(Qt::StrongFocus); | 134 | m_addField->setFocusPolicy(Qt::StrongFocus); | ||
169 | m_addField->setToolTip(futureI18n("Insert selected fields into form")); | 135 | m_addField->setToolTip(futureI18n("Insert selected fields into form")); | ||
170 | m_addField->setWhatsThis(futureI18n("Inserts selected fields into form")); | 136 | m_addField->setWhatsThis(futureI18n("Inserts selected fields into form")); | ||
171 | hlyr->addWidget(m_addField); | 137 | hlyr->addWidget(m_addField); | ||
172 | connect(m_addField, SIGNAL(clicked()), this, SLOT(slotInsertSelectedFields())); | 138 | connect(m_addField, SIGNAL(clicked()), this, SLOT(slotInsertSelectedFields())); | ||
173 | 139 | | |||
174 | m_fieldListView = new KexiFieldListView(this, | 140 | m_fieldListView = new KexiFieldListView(this, | ||
175 | KexiFieldListView::ShowDataTypes | KexiFieldListView::AllowMultiSelection); | 141 | KexiFieldListView::ShowDataTypes | KexiFieldListView::AllowMultiSelection); | ||
176 | m_fieldListView->setObjectName("fieldListView"); | 142 | m_fieldListView->setObjectName("fieldListView"); | ||
177 | m_fieldListView->setSizePolicy(QSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding)); | 143 | m_fieldListView->setSizePolicy(QSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding)); | ||
178 | m_availableFieldsLabel->setBuddy(m_fieldListView); | 144 | m_availableFieldsLabel->setBuddy(m_fieldListView); | ||
179 | mainLayout()->addWidget(m_fieldListView, 1); | 145 | m_mainLyr->addWidget(m_fieldListView, 1); | ||
180 | connect(m_fieldListView, SIGNAL(selectionChanged()), | 146 | connect(m_fieldListView, SIGNAL(selectionChanged()), | ||
181 | this, SLOT(slotFieldListViewSelectionChanged())); | 147 | this, SLOT(slotFieldListViewSelectionChanged())); | ||
182 | connect(m_fieldListView, | 148 | connect(m_fieldListView, | ||
183 | SIGNAL(fieldDoubleClicked(QString,QString,QString)), | 149 | SIGNAL(fieldDoubleClicked(QString,QString,QString)), | ||
184 | this, SLOT(slotFieldDoubleClicked(QString,QString,QString))); | 150 | this, SLOT(slotFieldDoubleClicked(QString,QString,QString))); | ||
185 | #endif | 151 | #endif | ||
186 | 152 | | |||
187 | mainLayout()->addStretch(1); | 153 | m_mainLyr->addStretch(1); | ||
188 | 154 | | |||
189 | connect(m_formDataSourceCombo, SIGNAL(editTextChanged(QString)), | 155 | connect(m_formDataSourceCombo, SIGNAL(editTextChanged(QString)), | ||
190 | this, SLOT(slotFormDataSourceTextChanged(QString))); | 156 | this, SLOT(slotFormDataSourceTextChanged(QString))); | ||
191 | connect(m_formDataSourceCombo, SIGNAL(dataSourceChanged()), | 157 | connect(m_formDataSourceCombo, SIGNAL(dataSourceChanged()), | ||
192 | this, SLOT(slotFormDataSourceChanged())); | 158 | this, SLOT(slotFormDataSourceChanged())); | ||
193 | connect(m_widgetDataSourceCombo, SIGNAL(selected()), | 159 | connect(m_widgetDataSourceCombo, SIGNAL(selected()), | ||
194 | this, SLOT(slotFieldSelected())); | 160 | this, SLOT(slotFieldSelected())); | ||
195 | 161 | | |||
Show All 16 Lines | |||||
212 | 178 | | |||
213 | void KexiDataSourcePage::clearFormDataSourceSelection(bool alsoClearComboBox) | 179 | void KexiDataSourcePage::clearFormDataSourceSelection(bool alsoClearComboBox) | ||
214 | { | 180 | { | ||
215 | if (m_insideClearFormDataSourceSelection) | 181 | if (m_insideClearFormDataSourceSelection) | ||
216 | return; | 182 | return; | ||
217 | m_insideClearFormDataSourceSelection = true; | 183 | m_insideClearFormDataSourceSelection = true; | ||
218 | if (alsoClearComboBox && !m_formDataSourceCombo->selectedName().isEmpty()) | 184 | if (alsoClearComboBox && !m_formDataSourceCombo->selectedName().isEmpty()) | ||
219 | m_formDataSourceCombo->setDataSource(QString(), QString()); | 185 | m_formDataSourceCombo->setDataSource(QString(), QString()); | ||
220 | m_gotoButton->setEnabled(false); | 186 | //! @todo m_gotoButton->setEnabled(false); | ||
221 | m_widgetDataSourceCombo->setFieldOrExpression(QString()); | 187 | m_widgetDataSourceCombo->setFieldOrExpression(QString()); | ||
222 | #ifdef KEXI_AUTOFIELD_FORM_WIDGET_SUPPORT | 188 | #ifdef KEXI_AUTOFIELD_FORM_WIDGET_SUPPORT | ||
223 | m_addField->setEnabled(false); | 189 | m_addField->setEnabled(false); | ||
224 | m_fieldListView->clear(); | 190 | m_fieldListView->clear(); | ||
225 | #endif | 191 | #endif | ||
226 | m_insideClearFormDataSourceSelection = false; | 192 | m_insideClearFormDataSourceSelection = false; | ||
227 | } | 193 | } | ||
228 | 194 | | |||
229 | void KexiDataSourcePage::slotWidgetDataSourceTextChanged(const QString &text) | 195 | void KexiDataSourcePage::slotWidgetDataSourceTextChanged(const QString &text) | ||
230 | { | 196 | { | ||
197 | if (!m_slotWidgetDataSourceTextChangedEnabled) { | ||||
198 | return; | ||||
199 | } | ||||
231 | if (text.isEmpty()) { | 200 | if (text.isEmpty()) { | ||
232 | clearWidgetDataSourceSelection(); | 201 | clearWidgetDataSourceSelection(); | ||
233 | } | 202 | } | ||
234 | } | 203 | } | ||
235 | 204 | | |||
236 | void KexiDataSourcePage::clearWidgetDataSourceSelection() | 205 | void KexiDataSourcePage::clearWidgetDataSourceSelection() | ||
237 | { | 206 | { | ||
238 | m_widgetDataSourceCombo->setFieldOrExpression(QString()); | 207 | m_widgetDataSourceCombo->setFieldOrExpression(QString()); | ||
▲ Show 20 Lines • Show All 63 Lines • ▼ Show 20 Line(s) | 270 | pluginId == "org.kexi-project.table" ? KDbTableOrQuerySchema::Type::Table | |||
302 | : KDbTableOrQuerySchema::Type::Query); | 271 | : KDbTableOrQuerySchema::Type::Query); | ||
303 | if (tableOrQuery->table() || tableOrQuery->query()) { | 272 | if (tableOrQuery->table() || tableOrQuery->query()) { | ||
304 | #ifdef KEXI_AUTOFIELD_FORM_WIDGET_SUPPORT | 273 | #ifdef KEXI_AUTOFIELD_FORM_WIDGET_SUPPORT | ||
305 | m_fieldListView->setSchema(tableOrQuery); | 274 | m_fieldListView->setSchema(tableOrQuery); | ||
306 | #else | 275 | #else | ||
307 | m_tableOrQuerySchema = tableOrQuery; | 276 | m_tableOrQuerySchema = tableOrQuery; | ||
308 | #endif | 277 | #endif | ||
309 | dataSourceFound = true; | 278 | dataSourceFound = true; | ||
279 | m_slotWidgetDataSourceTextChangedEnabled = false; // block clearing widget's data source property | ||||
310 | m_widgetDataSourceCombo->setTableOrQuery(name, pluginId == "org.kexi-project.table"); | 280 | m_widgetDataSourceCombo->setTableOrQuery(name, pluginId == "org.kexi-project.table"); | ||
281 | m_slotWidgetDataSourceTextChangedEnabled = true; | ||||
311 | } else { | 282 | } else { | ||
312 | delete tableOrQuery; | 283 | delete tableOrQuery; | ||
313 | } | 284 | } | ||
314 | } | 285 | } | ||
315 | if (!dataSourceFound) { | 286 | if (!dataSourceFound) { | ||
316 | m_widgetDataSourceCombo->setTableOrQuery(QString(), true); | 287 | m_widgetDataSourceCombo->setTableOrQuery(QString(), true); | ||
317 | } | 288 | } | ||
318 | m_gotoButton->setEnabled(dataSourceFound); | 289 | //! @todo m_gotoButton->setEnabled(dataSourceFound); | ||
319 | if (dataSourceFound) { | 290 | if (dataSourceFound) { | ||
320 | slotFieldListViewSelectionChanged(); | 291 | slotFieldListViewSelectionChanged(); | ||
321 | } else { | 292 | } else { | ||
322 | #ifdef KEXI_AUTOFIELD_FORM_WIDGET_SUPPORT | 293 | #ifdef KEXI_AUTOFIELD_FORM_WIDGET_SUPPORT | ||
323 | m_addField->setEnabled(false); | 294 | m_addField->setEnabled(false); | ||
324 | #endif | 295 | #endif | ||
325 | } | 296 | } | ||
326 | updateSourceFieldWidgetsAvailability(); | 297 | updateSourceFieldWidgetsAvailability(); | ||
Show All 21 Lines | 311 | #endif | |||
348 | ); | 319 | ); | ||
349 | } | 320 | } | ||
350 | 321 | | |||
351 | void KexiDataSourcePage::setFormDataSource(const QString& pluginId, const QString& name) | 322 | void KexiDataSourcePage::setFormDataSource(const QString& pluginId, const QString& name) | ||
352 | { | 323 | { | ||
353 | m_formDataSourceCombo->setDataSource(pluginId, name); | 324 | m_formDataSourceCombo->setDataSource(pluginId, name); | ||
354 | } | 325 | } | ||
355 | 326 | | |||
356 | #define KexiDataSourcePage_FADE 1 | 327 | void KexiDataSourcePage::assignPropertySet(KPropertySet* propertySet, AssignFlags flags) | ||
357 | | ||||
358 | void KexiDataSourcePage::assignPropertySet(KPropertySet* propertySet) | | |||
359 | { | 328 | { | ||
329 | const KexiStyle::PropertyPane &s = KexiStyle::propertyPane(); | ||||
360 | QString objectName; | 330 | QString objectName; | ||
361 | if (propertySet) | 331 | if (propertySet) | ||
362 | objectName = propertySet->propertyValue("objectName").toString(); | 332 | objectName = propertySet->propertyValue("objectName").toString(); | ||
363 | if (!objectName.isEmpty() && objectName == m_currentObjectName) | 333 | if (flags != ForceAssign && !objectName.isEmpty() && objectName == m_currentObjectName) { | ||
364 | return; //the same object | 334 | return; //the same object | ||
335 | } | ||||
365 | m_currentObjectName = objectName; | 336 | m_currentObjectName = objectName; | ||
366 | | ||||
367 | //! @todo | | |||
368 | #if KexiDataSourcePage_FADE | | |||
369 | KexiFadeWidgetEffect *animation = 0; | | |||
370 | if (isVisible()) | | |||
371 | animation = new KexiFadeWidgetEffect(this); | | |||
372 | #endif | | |||
373 | QString objectClassName; | 337 | QString objectClassName; | ||
374 | if (propertySet) { | 338 | if (propertySet) { | ||
375 | objectClassName = propertySet->propertyValue("this:className").toString(); | 339 | objectClassName = propertySet->propertyValue("this:className").toString(); | ||
376 | } | 340 | } | ||
377 | updateInfoLabelForPropertySet(propertySet); | | |||
378 | 341 | | |||
379 | const bool isForm = objectClassName == "KexiDBForm"; | 342 | const bool isForm = objectClassName == "KexiDBForm"; | ||
380 | const bool multipleSelection = objectClassName == "special:multiple"; | 343 | const bool multipleSelection = objectClassName == "special:multiple"; | ||
381 | const bool hasDataSourceProperty = propertySet | 344 | const bool hasDataSourceProperty = propertySet | ||
382 | && propertySet->contains("dataSource") && !multipleSelection; | 345 | && propertySet->contains("dataSource") && !multipleSelection; | ||
383 | 346 | | |||
384 | if (!isForm) { | 347 | if (!isForm) { | ||
385 | //this is a widget | 348 | //this is a widget | ||
386 | QString dataSource; | 349 | QString dataSource; | ||
387 | if (hasDataSourceProperty) { | 350 | if (hasDataSourceProperty) { | ||
388 | if (propertySet) { | 351 | if (propertySet) { | ||
389 | dataSource = (*propertySet)["dataSource"].value().toString(); | 352 | dataSource = (*propertySet)["dataSource"].value().toString(); | ||
390 | } | 353 | } | ||
391 | m_noDataSourceAvailableLabel->hide(); | 354 | m_noDataSourceAvailableLabel->hide(); | ||
392 | m_widgetDataSourceCombo->setFieldOrExpression(dataSource); | 355 | m_widgetDataSourceCombo->setFieldOrExpression(dataSource); | ||
393 | m_widgetDataSourceCombo->setEnabled(true); | | |||
394 | m_widgetDSLabel->show(); | | |||
395 | m_widgetDataSourceCombo->show(); | 356 | m_widgetDataSourceCombo->show(); | ||
396 | m_widgetDataSourceComboSpacer->show(); | 357 | s.setFormLabelAndWidgetVisible(m_widgetDataSourceContainer, m_formLyr, true); | ||
397 | updateSourceFieldWidgetsAvailability(); | 358 | updateSourceFieldWidgetsAvailability(); | ||
398 | } | 359 | } | ||
399 | } | 360 | } | ||
400 | 361 | | |||
401 | if (isForm) { | 362 | if (isForm) { | ||
402 | m_noDataSourceAvailableLabel->hide(); | 363 | // no source field can be set | ||
364 | s.setFormLabelAndWidgetVisible(m_widgetDataSourceContainer, m_formLyr, false); | ||||
403 | } | 365 | } | ||
404 | else if (!hasDataSourceProperty) { | 366 | else if (!hasDataSourceProperty) { | ||
405 | if (multipleSelection) { | 367 | if (multipleSelection) { | ||
406 | m_noDataSourceAvailableLabel->setText(m_noDataSourceAvailableMultiText); | 368 | m_noDataSourceAvailableLabel->setText(m_noDataSourceAvailableMultiText); | ||
407 | } | 369 | } | ||
408 | else { | 370 | else { | ||
409 | m_noDataSourceAvailableLabel->setText(m_noDataSourceAvailableSingleText); | 371 | m_noDataSourceAvailableLabel->setText(m_noDataSourceAvailableSingleText); | ||
410 | } | 372 | } | ||
373 | s.setFormLabelAndWidgetVisible(m_widgetDataSourceContainer, m_formLyr, true); | ||||
374 | m_widgetDataSourceCombo->hide(); | ||||
411 | m_noDataSourceAvailableLabel->show(); | 375 | m_noDataSourceAvailableLabel->show(); | ||
412 | m_widgetDataSourceCombo->setEditText(QString()); | 376 | m_widgetDataSourceCombo->setEditText(QString()); | ||
413 | } | 377 | } | ||
414 | 378 | | |||
415 | if (isForm || !hasDataSourceProperty) { | 379 | m_mainLyr->update(); | ||
416 | //no source field can be set | 380 | qApp->processEvents(); | ||
417 | m_widgetDSLabel->hide(); | | |||
418 | m_widgetDataSourceCombo->hide(); | | |||
419 | m_widgetDataSourceComboSpacer->hide(); | | |||
420 | } | | |||
421 | //! @todo | | |||
422 | #if KexiDataSourcePage_FADE | | |||
423 | if (animation) | | |||
424 | animation->start(100); | | |||
425 | #endif | | |||
426 | } | 381 | } | ||
427 | 382 | | |||
428 | void KexiDataSourcePage::slotFieldListViewSelectionChanged() | 383 | void KexiDataSourcePage::slotFieldListViewSelectionChanged() | ||
429 | { | 384 | { | ||
430 | #ifdef KEXI_AUTOFIELD_FORM_WIDGET_SUPPORT | 385 | #ifdef KEXI_AUTOFIELD_FORM_WIDGET_SUPPORT | ||
431 | //update "add field" button's state | 386 | //update "add field" button's state | ||
432 | for (Q3ListViewItemIterator it(m_fieldListView); it.current(); ++it) { | 387 | for (Q3ListViewItemIterator it(m_fieldListView); it.current(); ++it) { | ||
433 | if (it.current()->isSelected()) { | 388 | if (it.current()->isSelected()) { | ||
434 | m_addField->setEnabled(true); | 389 | m_addField->setEnabled(true); | ||
435 | return; | 390 | return; | ||
436 | } | 391 | } | ||
437 | } | 392 | } | ||
438 | m_addField->setEnabled(false); | 393 | m_addField->setEnabled(false); | ||
439 | #endif | 394 | #endif | ||
440 | } | 395 | } | ||
441 | 396 | | |||
442 | void KexiDataSourcePage::updateSourceFieldWidgetsAvailability() | 397 | void KexiDataSourcePage::updateSourceFieldWidgetsAvailability() | ||
443 | { | 398 | { | ||
444 | const bool hasDataSource = m_formDataSourceCombo->isSelectionValid(); | 399 | const bool hasDataSource = m_formDataSourceCombo->isSelectionValid(); | ||
445 | m_widgetDataSourceCombo->setEnabled(hasDataSource); | 400 | m_widgetDataSourceCombo->setEnabled(hasDataSource); | ||
446 | m_widgetDSLabel->setEnabled(hasDataSource); | | |||
447 | #ifdef KEXI_AUTOFIELD_FORM_WIDGET_SUPPORT | 401 | #ifdef KEXI_AUTOFIELD_FORM_WIDGET_SUPPORT | ||
448 | m_fieldListView->setEnabled(hasDataSource); | 402 | m_fieldListView->setEnabled(hasDataSource); | ||
449 | m_availableFieldsLabel->setEnabled(hasDataSource); | 403 | m_availableFieldsLabel->setEnabled(hasDataSource); | ||
450 | m_mousePointerLabel->setEnabled(hasDataSource); | 404 | m_mousePointerLabel->setEnabled(hasDataSource); | ||
451 | m_availableFieldsDescriptionLabel->setEnabled(hasDataSource); | 405 | m_availableFieldsDescriptionLabel->setEnabled(hasDataSource); | ||
452 | #endif | 406 | #endif | ||
453 | } | 407 | } | ||
454 | 408 | | |||
Show All 9 Lines |