20#include "kexifieldcombobox.h"
25#include <tqpushbutton.h>
28#include <tqapplication.h>
34#include <kiconloader.h>
35#include <tdeversion.h>
37#include <tdeglobalsettings.h>
40#include <kexidb/tableschema.h>
41#include <kexidb/queryschema.h>
42#include <kexidb/utils.h>
43#include <kexiutils/utils.h>
44#include <kexidragobjects.h>
45#include <kexiproject.h>
48class KexiFieldComboBox::Private
53 : keyIcon( SmallIcon(
"key") )
62 TQGuardedPtr<KexiProject> prj;
64 TQPixmap keyIcon, noIcon;
65 TQString tableOrQueryName;
66 TQString fieldOrExpression;
67 TQMap<TQString, TQString> captions;
73KexiFieldComboBox::KexiFieldComboBox(TQWidget *parent,
const char *name)
74 : KComboBox(true, parent, name)
77 setInsertionPolicy(NoInsertion);
78 setCompletionMode(TDEGlobalSettings::CompletionPopupAuto);
80 connect(
this, TQ_SIGNAL(activated(
int)),
this, TQ_SLOT(slotActivated(
int)));
81 connect(
this, TQ_SIGNAL(returnPressed(
const TQString &)),
this, TQ_SLOT(slotReturnPressed(
const TQString &)));
87KexiFieldComboBox::~KexiFieldComboBox()
97 setTableOrQuery(
"",
true);
105void KexiFieldComboBox::setTableOrQuery(
const TQString& name,
bool table)
107 d->tableOrQueryName = name;
113 if (d->tableOrQueryName.isEmpty() || !d->prj)
117 if (!tableOrQuery.table() && !tableOrQuery.query())
121 KexiDB::QueryColumnInfo::Vector columns = tableOrQuery.columns();
122 const int count = columns.count();
123 for(
int i=0; i < count; i++)
130 , TQString(colinfo->aliasOrName()));
131 completionObject()->addItem(colinfo->
aliasOrName());
137 setFieldOrExpression(d->fieldOrExpression);
140TQString KexiFieldComboBox::tableOrQueryName()
const
142 return d->tableOrQueryName;
145bool KexiFieldComboBox::isTableAssigned()
const
150void KexiFieldComboBox::setFieldOrExpression(
const TQString&
string)
152 const TQString name(
string);
153 const int pos = name.find(
'.');
155 d->fieldOrExpression = name;
158 TQString objectName = name.left(pos);
159 if (d->tableOrQueryName!=objectName) {
160 d->fieldOrExpression = name;
162 setCurrentText(name);
164 kexiwarn <<
"KexiFieldComboBox::setField(): invalid table/query name in '" << name <<
"'" << endl;
167 d->fieldOrExpression = name.mid(pos+1);
170 TQListBoxItem *item = listBox()->findItem(d->fieldOrExpression);
173 setCurrentText(d->fieldOrExpression);
177 setCurrentItem( listBox()->index(item) );
180void KexiFieldComboBox::setFieldOrExpression(
int index)
183 if (index>=count()) {
184 kexiwarn << TQString(
"KexiFieldComboBox::setFieldOrExpression(int index): index %1 "
185 "out of range (0..%2)").arg(index).arg(count()-1) << endl;
190 d->fieldOrExpression = TQString();
193 setCurrentItem(index);
194 d->fieldOrExpression = currentText();
198TQString KexiFieldComboBox::fieldOrExpression()
const
200 return d->fieldOrExpression;
206 if (!tableOrQuery.
table() && !tableOrQuery.
query())
209 return currentItem()>0 ? (currentItem()-1) : -1;
212TQString KexiFieldComboBox::fieldOrExpressionCaption()
const
214 return d->captions[ d->fieldOrExpression ];
217void KexiFieldComboBox::slotActivated(
int i)
219 d->fieldOrExpression = text(i);
223void KexiFieldComboBox::slotReturnPressed(
const TQString & text)
227 if (text.isEmpty()) {
231 TQListBoxItem *item = listBox()->findItem( text, TQt::ExactMatch );
234 index = listBox()->index( item );
238 setCurrentItem( index );
239 slotActivated( index );
242void KexiFieldComboBox::focusOutEvent( TQFocusEvent *e )
244 KComboBox::focusOutEvent( e );
247 slotReturnPressed(currentText());
250#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
A project's main controller.
KEXIUTILS_EXPORT TQPixmap emptyIcon(TDEIcon::Group iconGroup)
bool hasParent(TQObject *par, TQObject *o)