20#include "kexicomboboxpopup.h"
22#include "kexidatatableview.h"
23#include "kexitableview_p.h"
24#include "kexitableitem.h"
25#include "kexitableedit.h"
27#include <kexidb/lookupfieldschema.h>
28#include <kexidb/expression.h>
29#include <kexidb/parser/sqlparser.h>
41 KexiComboBoxPopup_KexiTableView(TQWidget* parent=0)
50 d->moveCursorOnMouseRelease =
true;
52 a.navigatorEnabled =
false;
54 a.backgroundAltering =
false;
55 a.fullRowSelection =
true;
56 a.rowHighlightingEnabled =
true;
57 a.rowMouseOverHighlightingEnabled =
true;
58 a.persistentSelections =
false;
59 a.rowMouseOverHighlightingColor = colorGroup().highlight();
60 a.rowMouseOverHighlightingTextColor = colorGroup().highlightedText();
61 a.rowHighlightingTextColor = a.rowMouseOverHighlightingTextColor;
62 a.gridEnabled =
false;
70 installEventFilter(
this);
71 setBottomMarginInternal( - horizontalScrollBar()->sizeHint().height() );
74 { KexiTableView::setData(
data, owner ); }
82class KexiComboBoxPopupPrivate
85 KexiComboBoxPopupPrivate()
91 ~KexiComboBoxPopupPrivate() {
96 KexiComboBoxPopup_KexiTableView *tv;
107 : TQFrame( parent,
"KexiComboBoxPopup", WType_Popup )
115 : TQFrame( parent,
"KexiComboBoxPopup", WType_Popup )
122KexiComboBoxPopup::~KexiComboBoxPopup()
127void KexiComboBoxPopup::init()
129 d =
new KexiComboBoxPopupPrivate();
130 setPaletteBackgroundColor(palette().color(TQPalette::Active,TQColorGroup::Base));
132 setFrameStyle( Box | Plain );
134 d->tv =
new KexiComboBoxPopup_KexiTableView(
this);
135 installEventFilter(
this);
137 connect(d->tv, TQ_SIGNAL(itemReturnPressed(KexiTableItem*,
int,
int)),
138 this, TQ_SLOT(slotTVItemAccepted(KexiTableItem*,
int,
int)));
140 connect(d->tv, TQ_SIGNAL(itemMouseReleased(KexiTableItem*,
int,
int)),
141 this, TQ_SLOT(slotTVItemAccepted(KexiTableItem*,
int,
int)));
143 connect(d->tv, TQ_SIGNAL(itemDblClicked(KexiTableItem*,
int,
int)),
144 this, TQ_SLOT(slotTVItemAccepted(KexiTableItem*,
int,
int)));
149 if (column && !field)
150 field = column->
field();
152 kexiwarn <<
"KexiComboBoxPopup::setData(): !field" << endl;
158 d->tv->setColumnStretchEnabled(
true, -1 );
165 lookupFieldSchema = field->table()->lookupFieldSchema( *field );
166 delete d->privateQuery;
168 if (lookupFieldSchema) {
169 const TQValueList<uint> visibleColumns( lookupFieldSchema->
visibleColumns() );
170 const bool multipleLookupColumnJoined = visibleColumns.count() > 1;
176 = field->table()->connection()->tableSchema( lookupFieldSchema->
rowSource().
name() );
180 if (multipleLookupColumnJoined) {
181 kdDebug() <<
"--- Orig query: " << endl;
186 cursor = field->table()->connection()->prepareQuery( *lookupTable );
192 = field->table()->connection()->querySchema( lookupFieldSchema->
rowSource().
name() );
196 if (multipleLookupColumnJoined) {
197 kdDebug() <<
"--- Orig query: " << endl;
198 lookupQuery->
debug();
202 cursor = field->table()->connection()->prepareQuery( *lookupQuery );
208 if (d->privateQuery) {
210 const KexiDB::QueryColumnInfo::Vector fieldsExpanded( d->privateQuery->fieldsExpanded() );
211 uint fieldsExpandedSize( fieldsExpanded.size() );
213 int count = visibleColumns.count();
214 for (TQValueList<uint>::ConstIterator it( visibleColumns.at(count-1) ); count>0; count--, --it) {
217 kdWarning() <<
"KexiComboBoxPopup::setData(): " << *it <<
" >= fieldsExpandedSize" << endl;
222 fieldExpr->field = ci->field;
223 fieldExpr->tablePositionForField = d->privateQuery->tableBoundToColumn( *it );
235 kdDebug() << expr->
toString() << endl;
239 d->privateQuery->addField( f );
243 const int numColumntoHide = d->privateQuery->fieldsExpanded().count() - 1;
244 for (
int i=0; i < numColumntoHide; i++)
245 d->privateQuery->setColumnVisible(i,
false);
249 kdDebug() <<
"--- Private query: " << endl;
250 d->privateQuery->debug();
251 cursor = field->table()->connection()->prepareQuery( *d->privateQuery );
257 if (d->tv->KexiDataAwareObjectInterface::data())
258 d->tv->KexiDataAwareObjectInterface::data()->disconnect(
this );
259 d->tv->setData( cursor );
261 connect( d->tv, TQ_SIGNAL(dataRefreshed()),
this, TQ_SLOT(slotDataReloadRequested()));
266 kdWarning() <<
"KexiComboBoxPopup::setData(KexiTableViewColumn &): no column relatedData \n - moving to setData(KexiDB::Field &)" << endl;
269 d->tv->setColumnStretchEnabled(
true, -1 );
275 TQValueVector<TQString> hints = field->enumHints();
276 for(uint i=0; i < hints.size(); i++) {
277 KexiTableItem *item = data->createItem();
278 (*item)[0]=TQVariant(hints[i]);
279 kdDebug() <<
"added: '" << hints[i] <<
"'"<<endl;
280 data->append( item );
287 if (d->tv->KexiDataAwareObjectInterface::data())
288 d->tv->KexiDataAwareObjectInterface::data()->disconnect(
this );
289 d->tv->setData( data, owner );
290 connect( d->tv, TQ_SIGNAL(dataRefreshed()),
this, TQ_SLOT(slotDataReloadRequested()));
295void KexiComboBoxPopup::updateSize(
int minWidth)
297 const int rows = TQMIN( d->max_rows, d->tv->rows() );
299 d->tv->adjustColumnWidthToContents(-1);
302 const int width = TQMAX( d->tv->tableSize().width(),
303 (te ? te->
totalSize().width() : (parentWidget()?parentWidget()->width():0)) );
304 kexidbg <<
"KexiComboBoxPopup::updateSize(): size=" << size() << endl;
305 resize( TQMAX(minWidth, width) , d->tv->rowHeight() * rows +2 );
306 kexidbg <<
"KexiComboBoxPopup::updateSize(): size after=" << size() << endl;
309 d->tv->setColumnStretchEnabled(
true, d->tv->columns()-1);
317void KexiComboBoxPopup::resize(
int w,
int h )
319 d->tv->horizontalScrollBar()->hide();
320 d->tv->verticalScrollBar()->hide();
322 d->tv->resize( w-2, h-2 );
323 TQFrame::resize(w,h);
338void KexiComboBoxPopup::slotTVItemAccepted(KexiTableItem *item,
int row,
int)
341 emit rowAccepted(item, row);
344bool KexiComboBoxPopup::eventFilter( TQObject *o, TQEvent *e )
346 if (o==
this && e->type()==TQEvent::Hide) {
349 else if (e->type()==TQEvent::MouseButtonPress) {
350 kdDebug() <<
"TQEvent::MousePress" << endl;
353 if (e->type()==TQEvent::KeyPress) {
354 TQKeyEvent *ke =
static_cast<TQKeyEvent*
>(e);
355 const int k = ke->key();
356 if ((ke->state()==TQt::NoButton && (k==Key_Escape || k==Key_F4))
357 || (ke->state()==AltButton && k==Key_Up))
365 return TQFrame::eventFilter( o, e );
368void KexiComboBoxPopup::slotDataReloadRequested()
373#include "kexicomboboxpopup.moc"
A base class for all expressions.
virtual TQString toString(QuerySchemaParameterValueListIterator *params=0)=0
Provides database cursor functionality.
void setExpression(KexiDB::BaseExpr *expr)
virtual TableSchema * table() const
@ Table
table as lookup row source
@ Query
named query as lookup row source
Provides information about lookup field's setup.
TQValueList< uint > visibleColumns() const
Helper class that assigns additional information for the column in a query.
KexiDB::QuerySchema provides information about database query.
Variables like fieldname or tablename.fieldname
KexiTableViewData * data() const
virtual void setSortingEnabled(bool set)
void setInsertingEnabled(bool set)
void setScrollbarToolTipsEnabled(bool set)
void setContextMenuEnabled(bool set)
void setReadOnly(bool set)
Database aware table widget.
KexiDB::Cursor * cursor()
bool setData(KexiDB::Cursor *cursor)
Abstract class for a cell editor. Handles cell painting and displaying the editor widget.
virtual TQSize totalSize()
KexiDB::Field * field() const
KexiTableViewData * relatedData() const
void addColumn(KexiTableViewColumn *col)
KexiTableView class provides a widget for displaying data in a tabular view.
void setAppearance(const Appearance &a)
const Appearance & appearance() const
void setVerticalHeaderVisible(bool set)
Sets vertical header's visibility.
void setHorizontalHeaderVisible(bool set)
Sets horizontal header's visibility.