00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "kexiformview.h"
00022
00023 #include <qobjectlist.h>
00024 #include <qfileinfo.h>
00025
00026 #include <formeditor/form.h>
00027 #include <formeditor/formIO.h>
00028 #include <formeditor/formmanager.h>
00029 #include <formeditor/objecttree.h>
00030 #include <formeditor/container.h>
00031 #include <formeditor/widgetpropertyset.h>
00032 #include <formeditor/commands.h>
00033
00034 #include <kexi.h>
00035 #include <kexidialogbase.h>
00036 #include <kexidragobjects.h>
00037 #include <kexidb/field.h>
00038 #include <kexidb/fieldlist.h>
00039 #include <kexidb/connection.h>
00040 #include <kexidb/cursor.h>
00041 #include <kexidb/utils.h>
00042 #include <kexidb/preparedstatement.h>
00043 #include <tableview/kexitableitem.h>
00044 #include <tableview/kexitableviewdata.h>
00045 #include <widget/kexipropertyeditorview.h>
00046 #include <formeditor/objecttree.h>
00047
00048 #include <koproperty/set.h>
00049 #include <koproperty/property.h>
00050
00051 #include "widgets/kexidbform.h"
00052 #include "kexiformscrollview.h"
00053 #include "kexidatasourcepage.h"
00054 #include "widgets/kexidbautofield.h"
00055
00056 #define NO_DSWIZARD
00057
00059
00060 KexiFormView::KexiFormView(KexiMainWindow *mainWin, QWidget *parent,
00061 const char *name, bool )
00062 : KexiDataAwareView( mainWin, parent, name )
00063 , m_propertySet(0)
00064 , m_resizeMode(KexiFormView::ResizeDefault)
00065 , m_query(0)
00066 , m_queryIsOwned(false)
00067 , m_cursor(0)
00068
00069 {
00070 m_delayedFormContentsResizeOnShow = 0;
00071
00072 QHBoxLayout *l = new QHBoxLayout(this);
00073 l->setAutoAdd(true);
00074
00075 m_scrollView = new KexiFormScrollView(this, viewMode()==Kexi::DataViewMode);
00076
00077
00078
00079
00080 m_dbform = new KexiDBForm(m_scrollView->viewport(), m_scrollView, name);
00081
00082
00083 m_scrollView->setWidget(m_dbform);
00084 m_scrollView->setResizingEnabled(viewMode()!=Kexi::DataViewMode);
00085
00086
00087
00088 if (viewMode()==Kexi::DataViewMode) {
00089 m_scrollView->recordNavigator()->setRecordHandler( m_scrollView );
00090 m_scrollView->viewport()->setPaletteBackgroundColor(m_dbform->palette().active().background());
00091
00092 }
00093 else
00094 {
00095 connect(KFormDesigner::FormManager::self(), SIGNAL(propertySetSwitched(KoProperty::Set*, bool)),
00096 this, SLOT(slotPropertySetSwitched(KoProperty::Set*, bool)));
00097 connect(KFormDesigner::FormManager::self(), SIGNAL(dirty(KFormDesigner::Form *, bool)),
00098 this, SLOT(slotDirty(KFormDesigner::Form *, bool)));
00099
00100 connect(m_dbform, SIGNAL(handleDragMoveEvent(QDragMoveEvent*)),
00101 this, SLOT(slotHandleDragMoveEvent(QDragMoveEvent*)));
00102 connect(m_dbform, SIGNAL(handleDropEvent(QDropEvent*)),
00103 this, SLOT(slotHandleDropEvent(QDropEvent*)));
00104
00105
00106 plugSharedAction("formpart_taborder", KFormDesigner::FormManager::self(), SLOT(editTabOrder()));
00107 plugSharedAction("formpart_adjust_size", KFormDesigner::FormManager::self(), SLOT(adjustWidgetSize()));
00108
00109
00110
00111 plugSharedAction("edit_copy", KFormDesigner::FormManager::self(), SLOT(copyWidget()));
00112 plugSharedAction("edit_cut", KFormDesigner::FormManager::self(), SLOT(cutWidget()));
00113 plugSharedAction("edit_paste", KFormDesigner::FormManager::self(), SLOT(pasteWidget()));
00114 plugSharedAction("edit_delete", KFormDesigner::FormManager::self(), SLOT(deleteWidget()));
00115 plugSharedAction("edit_select_all", KFormDesigner::FormManager::self(), SLOT(selectAll()));
00116 plugSharedAction("formpart_clear_contents", KFormDesigner::FormManager::self(), SLOT(clearWidgetContent()));
00117 plugSharedAction("edit_undo", KFormDesigner::FormManager::self(), SLOT(undo()));
00118 plugSharedAction("edit_redo", KFormDesigner::FormManager::self(), SLOT(redo()));
00119
00120 plugSharedAction("formpart_layout_menu", KFormDesigner::FormManager::self(), 0 );
00121 plugSharedAction("formpart_layout_hbox", KFormDesigner::FormManager::self(), SLOT(layoutHBox()) );
00122 plugSharedAction("formpart_layout_vbox", KFormDesigner::FormManager::self(), SLOT(layoutVBox()) );
00123 plugSharedAction("formpart_layout_grid", KFormDesigner::FormManager::self(), SLOT(layoutGrid()) );
00124 #ifdef KEXI_SHOW_SPLITTER_WIDGET
00125 plugSharedAction("formpart_layout_hsplitter", KFormDesigner::FormManager::self(), SLOT(layoutHSplitter()) );
00126 plugSharedAction("formpart_layout_vsplitter", KFormDesigner::FormManager::self(), SLOT(layoutVSplitter()) );
00127 #endif
00128 plugSharedAction("formpart_break_layout", KFormDesigner::FormManager::self(), SLOT(breakLayout()) );
00129
00130 plugSharedAction("formpart_format_raise", KFormDesigner::FormManager::self(), SLOT(bringWidgetToFront()) );
00131 plugSharedAction("formpart_format_lower", KFormDesigner::FormManager::self(), SLOT(sendWidgetToBack()) );
00132
00133 plugSharedAction("other_widgets_menu", KFormDesigner::FormManager::self(), 0 );
00134 setAvailable("other_widgets_menu", true);
00135
00136 plugSharedAction("formpart_align_menu", KFormDesigner::FormManager::self(), 0 );
00137 plugSharedAction("formpart_align_to_left", KFormDesigner::FormManager::self(),SLOT(alignWidgetsToLeft()) );
00138 plugSharedAction("formpart_align_to_right", KFormDesigner::FormManager::self(), SLOT(alignWidgetsToRight()) );
00139 plugSharedAction("formpart_align_to_top", KFormDesigner::FormManager::self(), SLOT(alignWidgetsToTop()) );
00140 plugSharedAction("formpart_align_to_bottom", KFormDesigner::FormManager::self(), SLOT(alignWidgetsToBottom()) );
00141 plugSharedAction("formpart_align_to_grid", KFormDesigner::FormManager::self(), SLOT(alignWidgetsToGrid()) );
00142
00143 plugSharedAction("formpart_adjust_size_menu", KFormDesigner::FormManager::self(), 0 );
00144 plugSharedAction("formpart_adjust_to_fit", KFormDesigner::FormManager::self(), SLOT(adjustWidgetSize()) );
00145 plugSharedAction("formpart_adjust_size_grid", KFormDesigner::FormManager::self(), SLOT(adjustSizeToGrid()) );
00146 plugSharedAction("formpart_adjust_height_small", KFormDesigner::FormManager::self(), SLOT(adjustHeightToSmall()) );
00147 plugSharedAction("formpart_adjust_height_big", KFormDesigner::FormManager::self(), SLOT(adjustHeightToBig()) );
00148 plugSharedAction("formpart_adjust_width_small", KFormDesigner::FormManager::self(), SLOT(adjustWidthToSmall()) );
00149 plugSharedAction("formpart_adjust_width_big", KFormDesigner::FormManager::self(), SLOT(adjustWidthToBig()) );
00150
00151 plugSharedAction("format_font", KFormDesigner::FormManager::self(), SLOT(changeFont()) );
00152 }
00153
00154 initForm();
00155
00156 KexiDataAwareView::init( m_scrollView, m_scrollView, m_scrollView,
00157 viewMode()==Kexi::DesignViewMode );
00158
00159 connect(this, SIGNAL(focus(bool)), this, SLOT(slotFocus(bool)));
00161
00162 }
00163
00164 KexiFormView::~KexiFormView()
00165 {
00166 deleteQuery();
00167 if (m_cursor) {
00168 KexiDB::Connection *conn = parentDialog()->mainWin()->project()->dbConnection();
00169 conn->deleteCursor(m_cursor);
00170 }
00171
00172
00173
00174
00175 m_propertySet = 0;
00176 propertySetSwitched();
00177 }
00178
00179 void
00180 KexiFormView::deleteQuery()
00181 {
00182 if (m_queryIsOwned) {
00183 delete m_query;
00184 } else {
00186 }
00187 m_query = 0;
00188 }
00189
00190 KFormDesigner::Form*
00191 KexiFormView::form() const
00192 {
00193 if(viewMode()==Kexi::DataViewMode)
00194 return tempData()->previewForm;
00195 else
00196 return tempData()->form;
00197 }
00198
00199 void
00200 KexiFormView::setForm(KFormDesigner::Form *f)
00201 {
00202 if(viewMode()==Kexi::DataViewMode)
00203 tempData()->previewForm = f;
00204 else
00205 tempData()->form = f;
00206 }
00207
00208 void
00209 KexiFormView::initForm()
00210 {
00211 setForm( new KFormDesigner::Form(KexiFormPart::library(), 0, viewMode()==Kexi::DesignViewMode) );
00212
00213
00214 form()->createToplevel(m_dbform, m_dbform);
00215
00216 if (viewMode()==Kexi::DesignViewMode) {
00217
00218 connect(form()->commandHistory(), SIGNAL(commandExecuted()),
00219 KFormDesigner::FormManager::self(), SLOT(slotHistoryCommandExecuted()));
00220 }
00221
00222 const bool newForm = parentDialog()->id() < 0;
00223
00224 KexiDB::FieldList *fields = 0;
00225 if (newForm) {
00226
00227 #ifndef NO_DSWIZARD
00228 KexiDataSourceWizard *w = new KexiDataSourceWizard(mainWin(), (QWidget*)mainWin(), "datasource_wizard");
00229 if(!w->exec())
00230 fields = 0;
00231 else
00232 fields = w->fields();
00233 delete w;
00234 #endif
00235 }
00236
00237 if(fields)
00238 {
00239 QDomDocument dom;
00240 formPart()->generateForm(fields, dom);
00241 KFormDesigner::FormIO::loadFormFromDom(form(), m_dbform, dom);
00243 }
00244 else
00245 loadForm();
00246
00247 if(form()->autoTabStops())
00248 form()->autoAssignTabStops();
00249
00250
00251 m_dbform->updateTabStopsOrder(form());
00252
00253
00254
00255
00256 KFormDesigner::FormManager::self()->importForm(form(), viewMode()==Kexi::DataViewMode);
00257 m_scrollView->setForm(form());
00258
00259
00260
00261
00262
00263
00264 m_scrollView->refreshContentsSize();
00265
00266
00267 if (newForm && !fields) {
00268
00269
00270 m_delayedFormContentsResizeOnShow = 3;
00271 }
00272
00273 updateDataSourcePage();
00274
00275 if (!newForm && viewMode()==Kexi::DesignViewMode) {
00276 form()->clearCommandHistory();
00277 }
00278 }
00279
00280
00281 void
00282 KexiFormView::loadForm()
00283 {
00284
00285
00286 kexipluginsdbg << "KexiFormView::loadForm() Loading the form with id : " << parentDialog()->id() << endl;
00287
00288 if(viewMode()==Kexi::DataViewMode && !tempData()->tempForm.isNull() )
00289 {
00290 KFormDesigner::FormIO::loadFormFromString(form(), m_dbform, tempData()->tempForm);
00291 return;
00292 }
00293
00294
00295 QString data;
00296 loadDataBlock(data);
00297 KFormDesigner::FormIO::loadFormFromString(form(), m_dbform, data);
00298
00299
00300 form()->setAutoTabStops( m_dbform->autoTabStops() );
00301
00303
00304
00305
00306
00307 QString dataSourceString( m_dbform->dataSource() );
00308 QCString dataSourceMimeTypeString( m_dbform->dataSourceMimeType() );
00309 KexiDB::Connection *conn = parentDialog()->mainWin()->project()->dbConnection();
00310 KexiDB::TableOrQuerySchema tableOrQuery(
00311 conn, dataSourceString.latin1(), dataSourceMimeTypeString=="kexi/table");
00312 if (tableOrQuery.table() || tableOrQuery.query()) {
00313 for (KFormDesigner::ObjectTreeDictIterator it(*form()->objectTree()->dict());
00314 it.current(); ++it)
00315 {
00316 KexiDBAutoField *afWidget = dynamic_cast<KexiDBAutoField*>( it.current()->widget() );
00317 if (afWidget) {
00318 KexiDB::QueryColumnInfo *colInfo = tableOrQuery.columnInfo( afWidget->dataSource() );
00319 if (colInfo) {
00320 afWidget->setColumnInfo(colInfo);
00321
00322
00323 }
00324 }
00325 }
00326 }
00327 else {
00328
00329 }
00330 }
00331
00332 void
00333 KexiFormView::slotPropertySetSwitched(KoProperty::Set *set, bool forceReload)
00334 {
00335
00336
00337 m_propertySet = set;
00338 if (forceReload)
00339 propertySetReloaded(true);
00340 else
00341 propertySetSwitched();
00342
00343 formPart()->dataSourcePage()->assignPropertySet(m_propertySet);
00344 }
00345
00346 tristate
00347 KexiFormView::beforeSwitchTo(int mode, bool &dontStore)
00348 {
00349 if (mode!=viewMode()) {
00350 if (viewMode()==Kexi::DataViewMode) {
00351 if (!m_scrollView->acceptRowEdit())
00352 return cancelled;
00353
00354 m_scrollView->beforeSwitchView();
00355 }
00356 else {
00357
00358 tempData()->scrollViewContentsPos
00359 = QPoint(m_scrollView->contentsX(), m_scrollView->contentsY());
00360 }
00361 }
00362
00363
00364 dontStore = true;
00365 if(dirty() && (mode == Kexi::DataViewMode) && form()->objectTree()) {
00366 KexiFormPart::TempData* temp = tempData();
00367 if (!KFormDesigner::FormIO::saveFormToString(form(), temp->tempForm))
00368 return false;
00369 }
00370
00371 return true;
00372 }
00373
00374 tristate
00375 KexiFormView::afterSwitchFrom(int mode)
00376 {
00377 if (mode == 0 || mode == Kexi::DesignViewMode) {
00378 if (parentDialog()->neverSaved()) {
00379 m_dbform->resize(QSize(400, 300));
00380 m_scrollView->refreshContentsSizeLater(true,true);
00381
00382 }
00383 }
00384
00385 if (mode != 0 && mode != Kexi::DesignViewMode) {
00386
00387 m_scrollView->setContentsPos(tempData()->scrollViewContentsPos.x(),
00388 tempData()->scrollViewContentsPos.y());
00389 }
00390
00391
00392
00393
00394
00395
00396 if((mode == Kexi::DesignViewMode) && viewMode()==Kexi::DataViewMode) {
00397
00398 delete m_dbform;
00399 m_dbform = new KexiDBForm(m_scrollView->viewport(), m_scrollView, "KexiDBForm");
00400 m_scrollView->setWidget(m_dbform);
00401
00402 initForm();
00403
00404
00405
00406 m_scrollView->setContentsPos(0,0);
00407 m_dbform->move(0,0);
00408
00409 }
00410
00411
00412 if (viewMode()==Kexi::DataViewMode) {
00413
00414
00415
00416
00417
00418 }
00419 else {
00420
00421 m_dbform->setAutoTabStops( form()->autoTabStops() );
00422 }
00423
00424 if (viewMode() == Kexi::DataViewMode) {
00425
00426 initDataSource();
00427
00428
00429 m_scrollView->setMainWidgetForEventHandling(parentDialog()->mainWin(), m_dbform);
00430
00431
00432 if (!m_dbform->orderedFocusWidgets()->isEmpty()) {
00433
00434
00435 QEvent fe( QEvent::FocusOut );
00436 QFocusEvent::setReason(QFocusEvent::Tab);
00437 QApplication::sendEvent( qApp->focusWidget(), &fe );
00438 QFocusEvent::resetReason();
00439
00440
00441 QPtrListIterator<QWidget> it(*m_dbform->orderedFocusWidgets());
00442 for (;it.current(); ++it) {
00443 KexiFormDataItemInterface *iface = dynamic_cast<KexiFormDataItemInterface*>(it.current());
00444 if (iface)
00445 kexipluginsdbg << iface->dataSource() << endl;
00446 if (iface && iface->columnInfo() && !iface->isReadOnly()
00448
00449 && !iface->columnInfo()->field->isAutoIncrement())
00450 break;
00451 }
00452 if (!it.current())
00453 it.toFirst();
00454
00455 it.current()->setFocus();
00456 SET_FOCUS_USING_REASON(it.current(), QFocusEvent::Tab);
00457 m_setFocusInternalOnce = it.current();
00458 }
00459
00460 if (m_query)
00461 m_scrollView->selectFirstRow();
00462 }
00463
00464
00465 if (mode == 0)
00466 setDirty( parentDialog()->partItem()->neverSaved() );
00467
00468 if (mode==Kexi::DataViewMode && viewMode()==Kexi::DesignViewMode) {
00469
00470
00471 }
00472
00473 return true;
00474 }
00475
00476 void KexiFormView::initDataSource()
00477 {
00478 deleteQuery();
00479 QString dataSourceString( m_dbform->dataSource() );
00480 QCString dataSourceMimeTypeString( m_dbform->dataSourceMimeType() );
00482 bool ok = !dataSourceString.isEmpty();
00483
00484
00485
00486
00487
00488
00489
00490 KexiDB::TableSchema *tableSchema = 0;
00491 KexiDB::Connection *conn = 0;
00492 QStringList sources;
00493
00494 if (ok) {
00495
00496
00497
00498 m_scrollView->setMainDataSourceWidget(m_dbform);
00499 sources = m_scrollView->usedDataSources();
00500 conn = parentDialog()->mainWin()->project()->dbConnection();
00501 if (dataSourceMimeTypeString.isEmpty()
00502 || dataSourceMimeTypeString=="kexi/table")
00503 {
00504 tableSchema = conn->tableSchema( dataSourceString );
00505 if (tableSchema) {
00506
00507 m_query = new KexiDB::QuerySchema();
00508 m_queryIsOwned = true;
00509
00510 if (dataSourceMimeTypeString.isEmpty())
00511 m_dbform->setDataSourceMimeType("kexi/table");
00512 }
00513 }
00514
00515 if (!tableSchema) {
00516 if (dataSourceMimeTypeString.isEmpty()
00517 || dataSourceMimeTypeString=="kexi/query")
00518 {
00519
00520
00521
00523 m_query = conn->querySchema( dataSourceString );
00524 m_queryIsOwned = false;
00525 ok = m_query != 0;
00526 if (ok && dataSourceMimeTypeString.isEmpty())
00527 m_dbform->setDataSourceMimeType("kexi/query");
00528 }
00529 else
00530 ok = false;
00531 }
00532 }
00533
00534 QValueList<uint> invalidSources;
00535 if (ok) {
00536 KexiDB::IndexSchema *pkey = tableSchema ? tableSchema->primaryKey() : 0;
00537 if (pkey) {
00538
00539
00540 sources += pkey->names();
00541 KexiDBDbg << "KexiFormView::initDataSource(): pkey added to data sources: " << pkey->names() << endl;
00542 }
00543
00544 uint index = 0;
00545 for (QStringList::ConstIterator it = sources.constBegin();
00546 it!=sources.constEnd(); ++it, index++) {
00548 QString fieldName( (*it).lower() );
00549
00550 if (tableSchema && fieldName.startsWith( tableSchema->name().lower()+"." ))
00551 fieldName = fieldName.mid(tableSchema->name().length()+1);
00552
00553 if (!tableSchema && fieldName.startsWith( m_query->name().lower()+"." ))
00554 fieldName = fieldName.mid(m_query->name().length()+1);
00555 KexiDB::Field *f = tableSchema ? tableSchema->field(fieldName) : m_query->field(fieldName);
00556 if (!f) {
00558
00559 invalidSources += index;
00560 continue;
00561 }
00562 if (tableSchema) {
00563 if (!m_query->hasField( f )) {
00564
00565 m_query->addField( f );
00566 }
00567 }
00568 }
00569 if (invalidSources.count()==sources.count()) {
00570
00571 deleteQuery();
00572 }
00573 else {
00574 m_cursor = conn->executeQuery( *m_query );
00575 }
00576 m_scrollView->invalidateDataSources( invalidSources, m_query );
00577 ok = m_cursor!=0;
00578 }
00579
00580 if (!invalidSources.isEmpty())
00581 m_dbform->updateTabStopsOrder();
00582
00583 if (ok) {
00586 KexiTableViewData* data = new KexiTableViewData(m_cursor);
00587 data->preloadAllRows();
00588
00590
00591
00592
00593
00594
00595
00596
00597
00598 m_scrollView->setData( data, true );
00599 }
00600 else
00601 m_scrollView->setData( 0, false );
00602 }
00603
00604 void
00605 KexiFormView::slotDirty(KFormDesigner::Form *dirtyForm, bool isDirty)
00606 {
00607 if(dirtyForm == form())
00608 KexiViewBase::setDirty(isDirty);
00609 }
00610
00611 KexiDB::SchemaData*
00612 KexiFormView::storeNewData(const KexiDB::SchemaData& sdata, bool &cancel)
00613 {
00614 KexiDB::SchemaData *s = KexiViewBase::storeNewData(sdata, cancel);
00615 kexipluginsdbg << "KexiDBForm::storeNewData(): new id:" << s->id() << endl;
00616
00617 if (!s || cancel) {
00618 delete s;
00619 return 0;
00620 }
00621 if (!storeData()) {
00622
00623 KexiDB::Connection *conn = parentDialog()->mainWin()->project()->dbConnection();
00624 conn->removeObject( s->id() );
00625 delete s;
00626 return 0;
00627 }
00628 return s;
00629 }
00630
00631 tristate
00632 KexiFormView::storeData(bool dontAsk)
00633 {
00634 Q_UNUSED(dontAsk);
00635 kexipluginsdbg << "KexiDBForm::storeData(): " << parentDialog()->partItem()->name()
00636 << " [" << parentDialog()->id() << "]" << endl;
00637
00638
00640 KexiDB::Connection *conn = parentDialog()->mainWin()->project()->dbConnection();
00641 KexiDB::TableSchema *blobsTable = conn->tableSchema("kexi__blobs");
00642 if (!blobsTable) {
00644 return false;
00645 }
00646
00647 QStringList blobsFieldNamesWithoutID(blobsTable->names());
00648 blobsFieldNamesWithoutID.pop_front();
00649 KexiDB::FieldList *blobsFieldsWithoutID = blobsTable->subList(blobsFieldNamesWithoutID);
00650
00651 KexiDB::PreparedStatement::Ptr st = conn->prepareStatement(
00652 KexiDB::PreparedStatement::InsertStatement, *blobsFieldsWithoutID);
00653
00655 if (!st) {
00656 delete blobsFieldsWithoutID;
00658 return false;
00659 }
00660
00661 KexiBLOBBuffer *blobBuf = KexiBLOBBuffer::self();
00662 for (QMapConstIterator<QWidget*, KexiBLOBBuffer::Id_t> it = m_unsavedLocalBLOBs.constBegin();
00663 it!=m_unsavedLocalBLOBs.constEnd(); ++it)
00664 {
00665 if (!it.key()) {
00666 kexipluginswarn << "KexiFormView::storeData(): it.key()==0 !" << endl;
00667 continue;
00668 }
00669 kexipluginsdbg << "name=" << it.key()->name() << " dataID=" << it.data() << endl;
00670 KexiBLOBBuffer::Handle h( blobBuf->objectForId(it.data(), false) );
00671 if (!h)
00672 continue;
00673
00674 QString originalFileName(h.originalFileName());
00675 QFileInfo fi(originalFileName);
00676 QString caption(fi.baseName().replace('_', " ").simplifyWhiteSpace());
00678
00679
00680 if (st) {
00681 *st
00682 << h.data() << originalFileName << caption
00683 << h.mimeType() << (uint)h.folderId();
00684 if (!st->execute()) {
00685 delete blobsFieldsWithoutID;
00686 kexipluginsdbg << " execute error" << endl;
00687 return false;
00688 }
00689 }
00691 #if 0
00692 if (!conn->insertRecord(*blobsFieldsWithoutID, h.data(), originalFileName, caption, h.mimeType())) {
00693 delete blobsFieldsWithoutID;
00695 return false;
00696 }
00697 #endif
00698 delete blobsFieldsWithoutID;
00699 blobsFieldsWithoutID=0;
00700 const Q_ULLONG storedBLOBID = conn->lastInsertedAutoIncValue("o_id", "kexi__blobs");
00701 if ((Q_ULLONG)-1 == storedBLOBID) {
00703 return false;
00704 }
00705 kexipluginsdbg << " storedDataID=" << storedBLOBID << endl;
00706 h.setStoredWidthID((KexiBLOBBuffer::Id_t )storedBLOBID);
00707
00708 const QVariant oldStoredPixmapId( it.key()->property("storedPixmapId") );
00709 it.key()->setProperty("storedPixmapId",
00710 QVariant((uint )storedBLOBID));
00711 KFormDesigner::ObjectTreeItem *widgetItem = form()->objectTree()->lookup(it.key()->name());
00712 if (widgetItem)
00713 widgetItem->addModifiedProperty( "storedPixmapId", oldStoredPixmapId );
00714 else
00715 kexipluginswarn << "KexiFormView::storeData(): no '" << widgetItem->name() << "' widget found within a form" << endl;
00716 }
00717
00718
00719
00720 QString data;
00721 if (!KFormDesigner::FormIO::saveFormToString(tempData()->form, data))
00722 return false;
00723 if (!storeDataBlock(data))
00724 return false;
00725
00726
00727 m_unsavedLocalBLOBs.clear();
00728
00729 tempData()->tempForm = QString::null;
00730 return true;
00731 }
00732
00733 #if 0
00734
00735 void
00736 KexiFormView::slotWidgetSelected(KFormDesigner::Form *f, bool multiple)
00737 {
00738 if(f != form())
00739 return;
00740
00741 enableFormActions();
00742
00743 setAvailable("edit_copy", true);
00744 setAvailable("edit_cut", true);
00745 setAvailable("edit_clear", true);
00746
00747
00748 setAvailable("formpart_align_menu", multiple);
00749 setAvailable("formpart_align_to_left", multiple);
00750 setAvailable("formpart_align_to_right", multiple);
00751 setAvailable("formpart_align_to_top", multiple);
00752 setAvailable("formpart_align_to_bottom", multiple);
00753
00754 setAvailable("formpart_adjust_size_menu", true);
00755 setAvailable("formpart_adjust_width_small", multiple);
00756 setAvailable("formpart_adjust_width_big", multiple);
00757 setAvailable("formpart_adjust_height_small", multiple);
00758 setAvailable("formpart_adjust_height_big", multiple);
00759
00760 setAvailable("formpart_format_raise", true);
00761 setAvailable("formpart_format_lower", true);
00762
00763
00764 if(!multiple)
00765 {
00766 KFormDesigner::ObjectTreeItem *item = f->objectTree()->lookup( f->selectedWidgets()->first()->name() );
00767 if(item && item->container())
00768 multiple = true;
00769 }
00770
00771 setAvailable("formpart_layout_hbox", multiple);
00772 setAvailable("formpart_layout_vbox", multiple);
00773 setAvailable("formpart_layout_grid", multiple);
00774
00775 KFormDesigner::Container *container = f->activeContainer();
00776 setAvailable("formpart_break_layout", container ?
00777 (container->layoutType() != KFormDesigner::Container::NoLayout) : false );
00778 }
00779
00780 void
00781 KexiFormView::slotFormWidgetSelected(KFormDesigner::Form *f)
00782 {
00783 if(f != form())
00784 return;
00785
00786 disableWidgetActions();
00787 enableFormActions();
00788
00789
00790 setAvailable("formpart_layout_hbox", true);
00791 setAvailable("formpart_layout_vbox", true);
00792 setAvailable("formpart_layout_grid", true);
00793 setAvailable("formpart_break_layout", (f->toplevelContainer()->layoutType() != KFormDesigner::Container::NoLayout));
00794 }
00795
00796 void
00797 KexiFormView::slotNoFormSelected()
00798 {
00799 disableWidgetActions();
00800
00801
00802 setAvailable("edit_paste", false);
00803 setAvailable("edit_undo", false);
00804 setAvailable("edit_redo", false);
00805
00806
00807 setAvailable("formpart_pixmap_collection", false);
00808 setAvailable("formpart_connections", false);
00809 setAvailable("formpart_taborder", false);
00810 setAvailable("formpart_change_style", false);
00811 }
00812
00813 void
00814 KexiFormView::enableFormActions()
00815 {
00816
00817 setAvailable("formpart_pixmap_collection", true);
00818 setAvailable("formpart_connections", true);
00819 setAvailable("formpart_taborder", true);
00820
00821 setAvailable("edit_paste", KFormDesigner::FormManager::self()->isPasteEnabled());
00822 }
00823
00824 void
00825 KexiFormView::disableWidgetActions()
00826 {
00827
00828 setAvailable("edit_copy", false);
00829 setAvailable("edit_cut", false);
00830 setAvailable("edit_clear", false);
00831
00832
00833 setAvailable("formpart_align_menu", false);
00834 setAvailable("formpart_align_to_left", false);
00835 setAvailable("formpart_align_to_right", false);
00836 setAvailable("formpart_align_to_top", false);
00837 setAvailable("formpart_align_to_bottom", false);
00838
00839 setAvailable("formpart_adjust_size_menu", false);
00840 setAvailable("formpart_adjust_width_small", false);
00841 setAvailable("formpart_adjust_width_big", false);
00842 setAvailable("formpart_adjust_height_small", false);
00843 setAvailable("formpart_adjust_height_big", false);
00844
00845 setAvailable("formpart_format_raise", false);
00846 setAvailable("formpart_format_lower", false);
00847
00848 setAvailable("formpart_layout_hbox", false);
00849 setAvailable("formpart_layout_vbox", false);
00850 setAvailable("formpart_layout_grid", false);
00851 setAvailable("formpart_break_layout", false);
00852 }
00853
00854 void
00855 KexiFormView::setUndoEnabled(bool enabled)
00856 {
00857 setAvailable("edit_undo", enabled);
00858 }
00859
00860 void
00861 KexiFormView::setRedoEnabled(bool enabled)
00862 {
00863 setAvailable("edit_redo", enabled);
00864 }
00865 #endif //0
00866
00867 QSize
00868 KexiFormView::preferredSizeHint(const QSize& otherSize)
00869 {
00870 if (parentDialog()->neverSaved()) {
00871
00872
00873 }
00874
00875 return (m_dbform->size()
00876 +QSize(m_scrollView->verticalScrollBar()->isVisible() ? m_scrollView->verticalScrollBar()->width()*3/2 : 10,
00877 m_scrollView->horizontalScrollBar()->isVisible() ? m_scrollView->horizontalScrollBar()->height()*3/2 : 10))
00878 .expandedTo( KexiViewBase::preferredSizeHint(otherSize) );
00879 }
00880
00881 void
00882 KexiFormView::resizeEvent( QResizeEvent *e )
00883 {
00884 if (viewMode()==Kexi::DataViewMode) {
00885 m_scrollView->refreshContentsSizeLater(
00886 e->size().width()!=e->oldSize().width(),
00887 e->size().height()!=e->oldSize().height()
00888 );
00889 }
00890 KexiViewBase::resizeEvent(e);
00891 m_scrollView->updateNavPanelGeometry();
00892 if (m_delayedFormContentsResizeOnShow>0) {
00893 m_delayedFormContentsResizeOnShow--;
00894 m_dbform->resize( e->size() - QSize(30, 30) );
00895 }
00896 }
00897
00898 void
00899 KexiFormView::setFocusInternal()
00900 {
00901 if (viewMode() == Kexi::DataViewMode) {
00902 if (m_dbform->focusWidget()) {
00903
00904 if (m_setFocusInternalOnce) {
00905 SET_FOCUS_USING_REASON(m_setFocusInternalOnce, QFocusEvent::Tab);
00906 }
00907 else {
00908 SET_FOCUS_USING_REASON(m_dbform->focusWidget(), QFocusEvent::Tab);
00909 }
00910 return;
00911 }
00912 }
00913 QWidget::setFocus();
00914 }
00915
00916 void
00917 KexiFormView::show()
00918 {
00919 KexiDataAwareView::show();
00920
00921
00922
00923
00924
00925 if (viewMode()==Kexi::DataViewMode) {
00926 if (resizeMode() == KexiFormView::ResizeAuto)
00927 m_scrollView->setResizePolicy(QScrollView::AutoOneFit);
00928 }
00929 }
00930
00931 void
00932 KexiFormView::slotFocus(bool in)
00933 {
00934 if(in && form() && KFormDesigner::FormManager::self() && KFormDesigner::FormManager::self()->activeForm() != form()) {
00935 KFormDesigner::FormManager::self()->windowChanged(m_dbform);
00936 updateDataSourcePage();
00937 }
00938 }
00939
00940 void
00941 KexiFormView::updateDataSourcePage()
00942 {
00943 if (viewMode()==Kexi::DesignViewMode) {
00944 QCString dataSourceMimeType, dataSource;
00945 KFormDesigner::WidgetPropertySet *set = KFormDesigner::FormManager::self()->propertySet();
00946 if (set->contains("dataSourceMimeType"))
00947 dataSourceMimeType = (*set)["dataSourceMimeType"].value().toCString();
00948 if (set->contains("dataSource"))
00949 dataSource = (*set)["dataSource"].value().toCString();
00950
00951 formPart()->dataSourcePage()->setDataSource(dataSourceMimeType, dataSource);
00952 }
00953 }
00954
00955 void
00956 KexiFormView::slotHandleDragMoveEvent(QDragMoveEvent* e)
00957 {
00958 if (KexiFieldDrag::canDecodeMultiple( e )) {
00959 e->accept(true);
00960
00961 }
00962 }
00963
00964 void
00965 KexiFormView::slotHandleDropEvent(QDropEvent* e)
00966 {
00967 if (KexiFieldDrag::canDecodeMultiple( e )) {
00968 QString sourceMimeType, sourceName;
00969 QStringList fields;
00970 if (!KexiFieldDrag::decodeMultiple( e, sourceMimeType, sourceName, fields ))
00971 return;
00972 insertAutoFields(sourceMimeType, sourceName, fields, e->pos());
00973 }
00974 }
00975
00976 void
00977 KexiFormView::insertAutoFields(const QString& sourceMimeType, const QString& sourceName,
00978 const QStringList& fields, const QPoint& _pos)
00979 {
00980 if (fields.isEmpty())
00981 return;
00982
00983 KexiDB::Connection *conn = parentDialog()->mainWin()->project()->dbConnection();
00984 KexiDB::TableOrQuerySchema tableOrQuery(conn, sourceName.latin1(), sourceMimeType=="kexi/table");
00985 if (!tableOrQuery.table() && !tableOrQuery.query()) {
00986 kexipluginswarn << "KexiFormView::insertAutoFields(): no such table/query \""
00987 << sourceName << "\"" << endl;
00988 return;
00989 }
00990
00991 QPoint pos(_pos);
00992
00993 if (pos==QPoint(-1,-1)) {
00994 if (m_widgetGeometryForRecentInsertAutoFields.isValid()) {
00995 pos = m_widgetGeometryForRecentInsertAutoFields.bottomLeft()
00996 + QPoint(0,form()->gridSize());
00997 }
00998 else {
00999 pos = QPoint(40, 40);
01000 }
01001 }
01002
01004
01005
01006 KFormDesigner::WidgetList widgetsToSelect;
01007 KFormDesigner::CommandGroup *group = new KFormDesigner::CommandGroup(
01008 fields.count()==1 ? i18n("Insert AutoField widget") : i18n("Insert %1 AutoField widgets").arg(fields.count()),
01009 KFormDesigner::FormManager::self()->propertySet()
01010 );
01011
01012 foreach( QStringList::ConstIterator, it, fields ) {
01013 KexiDB::QueryColumnInfo* column = tableOrQuery.columnInfo(*it);
01014 if (!column) {
01015 kexipluginswarn << "KexiFormView::insertAutoFields(): no such field \""
01016 << *it << "\" in table/query \"" << sourceName << "\"" << endl;
01017 continue;
01018 }
01020 KFormDesigner::InsertWidgetCommand *insertCmd
01021 = new KFormDesigner::InsertWidgetCommand(form()->toplevelContainer(),
01023 "KexiDBAutoField",
01025 pos, column->aliasOrName()
01026 );
01027 insertCmd->execute();
01028 group->addCommand(insertCmd, false);
01029
01030 KFormDesigner::ObjectTreeItem *newWidgetItem
01031 = form()->objectTree()->dict()->find(insertCmd->widgetName());
01032 KexiDBAutoField* newWidget
01033 = newWidgetItem ? dynamic_cast<KexiDBAutoField*>(newWidgetItem->widget()) : 0;
01034 widgetsToSelect.append(newWidget);
01035
01036 KFormDesigner::CommandGroup *subGroup
01037 = new KFormDesigner::CommandGroup("", KFormDesigner::FormManager::self()->propertySet());
01038 QMap<QCString, QVariant> propValues;
01039 propValues.insert("dataSource", column->aliasOrName());
01040 propValues.insert("fieldTypeInternal", (int)column->field->type());
01041 propValues.insert("fieldCaptionInternal", column->captionOrAliasOrName());
01042 KFormDesigner::FormManager::self()->propertySet()->createPropertyCommandsInDesignMode(
01043 newWidget, propValues, subGroup, false,
01044 true );
01045 subGroup->execute();
01046 group->addCommand( subGroup, false );
01047
01048
01049
01050
01051
01052
01053
01054
01055
01056
01057 KFormDesigner::WidgetList list;
01058 list.append(newWidget);
01059 KFormDesigner::AdjustSizeCommand *adjustCommand
01060 = new KFormDesigner::AdjustSizeCommand(KFormDesigner::AdjustSizeCommand::SizeToFit,
01061 list, form());
01062 adjustCommand->execute();
01063 group->addCommand( adjustCommand,
01064 false
01065 );
01066
01067 if (newWidget) {
01068 pos.setY( pos.y() + newWidget->height() + form()->gridSize());
01069 }
01070 }
01071 if (widgetsToSelect.last()) {
01072
01073 QRect oldFormRect( m_dbform->geometry() );
01074 QRect newFormRect( oldFormRect );
01075 newFormRect.setWidth(QMAX(m_dbform->width(), widgetsToSelect.last()->geometry().right()+1));
01076 newFormRect.setHeight(QMAX(m_dbform->height(), widgetsToSelect.last()->geometry().bottom()+1));
01077 if (newFormRect != oldFormRect) {
01078
01079 m_dbform->setGeometry( newFormRect );
01080
01081 KFormDesigner::PropertyCommand *resizeFormCommand = new KFormDesigner::PropertyCommand(
01082 KFormDesigner::FormManager::self()->propertySet(), m_dbform->name(),
01083 oldFormRect, newFormRect, "geometry");
01084 group->addCommand(resizeFormCommand, true);
01085 }
01086
01087
01088 m_widgetGeometryForRecentInsertAutoFields = widgetsToSelect.last()->geometry();
01089 }
01090
01091
01092 form()->addCommand( group, true );
01093
01094
01095
01096
01097 group->resetAllowExecuteFlags();
01098
01099 m_scrollView->repaint();
01100 m_scrollView->viewport()->repaint();
01101 m_scrollView->repaintContents();
01102 m_scrollView->updateContents();
01103 m_scrollView->clipper()->repaint();
01104 m_scrollView->refreshContentsSize();
01105
01106
01107 if (widgetsToSelect.count()>1) {
01108 form()->setSelectedWidget(0);
01109 foreach_list (KFormDesigner::WidgetListIterator, it, widgetsToSelect)
01110 form()->setSelectedWidget(it.current(), true, true);
01111 }
01112 }
01113
01114 void
01115 KexiFormView::setUnsavedLocalBLOB(QWidget *widget, KexiBLOBBuffer::Id_t id)
01116 {
01118 if (id==0)
01119 m_unsavedLocalBLOBs.remove(widget);
01120 else
01121 m_unsavedLocalBLOBs.insert(widget, id);
01122 }
01123
01124
01125
01126
01127
01128
01129
01130
01131
01132
01133
01134
01135
01136
01137
01138
01139
01140
01141
01142
01143
01144
01145
01146
01147
01148
01149
01150
01151
01152
01153 #include "kexiformview.moc"
01154