25#include <tqmetaobject.h>
28#include <kpushbutton.h>
29#include <kiconloader.h>
30#include <tdemessagebox.h>
34#include "kexitableview.h"
35#include "kexitableviewdata.h"
38#include "formmanager.h"
39#include "objecttree.h"
41#include "connectiondialog.h"
48ConnectionDialog::ConnectionDialog(TQWidget *parent)
49: KDialogBase(parent, "connections_dialog", true, i18n( "Edit Form Connections"),
50 Ok|Cancel|Details, Ok, false)
53 TQFrame *frame = makeMainWidget();
54 TQHBoxLayout *layout = new TQHBoxLayout(frame, 0, 6);
57 TQHBox *details = new TQHBox(frame);
58 setDetailsWidget(details);
61 m_pixmapLabel = new TQLabel(details);
62 m_pixmapLabel->setFixedWidth( int(IconSize(TDEIcon::Desktop) * 1.5) );
63 m_pixmapLabel->setAlignment(AlignHCenter | AlignTop);
65 m_textLabel = new TQLabel(details);
66 m_textLabel->setAlignment(AlignLeft | AlignTop);
71 m_table = new KexiTableView(0, frame, "connections_tableview");
72 m_table->setSpreadSheetMode();
73 m_table->setInsertingEnabled( true);
75 m_table->setData(m_data, false);
76 m_table->adjustColumnWidthToContents(0);
77 layout->addWidget(m_table);
80 TQVBoxLayout *vlayout = new TQVBoxLayout(layout, 3);
81 KPushButton *newItem = new KPushButton(SmallIconSet( "document-new"), i18n( "&New Connection"), frame);
82 vlayout->addWidget(newItem);
83 m_buttons.insert(BAdd, newItem);
84 connect(newItem, TQ_SIGNAL(clicked()), this, TQ_SLOT(newItem()));
86 KPushButton *delItem = new KPushButton(SmallIconSet( "edit-delete"), i18n( "&Remove Connection"), frame);
87 vlayout->addWidget(delItem);
88 m_buttons.insert(BRemove, delItem);
89 connect(delItem, TQ_SIGNAL(clicked()), this, TQ_SLOT(removeItem()));
91 vlayout->addStretch();
93 setInitialSize(TQSize(600, 300));
96 connect(m_table,TQ_SIGNAL(cellSelected( int, int)), this, TQ_SLOT(slotCellSelected( int, int)));
97 connect(m_table->KexiDataAwareObjectInterface::data(), TQ_SIGNAL(rowInserted(KexiTableItem*, bool)), this, TQ_SLOT(slotRowInserted(KexiTableItem*, bool)));
108 m_data->addColumn(col0);
113 m_data->addColumn(col1);
118 m_data->addColumn(col2);
122 m_data->addColumn(col3);
127 m_data->addColumn(col4);
131 m_table->maximizeColumnsWidth(c);
132 m_table->setColumnStretchEnabled( true, 4 );
134 connect(m_data, TQ_SIGNAL(aboutToChangeCell(KexiTableItem*, int, TQVariant&, KexiDB::ResultInfo*)),
136 connect(m_data, TQ_SIGNAL(rowUpdated(KexiTableItem*)), this, TQ_SLOT( checkConnection(KexiTableItem *)));
137 connect(m_table, TQ_SIGNAL(itemSelected(KexiTableItem *)), this, TQ_SLOT( checkConnection(KexiTableItem *)));
149void ConnectionDialog::slotCellSelected( int col, int row)
151 m_buttons[BRemove]->setEnabled( row < m_table->rows() );
152 KexiTableItem *item = m_table->itemAt(row);
156 updateSignalList(item);
158 updateSlotList(item);
161void ConnectionDialog::slotRowInserted(KexiTableItem* item, bool)
163 m_buffer->append( new Connection());
164 checkConnection( item );
171 for( int i=0; i < m_table->rows(); i++)
173 KexiTableItem *item = m_table->itemAt(i);
174 Connection *c = m_buffer->at(i);
176 c->setSender( (*item)[1].toString() );
177 c->setSignal( (*item)[2].toString() );
178 c->setReceiver( (*item)[3].toString() );
179 c->setSlot( (*item)[4].toString() );
183 delete m_form->connectionBuffer();
184 m_form->setConnectionBuffer(m_buffer);
195 for(; it.current(); ++it)
197 KexiTableItem *item = m_widgetsColumnData->createItem();
198 (*item)[0] = it.current()->name();
199 (*item)[1] = (*item)[0];
200 m_widgetsColumnData->append(item);
205 for(Connection *c = m_form->connectionBuffer()->first(); c ; c = m_form->connectionBuffer()->next())
207 KexiTableItem *item = m_table->KexiDataAwareObjectInterface::data()->createItem();
208 (*item)[1] = c->sender();
209 (*item)[2] = c->signal();
210 (*item)[3] = c->receiver();
211 (*item)[4] = c->slot();
212 m_table->insertItem(item, m_table->rows());
215 m_buffer = new ConnectionBuffer(*(m_form->connectionBuffer()));
221 m_pixmapLabel->setPixmap( DesktopIcon( "button_ok") );
222 m_textLabel->setText( "<qt><h2>The connection is OK.</h2></qt>");
225 item = m_table->selectedItem();
226 if (m_table->currentRow() >= m_table->rows())
230 (*item)[0] = "button_ok";
232 m_pixmapLabel->setPixmap( TQPixmap() );
233 m_textLabel->setText(TQString());
240 m_pixmapLabel->setPixmap( DesktopIcon( "button_cancel") );
241 m_textLabel->setText( "<qt><h2>The connection is invalid.</h2></qt>" + msg);
244 item = m_table->selectedItem();
245 if (m_table->currentRow() >= m_table->rows())
249 (*item)[0] = "button_cancel";
251 m_pixmapLabel->setPixmap( TQPixmap() );
252 m_textLabel->setText(TQString());
263 (*item)[2] = TQString( "");
268 (*item)[4] = TQString( "");
279 m_slotsColumnData->deleteAllRows();
280 TQString widget = (*item)[1].toString();
281 TQString signal = (*item)[2].toString();
283 if((widget.isEmpty()) || signal.isEmpty())
286 if(!tree || !tree->widget())
289 TQString signalArg(signal);
290 signalArg = signalArg.remove( TQRegExp( ".*[(]|[)]") );
292 TQStrList slotList = tree->widget()->metaObject()->slotNames( true);
293 TQStrListIterator it(slotList);
294 for(; it.current() != 0; ++it)
297 TQString slotArg(*it);
298 slotArg = slotArg.remove( TQRegExp( ".*[(]|[)]") );
300 if(!signalArg.startsWith(slotArg, true) && (!signal.isEmpty()))
303 KexiTableItem *item = m_slotsColumnData->createItem();
304 (*item)[0] = TQString(*it);
305 (*item)[1] = (*item)[0];
306 m_slotsColumnData->append(item);
313 ObjectTreeItem *tree = m_form->objectTree()->lookup((*item)[1].toString());
314 if(!tree || !tree->widget())
317 m_signalsColumnData->deleteAllRows();
318 TQStrList signalList = tree->widget()->metaObject()->signalNames( true);
319 TQStrListIterator it(signalList);
320 for(; it.current() != 0; ++it)
322 KexiTableItem *item = m_signalsColumnData->createItem();
323 (*item)[0] = TQString(*it);
324 (*item)[1] = (*item)[0];
325 m_signalsColumnData->append(item);
333 for( int i = 1; i < 5; i++)
335 if( !item || (*item)[i].toString().isEmpty())
337 setStatusError( i18n( "<qt>You have not selected item: <b>%1</b>.</qt>").arg(m_data->column(i)->captionAliasOrName()),
344 TQString signal = (*item)[2].toString();
345 signal = signal.remove( TQRegExp( ".*[(]|[)]") );
346 TQString slot = (*item)[4].toString();
347 slot = slot.remove( TQRegExp( ".*[(]|[)]") );
349 if(!signal.startsWith(slot, true))
351 setStatusError( i18n( "The signal/slot arguments are not compatible."), item);
361 m_table->acceptRowEdit();
362 m_table->setCursorPosition(m_table->rows(), 1);
382 Connection *c = new Connection(connection);
383 KexiTableItem *item = m_table->KexiDataAwareObjectInterface::data()->createItem();
384 (*item)[1] = c->sender();
385 (*item)[2] = c->signal();
386 (*item)[3] = c->receiver();
387 (*item)[4] = c->slot();
388 m_table->insertItem(item, m_table->rows());
403ConnectionDialog::removeItem()
405 if(m_table->currentRow() == -1 || m_table->currentRow()>=m_table->rows())
408 int confirm = KMessageBox::warningContinueCancel(parentWidget(),
409 TQString( "<qt>")+i18n( "Do you want to delete this connection ?")+ "</qt>", TQString(), KGuiItem(i18n( "&Delete Connection")),
410 "dontAskBeforeDeleteConnection");
411 if(confirm == KMessageBox::Cancel)
414 m_buffer->remove(m_table->currentRow());
415 m_table->deleteItem(m_table->selectedItem());
420#include "connectiondialog.moc"
void setDescription(const TQString &description)
void setSubType(const TQString &subType)
KexiDB::Field * field() const
void setReadOnly(bool ro) forces readOnly flag to be set to ro
void setRelatedData(KexiTableViewData *data)
KexiTableView class provides a widget for displaying data in a tabular view.
|