20#include "kexilookupcolumnpage.h"
27#include <kiconloader.h>
29#include <tdetoolbarbutton.h>
31#include <tdepopupmenu.h>
33#include <widget/kexipropertyeditorview.h>
34#include <widget/kexidatasourcecombobox.h>
35#include <widget/kexifieldlistview.h>
36#include <widget/kexifieldcombobox.h>
37#include <widget/kexismalltoolbutton.h>
38#include <kexidb/connection.h>
39#include <kexiproject.h>
41#include <koproperty/property.h>
42#include <koproperty/utils.h>
44TQString mimeTypeToType(
const TQString& mimeType)
46 if (mimeType==
"kexi/table")
48 else if (mimeType==
"kexi/query")
54TQString typeToMimeType(
const TQString& type)
58 else if (type==
"query")
67class KexiLookupColumnPage::Private
72 , insideClearRowSourceSelection(false)
73 , propertySetEnabled(true)
80 bool hasPropertySet()
const {
84 void setPropertySet(KoProperty::Set* aPropertySet) {
85 propertySet = aPropertySet;
88 TQVariant propertyValue(
const TQCString& propertyName)
const {
89 return propertySet ? propertySet->property(propertyName).value() : TQVariant();
92 void changeProperty(
const TQCString &property,
const TQVariant &value)
94 if (!propertySetEnabled)
96 propertySet->changeProperty(property, value);
99 void updateInfoLabelForPropertySet(
const TQString& textToDisplayForNullSet) {
101 objectInfoLabel, propertySet, textToDisplayForNullSet);
107 TQLabel *rowSourceLabel, *boundColumnLabel, *visibleColumnLabel;
108 TQToolButton *clearRowSourceButton, *gotoRowSourceButton, *clearBoundColumnButton,
109 *clearVisibleColumnButton;
113 bool insideClearRowSourceSelection : 1;
115 bool propertySetEnabled : 1;
120 TQGuardedPtr<KoProperty::Set> propertySet;
125KexiLookupColumnPage::KexiLookupColumnPage(TQWidget *parent)
129 setName(
"KexiLookupColumnPage");
131 TQVBoxLayout *vlyr =
new TQVBoxLayout(
this);
133 vlyr->addWidget(d->objectInfoLabel);
139 TQWidget *contents =
new TQWidget(
this);
140 vlyr->addWidget(contents);
141 TQVBoxLayout *contentsVlyr =
new TQVBoxLayout(contents);
143 TQHBoxLayout *hlyr =
new TQHBoxLayout(contentsVlyr);
144 d->rowSourceLabel =
new TQLabel(i18n(
"Row source:"), contents);
145 d->rowSourceLabel->setSizePolicy(TQSizePolicy::Minimum, TQSizePolicy::Fixed);
146 d->rowSourceLabel->setMargin(2);
147 d->rowSourceLabel->setMinimumHeight(IconSize(TDEIcon::Small)+4);
148 d->rowSourceLabel->setAlignment(TQt::AlignLeft|TQt::AlignBottom);
149 hlyr->addWidget(d->rowSourceLabel);
151 d->gotoRowSourceButton =
new KexiSmallToolButton(contents, TQString(),
"goto",
"gotoRowSourceButton");
152 d->gotoRowSourceButton->setMinimumHeight(d->rowSourceLabel->minimumHeight());
153 TQToolTip::add(d->gotoRowSourceButton, i18n(
"Go to selected row source"));
154 hlyr->addWidget(d->gotoRowSourceButton);
155 connect(d->gotoRowSourceButton, TQ_SIGNAL(clicked()),
this, TQ_SLOT(slotGotoSelectedRowSource()));
158 "clear_left",
"clearRowSourceButton");
159 d->clearRowSourceButton->setMinimumHeight(d->rowSourceLabel->minimumHeight());
160 TQToolTip::add(d->clearRowSourceButton, i18n(
"Clear row source"));
161 hlyr->addWidget(d->clearRowSourceButton);
162 connect(d->clearRowSourceButton, TQ_SIGNAL(clicked()),
this, TQ_SLOT(clearRowSourceSelection()));
165 d->rowSourceLabel->setBuddy(d->rowSourceCombo);
166 contentsVlyr->addWidget(d->rowSourceCombo);
168 contentsVlyr->addSpacing(8);
171 hlyr =
new TQHBoxLayout(contentsVlyr);
172 d->boundColumnLabel =
new TQLabel(i18n(
"Bound column:"), contents);
173 d->boundColumnLabel->setSizePolicy(TQSizePolicy::Minimum, TQSizePolicy::Fixed);
174 d->boundColumnLabel->setMargin(2);
175 d->boundColumnLabel->setMinimumHeight(IconSize(TDEIcon::Small)+4);
176 d->boundColumnLabel->setAlignment(TQt::AlignLeft|TQt::AlignBottom);
177 hlyr->addWidget(d->boundColumnLabel);
180 "clear_left",
"clearBoundColumnButton");
181 d->clearBoundColumnButton->setMinimumHeight(d->boundColumnLabel->minimumHeight());
182 TQToolTip::add(d->clearBoundColumnButton, i18n(
"Clear bound column"));
183 hlyr->addWidget(d->clearBoundColumnButton);
184 connect(d->clearBoundColumnButton, TQ_SIGNAL(clicked()),
this, TQ_SLOT(clearBoundColumnSelection()));
187 d->boundColumnLabel->setBuddy(d->boundColumnCombo);
188 contentsVlyr->addWidget(d->boundColumnCombo);
190 contentsVlyr->addSpacing(8);
193 hlyr =
new TQHBoxLayout(contentsVlyr);
194 d->visibleColumnLabel =
new TQLabel(i18n(
"Visible column:"), contents);
195 d->visibleColumnLabel->setSizePolicy(TQSizePolicy::Minimum, TQSizePolicy::Fixed);
196 d->visibleColumnLabel->setMargin(2);
197 d->visibleColumnLabel->setMinimumHeight(IconSize(TDEIcon::Small)+4);
198 d->visibleColumnLabel->setAlignment(TQt::AlignLeft|TQt::AlignBottom);
199 hlyr->addWidget(d->visibleColumnLabel);
202 "clear_left",
"clearVisibleColumnButton");
203 d->clearVisibleColumnButton->setMinimumHeight(d->visibleColumnLabel->minimumHeight());
204 TQToolTip::add(d->clearVisibleColumnButton, i18n(
"Clear visible column"));
205 hlyr->addWidget(d->clearVisibleColumnButton);
206 connect(d->clearVisibleColumnButton, TQ_SIGNAL(clicked()),
this, TQ_SLOT(clearVisibleColumnSelection()));
209 d->visibleColumnLabel->setBuddy(d->visibleColumnCombo);
210 contentsVlyr->addWidget(d->visibleColumnCombo);
214 connect(d->rowSourceCombo, TQ_SIGNAL(textChanged(
const TQString &)),
215 this, TQ_SLOT(slotRowSourceTextChanged(
const TQString &)));
216 connect(d->rowSourceCombo, TQ_SIGNAL(dataSourceChanged()),
this, TQ_SLOT(slotRowSourceChanged()));
217 connect(d->boundColumnCombo, TQ_SIGNAL(selected()),
this, TQ_SLOT(slotBoundColumnSelected()));
218 connect(d->visibleColumnCombo, TQ_SIGNAL(selected()),
this, TQ_SLOT(slotVisibleColumnSelected()));
220 clearBoundColumnSelection();
221 clearVisibleColumnSelection();
224KexiLookupColumnPage::~KexiLookupColumnPage()
229void KexiLookupColumnPage::setProject(
KexiProject *prj)
231 d->rowSourceCombo->setProject(prj,
234 d->boundColumnCombo->setProject(prj);
235 d->visibleColumnCombo->setProject(prj);
240 if (!d->hasPropertySet() && !propertySet)
242 if (propertySet && d->currentFieldUid == (*propertySet)[
"uid"].value().toInt())
245 d->propertySetEnabled =
false;
246 d->setPropertySet( propertySet );
247 d->updateInfoLabelForPropertySet( i18n(
"No field selected") );
249 const bool hasRowSource = d->hasPropertySet() && !d->propertyValue(
"rowSourceType").isNull()
250 && !d->propertyValue(
"rowSource").isNull();
252 TQString rowSource, rowSourceType;
254 rowSourceType = typeToMimeType( d->propertyValue(
"rowSourceType").toString() );
255 rowSource = d->propertyValue(
"rowSource").toString();
257 d->rowSourceCombo->setDataSource( rowSourceType, rowSource );
258 d->rowSourceLabel->setEnabled( d->hasPropertySet() );
259 d->rowSourceCombo->setEnabled( d->hasPropertySet() );
260 if (!d->hasPropertySet())
261 d->clearRowSourceButton->setEnabled(
false );
263 int boundColumn = -1, visibleColumn = -1;
264 if (d->rowSourceCombo->isSelectionValid()) {
265 boundColumn = d->propertyValue(
"boundColumn").toInt();
266 visibleColumn = d->propertyValue(
"visibleColumn").toInt();
268 d->boundColumnCombo->setFieldOrExpression(boundColumn);
269 d->visibleColumnCombo->setFieldOrExpression(visibleColumn);
270 updateBoundColumnWidgetsAvailability();
271 d->propertySetEnabled =
true;
274void KexiLookupColumnPage::clearBoundColumnSelection()
276 d->boundColumnCombo->setCurrentText(
"");
277 d->boundColumnCombo->setFieldOrExpression(TQString());
278 slotBoundColumnSelected();
279 d->clearBoundColumnButton->setEnabled(
false);
282void KexiLookupColumnPage::slotBoundColumnSelected()
290 d->clearBoundColumnButton->setEnabled( !d->boundColumnCombo->fieldOrExpression().isEmpty() );
291 if (!d->boundColumnCombo->fieldOrExpression().isEmpty()) {
296 if (d->hasPropertySet()) {
297 d->changeProperty(
"boundColumn", d->boundColumnCombo->indexOfField());
307void KexiLookupColumnPage::clearVisibleColumnSelection()
309 d->visibleColumnCombo->setCurrentText(
"");
310 d->visibleColumnCombo->setFieldOrExpression(TQString());
311 slotVisibleColumnSelected();
312 d->clearVisibleColumnButton->setEnabled(
false);
315void KexiLookupColumnPage::slotVisibleColumnSelected()
319 d->clearVisibleColumnButton->setEnabled( !d->visibleColumnCombo->fieldOrExpression().isEmpty() );
322 if (d->hasPropertySet()) {
324 d->changeProperty(
"visibleColumn", d->visibleColumnCombo->indexOfField());
328void KexiLookupColumnPage::slotRowSourceChanged()
330 if (!d->rowSourceCombo->project())
332 TQString mime = d->rowSourceCombo->selectedMimeType();
333 bool rowSourceFound =
false;
334 TQString name = d->rowSourceCombo->selectedName();
335 if ((mime==
"kexi/table" || mime==
"kexi/query") && d->rowSourceCombo->isSelectionValid()) {
337 d->rowSourceCombo->project()->dbConnection(), name.latin1(), mime==
"kexi/table");
338 if (tableOrQuery->
table() || tableOrQuery->
query()) {
341 rowSourceFound =
true;
342 d->boundColumnCombo->setTableOrQuery(name, mime==
"kexi/table");
343 d->visibleColumnCombo->setTableOrQuery(name, mime==
"kexi/table");
349 if (!rowSourceFound) {
350 d->boundColumnCombo->setTableOrQuery(
"",
true);
351 d->visibleColumnCombo->setTableOrQuery(
"",
true);
353 clearBoundColumnSelection();
354 clearVisibleColumnSelection();
355 d->clearRowSourceButton->setEnabled(rowSourceFound);
356 d->gotoRowSourceButton->setEnabled(rowSourceFound);
363 updateBoundColumnWidgetsAvailability();
366 if (d->hasPropertySet()) {
367 d->changeProperty(
"rowSourceType", mimeTypeToType(mime));
368 d->changeProperty(
"rowSource", name);
375void KexiLookupColumnPage::slotRowSourceTextChanged(
const TQString &
string)
378 const bool enable = d->rowSourceCombo->isSelectionValid();
380 updateBoundColumnWidgetsAvailability();
383 clearRowSourceSelection( d->rowSourceCombo->selectedName().isEmpty() );
387void KexiLookupColumnPage::clearRowSourceSelection(
bool alsoClearComboBox)
389 if (d->insideClearRowSourceSelection)
391 d->insideClearRowSourceSelection =
true;
392 if (alsoClearComboBox && !d->rowSourceCombo->selectedName().isEmpty())
393 d->rowSourceCombo->setDataSource(
"",
"");
394 d->clearRowSourceButton->setEnabled(
false);
395 d->gotoRowSourceButton->setEnabled(
false);
396 d->insideClearRowSourceSelection =
false;
399void KexiLookupColumnPage::slotGotoSelectedRowSource()
401 TQString mime = d->rowSourceCombo->selectedMimeType();
402 if (mime==
"kexi/table" || mime==
"kexi/query") {
403 if (d->rowSourceCombo->isSelectionValid())
408void KexiLookupColumnPage::updateBoundColumnWidgetsAvailability()
410 const bool hasRowSource = d->rowSourceCombo->isSelectionValid();
411 d->boundColumnCombo->setEnabled( hasRowSource );
412 d->boundColumnLabel->setEnabled( hasRowSource );
413 d->clearBoundColumnButton->setEnabled( hasRowSource && !d->boundColumnCombo->fieldOrExpression().isEmpty() );
414 d->visibleColumnCombo->setEnabled( hasRowSource );
415 d->visibleColumnLabel->setEnabled( hasRowSource );
416 d->clearVisibleColumnButton->setEnabled( hasRowSource && !d->visibleColumnCombo->fieldOrExpression().isEmpty() );
419#include "kexilookupcolumnpage.moc"
QuerySchema * query() const
TableSchema * table() const
A combo box listing availabe data sources (tables and queries) with icons.
void jumpToObjectRequested(const TQCString &mime, const TQCString &name)
Signal emitted when helper button 'Go to selected row sourcesource' is clicked.
void assignPropertySet(KoProperty::Set *propertySet)
Receives a pointer to a new property set (from KexiFormView::managerPropertyChanged())
Helper class displaying small icon with class name and object name.
A project's main controller.
static void updateInfoLabelForPropertySet(KexiObjectInfoLabel *infoLabel, KoProperty::Set *set, const TQString &textToDisplayForNullSet=TQString())