tristate KexiWindow::storeDataAs(KexiPart::Item *item, KexiView::StoreNewDataOptions options) { if (neverSaved()) { kWarning() << "The data was never saved, so storeNewData() should be called instead, giving up."; return false; } KexiView *v = selectedView(); if (!v) { return false; } //create schema object and assign information KexiProject *project = KexiMainWindowIface::global()->project(); KexiDB::SchemaData sdata(project->idForClass(d->part->info()->partClass())); if (!d->setupSchemaData(&sdata, item, options)) { return false; } bool cancel = false; KexiDB::SchemaData *newSchemaData; if (isDirty()) { // full save of new data newSchemaData = v->storeNewData(sdata, options, cancel); } else { // there were no changes; full copy of the data is enough // - gives better performance (e.g. tables are copied on server side) // - works without bothering the user (no unnecessary questions) newSchemaData = v->copyData(sdata, options, cancel); } if (cancel) { return cancelled; } if (!newSchemaData) { setStatus(project->dbConnection(), i18n("Saving object's definition failed."), ""); return false; } setSchemaData(newSchemaData); // deletes previous schema if owned if (project->idForClass(part()->info()->partClass()) < 0) { if (!project->createIdForPart(*part()->info())) return false; } // for now this Window has new item assigned d->item = item; // new schema data has now ID updated to a unique value // -assign that to item's identifier item->setIdentifier(d->schemaData->id()); project->addStoredItem(part()->info(), d->item); // set 'dirty' flag on every dialog's view setDirty(false); return true; }
tristate KexiWindow::storeNewData(KexiView::StoreNewDataOptions options) { if (!neverSaved()) { return false; } if (d->schemaData) { return false; //schema must not exist } KexiView *v = selectedView(); if (!v) { return false; } //create schema object and assign information KexiProject *project = KexiMainWindowIface::global()->project(); KexiDB::SchemaData sdata(project->idForClass(d->part->info()->partClass())); if (!d->setupSchemaData(&sdata, d->item, options)) { return false; } bool cancel = false; d->schemaData = v->storeNewData(sdata, options, cancel); if (cancel) return cancelled; if (!d->schemaData) { setStatus(project->dbConnection(), i18n("Saving object's definition failed."), ""); return false; } if (project->idForClass(part()->info()->partClass()) < 0) { if (!project->createIdForPart(*part()->info())) return false; } /* Sets 'dirty' flag on every dialog's view. */ setDirty(false); //new schema data has now ID updated to a unique value //-assign that to item's identifier d->item->setIdentifier(d->schemaData->id()); project->addStoredItem(part()->info(), d->item); return true; }