20#include "kexifieldcombobox.h"
25#include <tqpushbutton.h>
28#include <tqapplication.h>
34#include <kiconloader.h>
36#include <tdeglobalsettings.h>
39#include <kexidb/tableschema.h>
40#include <kexidb/queryschema.h>
41#include <kexidb/utils.h>
42#include <kexiutils/utils.h>
43#include <kexidragobjects.h>
44#include <kexiproject.h>
47class KexiFieldComboBox::Private
52 : keyIcon( SmallIcon(
"key") )
53 , noIcon( KexiUtils::
emptyIcon(TDEIcon::Small) )
61 TQGuardedPtr<KexiProject> prj;
63 TQPixmap keyIcon, noIcon;
64 TQString tableOrQueryName;
65 TQString fieldOrExpression;
66 TQMap<TQString, TQString> captions;
72KexiFieldComboBox::KexiFieldComboBox(TQWidget *parent,
const char *name)
73 : KComboBox(true, parent, name)
76 setInsertionPolicy(NoInsertion);
77 setCompletionMode(TDEGlobalSettings::CompletionPopupAuto);
79 connect(
this, TQ_SIGNAL(activated(
int)),
this, TQ_SLOT(slotActivated(
int)));
80 connect(
this, TQ_SIGNAL(returnPressed(
const TQString &)),
this, TQ_SLOT(slotReturnPressed(
const TQString &)));
86KexiFieldComboBox::~KexiFieldComboBox()
96 setTableOrQuery(
"",
true);
104void KexiFieldComboBox::setTableOrQuery(
const TQString& name,
bool table)
106 d->tableOrQueryName = name;
112 if (d->tableOrQueryName.isEmpty() || !d->prj)
116 if (!tableOrQuery.table() && !tableOrQuery.query())
120 KexiDB::QueryColumnInfo::Vector columns = tableOrQuery.columns();
121 const int count = columns.count();
122 for(
int i=0; i < count; i++)
130 completionObject()->addItem(colinfo->
aliasOrName());
139TQString KexiFieldComboBox::tableOrQueryName()
const
141 return d->tableOrQueryName;
144bool KexiFieldComboBox::isTableAssigned()
const
151 const TQString name(
string);
152 const int pos = name.find(
'.');
154 d->fieldOrExpression = name;
157 TQString objectName = name.left(pos);
158 if (d->tableOrQueryName!=objectName) {
159 d->fieldOrExpression = name;
161 setCurrentText(name);
163 kexiwarn <<
"KexiFieldComboBox::setField(): invalid table/query name in '" << name <<
"'" << endl;
166 d->fieldOrExpression = name.mid(pos+1);
169 TQListBoxItem *item = listBox()->findItem(d->fieldOrExpression);
172 setCurrentText(d->fieldOrExpression);
176 setCurrentItem( listBox()->index(item) );
182 if (index>=count()) {
183 kexiwarn << TQString(
"KexiFieldComboBox::setFieldOrExpression(int index): index %1 "
184 "out of range (0..%2)").arg(index).arg(count()-1) << endl;
189 d->fieldOrExpression = TQString();
192 setCurrentItem(index);
193 d->fieldOrExpression = currentText();
197TQString KexiFieldComboBox::fieldOrExpression()
const
199 return d->fieldOrExpression;
205 if (!tableOrQuery.
table() && !tableOrQuery.
query())
208 return currentItem()>0 ? (currentItem()-1) : -1;
211TQString KexiFieldComboBox::fieldOrExpressionCaption()
const
213 return d->captions[ d->fieldOrExpression ];
216void KexiFieldComboBox::slotActivated(
int i)
218 d->fieldOrExpression = text(i);
222void KexiFieldComboBox::slotReturnPressed(
const TQString & text)
226 if (text.isEmpty()) {
230 TQListBoxItem *item = listBox()->findItem( text, TQt::ExactMatch );
233 index = listBox()->index( item );
237 setCurrentItem( index );
238 slotActivated( index );
241void KexiFieldComboBox::focusOutEvent( TQFocusEvent *e )
243 KComboBox::focusOutEvent( e );
246 slotReturnPressed(currentText());
249#include "kexifieldcombobox.moc"
bool isPrimaryKey() const
Helper class that assigns additional information for the column in a query.
TQCString aliasOrName() const
TQString captionOrAliasOrName() const
QuerySchema * query() const
TableSchema * table() const
KexiProject * project() const
void setFieldOrExpression(const TQString &string)
void setProject(KexiProject *prj)
Sets global project that is used to retrieve schema informationm for this combo box.
A project's main controller.
KEXIUTILS_EXPORT TQPixmap emptyIcon(TDEIcon::Group iconGroup)
bool hasParent(TQObject *par, TQObject *o)