00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "kexiformscrollview.h"
00022
00023
00024 #include <formeditor/form.h>
00025 #include <formeditor/formmanager.h>
00026 #include <formeditor/objecttree.h>
00027 #include <formeditor/commands.h>
00028 #include <widget/utils/kexirecordmarker.h>
00029
00030 #include <kpopupmenu.h>
00031 #include <kdebug.h>
00032
00033 KexiFormScrollView::KexiFormScrollView(QWidget *parent, bool preview)
00034 : KexiScrollView(parent, preview)
00035 , KexiRecordNavigatorHandler()
00036 , KexiSharedActionClient()
00037 , KexiDataAwareObjectInterface()
00038 , KexiFormDataProvider()
00039 , KexiFormEventHandler()
00040 {
00041 m_currentLocalSortColumn = -1;
00042 m_localSortingOrder = -1;
00043 m_previousItem = 0;
00044 m_navPanel = m_scrollViewNavPanel;
00045 if (preview) {
00046 setRecordNavigatorVisible(true);
00047
00048
00049
00050 }
00051
00052 connect(this, SIGNAL(resizingStarted()), this, SLOT(slotResizingStarted()));
00053
00054 m_popupMenu = new KPopupMenu(this, "contextMenu");
00055
00056
00057 }
00058
00059 KexiFormScrollView::~KexiFormScrollView()
00060 {
00061 if (m_owner)
00062 delete m_data;
00063 m_data = 0;
00064 }
00065
00066 void
00067 KexiFormScrollView::show()
00068 {
00069 KexiScrollView::show();
00070
00071 #if 0 //moved to KexiFormView, OK?
00072
00073 if (m_preview) {
00074 KexiFormView* fv = dynamic_cast<KexiFormView*>(parent());
00075 int resizeMode = fv ? fv->resizeMode() : KexiFormView::ResizeAuto;
00076 if (resizeMode == KexiFormView::ResizeAuto)
00077 setResizePolicy(AutoOneFit);
00078 }
00079 #endif
00080 }
00081
00082 void
00083 KexiFormScrollView::slotResizingStarted()
00084 {
00085 if(m_form && KFormDesigner::FormManager::self())
00086 setSnapToGrid(KFormDesigner::FormManager::self()->snapWidgetsToGrid(), m_form->gridSize());
00087 else
00088 setSnapToGrid(false);
00089 }
00090
00091 int KexiFormScrollView::rowsPerPage() const
00092 {
00094 return 10;
00095 }
00096
00097 void KexiFormScrollView::selectCellInternal()
00098 {
00099
00100 if (m_currentItem) {
00101 if (m_currentItem!=m_previousItem) {
00102 fillDataItems(*m_currentItem, cursorAtNewRow());
00103 m_previousItem = m_currentItem;
00104 }
00105 }
00106 else {
00107 m_previousItem = 0;
00108 }
00109 }
00110
00111 void KexiFormScrollView::ensureCellVisible(int row, int col)
00112 {
00113 Q_UNUSED( row );
00114 Q_UNUSED( col );
00116
00117
00118
00119
00120
00121 }
00122
00123 void KexiFormScrollView::moveToRecordRequested(uint r)
00124 {
00126 selectRow(r);
00127 }
00128
00129 void KexiFormScrollView::moveToLastRecordRequested()
00130 {
00132 selectLastRow();
00133 }
00134
00135 void KexiFormScrollView::moveToPreviousRecordRequested()
00136 {
00138 selectPrevRow();
00139 }
00140
00141 void KexiFormScrollView::moveToNextRecordRequested()
00142 {
00144 selectNextRow();
00145 }
00146
00147 void KexiFormScrollView::moveToFirstRecordRequested()
00148 {
00150 selectFirstRow();
00151 }
00152
00153 void KexiFormScrollView::clearColumnsInternal(bool repaint)
00154 {
00155 Q_UNUSED( repaint );
00157 }
00158
00159 void KexiFormScrollView::addHeaderColumn(const QString& caption, const QString& description,
00160 const QIconSet& icon, int width)
00161 {
00162 Q_UNUSED( caption );
00163 Q_UNUSED( description );
00164 Q_UNUSED( icon );
00165 Q_UNUSED( width );
00166
00168 }
00169
00170 int KexiFormScrollView::currentLocalSortingOrder() const
00171 {
00173 return m_localSortingOrder;
00174 }
00175
00176 int KexiFormScrollView::currentLocalSortColumn() const
00177 {
00178 return m_currentLocalSortColumn;
00179 }
00180
00181 void KexiFormScrollView::setLocalSortingOrder(int col, int order)
00182 {
00184 m_currentLocalSortColumn = col;
00185 m_localSortingOrder = order;
00186 }
00187
00188 void KexiFormScrollView::sortColumnInternal(int col, int order)
00189 {
00190 Q_UNUSED( col );
00191 Q_UNUSED( order );
00193 }
00194
00195 void KexiFormScrollView::updateGUIAfterSorting()
00196 {
00198 }
00199
00200 void KexiFormScrollView::createEditor(int row, int col, const QString& addText,
00201 bool removeOld)
00202 {
00203 Q_UNUSED( row );
00204 Q_UNUSED( addText );
00205 Q_UNUSED( removeOld );
00206
00207 if (isReadOnly()) {
00208 kexipluginsdbg << "KexiFormScrollView::createEditor(): DATA IS READ ONLY!"<<endl;
00209 return;
00210 }
00211 if (column( col )->isReadOnly()) {
00212 kexipluginsdbg << "KexiFormScrollView::createEditor(): COL IS READ ONLY!"<<endl;
00213 return;
00214 }
00215
00217 const bool startRowEdit = !m_rowEditing;
00218
00219 if (!m_rowEditing) {
00220
00221 m_data->clearRowEditBuffer();
00222
00223 m_rowEditing = true;
00224
00225 if (m_verticalHeader)
00226 m_verticalHeader->setEditRow(m_curRow);
00227 if (isInsertingEnabled() && m_currentItem==m_insertItem) {
00228
00229 m_newRowEditing = true;
00230
00231 m_data->append( m_insertItem );
00232
00233 m_insertItem = m_data->createItem();
00234
00235 if (m_verticalHeader)
00236 m_verticalHeader->addLabel();
00237
00238 updateWidgetContentsSize();
00239
00240
00241
00242
00243
00244
00245 }
00246 }
00247
00248 m_editor = editor(col);
00249 if (!m_editor)
00250 return;
00251
00252 if (startRowEdit) {
00253 recordNavigator()->showEditingIndicator(true);
00254
00255
00256 emit rowEditStarted(m_curRow);
00257 }
00258 }
00259
00260 KexiDataItemInterface *KexiFormScrollView::editor( int col, bool ignoreMissingEditor )
00261 {
00262 Q_UNUSED( ignoreMissingEditor );
00263
00264 if (!m_data || col<0 || col>=columns())
00265 return 0;
00266
00267 return dynamic_cast<KexiFormDataItemInterface*>(dbFormWidget()->orderedDataAwareWidgets()->at( col ));
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302 }
00303
00304 void KexiFormScrollView::editorShowFocus( int row, int col )
00305 {
00306 Q_UNUSED( row );
00307 Q_UNUSED( col );
00309
00310
00311 }
00312
00313 void KexiFormScrollView::updateCell(int row, int col)
00314 {
00315 Q_UNUSED( row );
00316 Q_UNUSED( col );
00318 }
00319
00320 void KexiFormScrollView::updateCurrentCell()
00321 {
00322 }
00323
00324 void KexiFormScrollView::updateRow(int row)
00325 {
00326 Q_UNUSED(row)
00328 }
00329
00330 void KexiFormScrollView::updateWidgetContents()
00331 {
00333 }
00334
00335 void KexiFormScrollView::updateWidgetContentsSize()
00336 {
00338 }
00339
00340 void KexiFormScrollView::updateWidgetScrollBars()
00341 {
00343 }
00344
00345 void KexiFormScrollView::slotRowRepaintRequested(KexiTableItem& item)
00346 {
00347 Q_UNUSED( item );
00349 }
00350
00351
00352
00353
00355
00356
00357
00358
00360
00361
00362 void KexiFormScrollView::slotRowInserted(KexiTableItem *item, bool repaint)
00363 {
00364 Q_UNUSED( item );
00365 Q_UNUSED( repaint );
00367 }
00368
00369 void KexiFormScrollView::slotRowInserted(KexiTableItem *item, uint row, bool repaint)
00370 {
00371 Q_UNUSED( item );
00372 Q_UNUSED( row );
00373 Q_UNUSED( repaint );
00375 }
00376
00377 void KexiFormScrollView::slotRowsDeleted( const QValueList<int> & )
00378 {
00380 }
00381
00382 KexiDBForm* KexiFormScrollView::dbFormWidget() const
00383 {
00384 return dynamic_cast<KexiDBForm*>(m_widget);
00385 }
00386
00387 int KexiFormScrollView::columns() const
00388 {
00389 return dbFormWidget()->orderedDataAwareWidgets()->count();
00390 }
00391
00392
00393
00394
00395
00396
00397
00398
00399
00400
00401 bool KexiFormScrollView::columnEditable(int col)
00402 {
00403 kexipluginsdbg << "KexiFormScrollView::columnEditable(" << col << ")" << endl;
00404 foreach_list (QPtrListIterator<KexiFormDataItemInterface>, it, m_dataItems) {
00405 kexipluginsdbg << (dynamic_cast<QWidget*>(it.current()) ? dynamic_cast<QWidget*>(it.current())->name() : "" )
00406 << " " << it.current()->dataSource() << endl;
00407 }
00408 kexipluginsdbg << "-- focus widgets --" << endl;
00409 foreach_list (QPtrListIterator<QWidget>, it, *dbFormWidget()->orderedFocusWidgets()) {
00410 kexipluginsdbg << it.current()->name() << endl;
00411 }
00412 kexipluginsdbg << "-- data-aware widgets --" << endl;
00413 foreach_list (QPtrListIterator<QWidget>, it, *dbFormWidget()->orderedDataAwareWidgets()) {
00414 kexipluginsdbg << it.current()->name() << endl;
00415 }
00416
00417
00418
00419 KexiFormDataItemInterface *item = dynamic_cast<KexiFormDataItemInterface*>(dbFormWidget()->orderedDataAwareWidgets()->at( col ));
00420
00421 if (!item || item->isReadOnly())
00422 return false;
00423
00424
00425
00426 return KexiDataAwareObjectInterface::columnEditable( col );
00427 }
00428
00429 void KexiFormScrollView::valueChanged(KexiDataItemInterface* item)
00430 {
00431 if (!item)
00432 return;
00433
00434 kexipluginsdbg << "** KexiFormScrollView::valueChanged(): editedItem="
00435 << (dbFormWidget()->editedItem ? dbFormWidget()->editedItem->value().toString() : QString::null)
00436 << ", "
00437 << (item ? item->value().toString() : QString::null)
00438 << endl;
00439 if (dbFormWidget()->editedItem!=item) {
00440 kexipluginsdbg << "**>>> dbFormWidget()->editedItem = dynamic_cast<KexiFormDataItemInterface*>(item)" << endl;
00441 dbFormWidget()->editedItem = dynamic_cast<KexiFormDataItemInterface*>(item);
00442 startEditCurrentCell();
00443 }
00444 fillDuplicatedDataItems(dynamic_cast<KexiFormDataItemInterface*>(item), item->value());
00445
00446
00447 dynamic_cast<KexiFormDataItemInterface*>(item)->setDisplayDefaultValue(dynamic_cast<QWidget*>(item), false);
00448 }
00449
00450 bool KexiFormScrollView::cursorAtNewRow() const
00451 {
00452 return isInsertingEnabled() && ( m_currentItem==m_insertItem || m_newRowEditing );
00453 }
00454
00455 void KexiFormScrollView::initDataContents()
00456 {
00457 KexiDataAwareObjectInterface::initDataContents();
00458
00459 if (m_preview) {
00461 setRecordNavigatorVisible(m_data);
00462 recordNavigator()->setEnabled(m_data);
00463 if (m_data) {
00464 recordNavigator()->setEditingIndicatorEnabled( !isReadOnly() );
00465 recordNavigator()->showEditingIndicator(false);
00466 }
00467
00468 dbFormWidget()->updateReadOnlyFlags();
00469 }
00470 }
00471
00472 KexiTableViewColumn* KexiFormScrollView::column(int col)
00473 {
00474 const int id = fieldNumberForColumn(col);
00475 return (id >= 0) ? m_data->column( id ) : 0;
00476 }
00477
00478 bool KexiFormScrollView::shouldDisplayDefaultValueForItem(KexiFormDataItemInterface* itemIface) const
00479 {
00480 return cursorAtNewRow()
00481 && !itemIface->columnInfo()->field->defaultValue().isNull()
00482
00483 && !itemIface->columnInfo()->field->isAutoIncrement();
00484 }
00485
00486 bool KexiFormScrollView::cancelEditor()
00487 {
00488 if (!dynamic_cast<KexiFormDataItemInterface*>(m_editor))
00489 return false;
00490
00491 if (m_errorMessagePopup)
00492 m_errorMessagePopup->close();
00493
00494 KexiFormDataItemInterface *itemIface = dynamic_cast<KexiFormDataItemInterface*>(m_editor);
00495 itemIface->undoChanges();
00496
00497 const bool displayDefaultValue = shouldDisplayDefaultValueForItem(itemIface);
00498
00499 if (itemIface->hasDisplayedDefaultValue() != displayDefaultValue)
00500 itemIface->setDisplayDefaultValue( dynamic_cast<QWidget*>(itemIface), displayDefaultValue );
00501
00502 fillDuplicatedDataItems(itemIface, m_editor->value());
00503
00504
00505 return KexiDataAwareObjectInterface::cancelEditor();
00506 }
00507
00508 void KexiFormScrollView::updateAfterCancelRowEdit()
00509 {
00510 for (QPtrListIterator<KexiFormDataItemInterface> it(m_dataItems); it.current(); ++it) {
00511 if (dynamic_cast<QWidget*>(it.current())) {
00512 kexipluginsdbg << "KexiFormScrollView::updateAfterCancelRowEdit(): "
00513 << dynamic_cast<QWidget*>(it.current())->className() << " "
00514 << dynamic_cast<QWidget*>(it.current())->name() << endl;
00515 }
00516 KexiFormDataItemInterface *itemIface = it.current();
00517 const bool displayDefaultValue = shouldDisplayDefaultValueForItem(itemIface);
00518 itemIface->undoChanges();
00519 if (itemIface->hasDisplayedDefaultValue() != displayDefaultValue)
00520 itemIface->setDisplayDefaultValue( dynamic_cast<QWidget*>(itemIface), displayDefaultValue );
00521 }
00522 recordNavigator()->showEditingIndicator(false);
00523 dbFormWidget()->editedItem = 0;
00524 }
00525
00526 void KexiFormScrollView::updateAfterAcceptRowEdit()
00527 {
00528 if (!m_currentItem)
00529 return;
00530 recordNavigator()->showEditingIndicator(false);
00531 dbFormWidget()->editedItem = 0;
00532
00533 fillDataItems(*m_currentItem, cursorAtNewRow());
00534 m_previousItem = m_currentItem;
00535 }
00536
00537 void KexiFormScrollView::beforeSwitchView()
00538 {
00539 m_editor = 0;
00540 }
00541
00542 void KexiFormScrollView::refreshContentsSize()
00543 {
00544 KexiScrollView::refreshContentsSize();
00545
00546 if (!m_preview && sender()==&m_delayedResize) {
00547 if (m_form)
00548 m_form->clearCommandHistory();
00549 }
00550 }
00551
00552 void KexiFormScrollView::handleDataWidgetAction(const QString& actionName)
00553 {
00554 QWidget *w = focusWidget();
00555 KexiFormDataItemInterface *item = 0;
00556 while (w) {
00557 item = dynamic_cast<KexiFormDataItemInterface*>(w);
00558 if (item)
00559 break;
00560 w = w->parentWidget();
00561 }
00562 if (item)
00563 item->handleAction(actionName);
00564 }
00565
00566 void KexiFormScrollView::copySelection()
00567 {
00568 handleDataWidgetAction("edit_copy");
00569 }
00570
00571 void KexiFormScrollView::cutSelection()
00572 {
00573 handleDataWidgetAction("edit_cut");
00574 }
00575
00576 void KexiFormScrollView::paste()
00577 {
00578 handleDataWidgetAction("edit_paste");
00579 }
00580
00581 int KexiFormScrollView::lastVisibleRow() const
00582 {
00584 return -1;
00585 }
00586
00587 #include "kexiformscrollview.moc"