20#include "kexidatasourcecombobox.h"
23#include <kiconloader.h>
24#include <tdelistbox.h>
27#include <kexiproject.h>
28#include <keximainwindow.h>
30#include <kexipartmanager.h>
31#include <kexipartinfo.h>
32#include <kexipartitem.h>
34#include <kexidb/connection.h>
36#ifdef KEXI_SHOW_UNIMPLEMENTED
37#define ADD_DEFINEQUERY_ROW
41class KexiDataSourceComboBox::Private
51 int firstTableIndex()
const {
53#ifdef ADD_DEFINEQUERY_ROW
58 int firstQueryIndex()
const {
59 return firstTableIndex() + tablesCount;
62 TQGuardedPtr<KexiProject> prj;
63 TQPixmap tableIcon, queryIcon;
72KexiDataSourceComboBox::KexiDataSourceComboBox(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 &)));
82 d->tableIcon = SmallIcon(
"table");
83 d->queryIcon = SmallIcon(
"query");
86KexiDataSourceComboBox::~KexiDataSourceComboBox()
102 disconnect(d->prj, 0,
this, 0);
105 d->showTables = showTables;
106 d->showQueries = showQueries;
117 connect(d->prj, TQ_SIGNAL(itemRenamed(
const KexiPart::Item&,
const TQCString&)),
118 this, TQ_SLOT(slotItemRenamed(
const KexiPart::Item&,
const TQCString&)));
126#ifdef ADD_DEFINEQUERY_ROW
128 insertItem(i18n(
"Define Query..."));
131 TDECompletion *comp = completionObject();
142 for (KexiPart::ItemListIterator it(list); it.current(); ++it, d->tablesCount++) {
143 insertItem(d->tableIcon, it.current()->name());
144 comp->addItem(it.current()->name());
148 if (d->showQueries) {
156 for (KexiPart::ItemListIterator it(list); it.current(); ++it) {
157 insertItem(d->queryIcon, it.current()->name());
158 comp->addItem(it.current()->name());
167 if (name.isEmpty()) {
175 TQString mt(mimeType);
176 if (mimeType.isEmpty())
180 if (mimeType.isEmpty())
191void KexiDataSourceComboBox::slotNewItemStored(
KexiPart::Item& item)
193 TQString name(item.name());
195 if (item.mimeType()==
"kexi/table") {
197#ifdef ADD_DEFINEQUERY_ROW
200 for (; i < d->firstQueryIndex() && name>=text(i); i++)
202 insertItem(d->tableIcon, name, i);
203 completionObject()->addItem(name);
206 else if (item.mimeType()==
"kexi/query") {
208 for (i=d->firstQueryIndex(); i<count() && name>=text(i); i++)
210 insertItem(d->queryIcon, name, i);
211 completionObject()->addItem(name);
218 if (mimeType==
"kexi/table") {
220#ifdef ADD_DEFINEQUERY_ROW
223 end = d->firstQueryIndex();
225 else if (mimeType==
"kexi/query") {
226 i = d->firstQueryIndex();
232 TQString nameString(name);
235 if (text(i)==nameString)
241void KexiDataSourceComboBox::slotItemRemoved(
const KexiPart::Item& item)
243 const int i =
findItem(item.mimeType(), item.name());
247 completionObject()->removeItem(item.name());
248 if (item.mimeType()==
"kexi/table")
251 if (currentItem()==i) {
260void KexiDataSourceComboBox::slotItemRenamed(
const KexiPart::Item& item,
const TQCString& oldName)
262 const int i =
findItem(item.mimeType(), TQString(oldName));
265 changeItem(item.name(), i);
266 completionObject()->removeItem(TQString(oldName));
267 completionObject()->addItem(item.name());
268 setCurrentText(oldName);
271void KexiDataSourceComboBox::slotActivated(
int index )
273 if (index >= d->firstTableIndex() && index < count() && d->prevIndex!=currentItem()) {
274 d->prevIndex = currentItem();
283 const int index = currentItem();
284 if (index >= d->firstTableIndex() && index < (
int)d->firstQueryIndex())
286 else if (index >= (
int)d->firstQueryIndex() && index < count())
294 return text(currentItem());
295 return currentText();
300 const int index = currentItem();
301 return index >= d->firstTableIndex() && index < count() && text(index)==currentText();
304void KexiDataSourceComboBox::slotReturnPressed(
const TQString & text)
307 bool changed =
false;
308 if (text.isEmpty() && 0!=currentItem()) {
313 TQListBoxItem *item = listBox()->findItem( text, TQt::ExactMatch );
315 int index = listBox()->index( item );
317 if (index>=0 && index!=currentItem()) {
318 setCurrentItem( index );
327void KexiDataSourceComboBox::focusOutEvent( TQFocusEvent *e )
329 KComboBox::focusOutEvent( e );
330 slotReturnPressed(currentText());
333#include "kexidatasourcecombobox.moc"
Provides database connection, allowing queries and data modification.
void dataSourceChanged()
Emitted whenever data source changes.
KexiProject * project() const
void setDataSource(const TQString &mimeType, const TQString &name)
int findItem(const TQString &mimeType, const TQString &name)
TQString selectedMimeType() const
TQString selectedName() const
bool isSelectionValid() const
void setProject(KexiProject *prj, bool showTables=true, bool showQueries=true)
Sets global project that is used to retrieve schema informationm for this combo box.
Information about a Kexi Part (plugin).
Part item list with reimplemented compareItems() method.
Information about a single object that can be instantiated using Kexi Part.
Info * infoForMimeType(const TQString &mimeType)
A project's main controller.
void getSortedItems(KexiPart::ItemList &list, KexiPart::Info *i)
Puts a list of items of a type i in this project into list.
KEXICORE_EXPORT KexiPart::Manager & partManager()
shared part manager