20#include "kexitabledesignerview_p.h"
21#include "kexitabledesignerview.h"
25#include <tqsplitter.h>
27#include <kiconloader.h>
31#include <tdepopupmenu.h>
32#include <tdemessagebox.h>
34#include <koproperty/set.h>
36#include <kexidb/cursor.h>
37#include <kexidb/tableschema.h>
38#include <kexidb/connection.h>
39#include <kexidb/utils.h>
40#include <kexidb/roweditbuffer.h>
41#include <kexidb/error.h>
42#include <kexiutils/identifier.h>
43#include <kexiproject.h>
44#include <keximainwindow.h>
45#include <widget/tableview/kexidataawarepropertyset.h>
46#include <widget/kexicustompropertyfactory.h>
47#include <kexiutils/utils.h>
48#include <kexidialogbase.h>
49#include <kexitableview.h>
50#include "kexitabledesignercommands.h"
52using namespace KexiTableDesignerCommands;
56CommandHistory::CommandHistory(TDEActionCollection *actionCollection,
bool withMenus)
57 : KCommandHistory(actionCollection, withMenus)
62 setUndoLimit(INT_MAX);
63 setRedoLimit(INT_MAX);
66void CommandHistory::addCommand(KCommand *command,
bool execute)
68 KCommandHistory::addCommand(command, execute);
69 m_commandsToUndo.append(command);
72void CommandHistory::undo()
74 if (!m_commandsToUndo.isEmpty()) {
75 KCommand * cmd = m_commandsToUndo.take( m_commandsToUndo.count()-1 );
76 m_commandsToRedo.append( cmd );
78 KCommandHistory::undo();
81void CommandHistory::redo()
83 if (!m_commandsToRedo.isEmpty()) {
84 KCommand * cmd = m_commandsToRedo.take( m_commandsToRedo.count()-1 );
85 m_commandsToUndo.append( cmd );
87 KCommandHistory::redo();
90void CommandHistory::clear() {
91 KCommandHistory::clear(); m_commandsToUndo.clear();
97 : designerView(aDesignerView)
100 , dontAskOnStoreData(false)
101 , slotTogglePrimaryKeyCalled(false)
102 , primaryKeyExists(false)
103 , slotPropertyChanged_primaryKey_enabled(true)
104 , slotPropertyChanged_subType_enabled(true)
105 , addHistoryCommand_in_slotPropertyChanged_enabled(true)
106 , addHistoryCommand_in_slotRowUpdated_enabled(true)
107 , addHistoryCommand_in_slotAboutToDeleteRow_enabled(true)
108 , addHistoryCommand_in_slotRowInserted_enabled(true)
109 , slotBeforeCellChanged_enabled(true)
110 , tempStoreDataUsingRealAlterTable(false)
112 historyActionCollection =
new TDEActionCollection((TQWidget*)0,
"");
113 history =
new CommandHistory(historyActionCollection,
true);
115 internalPropertyNames.insert(
"subType",(
char*)1);
116 internalPropertyNames.insert(
"uid",(
char*)1);
117 internalPropertyNames.insert(
"newrow",(
char*)1);
118 internalPropertyNames.insert(
"rowSource",(
char*)1);
119 internalPropertyNames.insert(
"rowSourceType",(
char*)1);
120 internalPropertyNames.insert(
"boundColumn",(
char*)1);
121 internalPropertyNames.insert(
"visibleColumn",(
char*)1);
124KexiTableDesignerViewPrivate::~KexiTableDesignerViewPrivate() {
126 delete historyActionCollection;
130int KexiTableDesignerViewPrivate::generateUniqueId()
132 return ++uniqueIdCounter;
135void KexiTableDesignerViewPrivate::setPropertyValueIfNeeded(
136 const KoProperty::Set& set,
const TQCString& propertyName,
137 const TQVariant& newValue,
const TQVariant& oldValue, CommandGroup* commandGroup,
138 bool forceAddCommand,
bool rememberOldValue,
139 TQStringList*
const slist, TQStringList*
const nlist)
141 KoProperty::Property&
property = set[propertyName];
143 KoProperty::Property::ListData *oldListData =
property.listData() ?
144 new KoProperty::Property::ListData(*property.listData()) : 0;
145 if (slist && nlist) {
146 if (slist->isEmpty() || nlist->isEmpty()) {
147 property.setListData(0);
150 property.setListData(*slist, *nlist);
153 if (oldValue.type() == newValue.type()
154 && (oldValue == newValue || (!oldValue.isValid() && !newValue.isValid()))
160 const bool prev_addHistoryCommand_in_slotPropertyChanged_enabled
161 = addHistoryCommand_in_slotPropertyChanged_enabled;
162 addHistoryCommand_in_slotPropertyChanged_enabled =
false;
163 if (property.value() != newValue)
164 property.setValue( newValue, rememberOldValue );
166 commandGroup->addCommand(
168 oldListData, property.listData()) );
171 addHistoryCommand_in_slotPropertyChanged_enabled
172 = prev_addHistoryCommand_in_slotPropertyChanged_enabled;
175void KexiTableDesignerViewPrivate::setPropertyValueIfNeeded(
176 const KoProperty::Set& set,
const TQCString& propertyName,
177 const TQVariant& newValue, CommandGroup* commandGroup,
178 bool forceAddCommand,
bool rememberOldValue,
179 TQStringList*
const slist, TQStringList*
const nlist)
181 KoProperty::Property&
property = set[propertyName];
182 TQVariant oldValue( property.value() );
183 setPropertyValueIfNeeded( set, propertyName, newValue, property.value(),
184 commandGroup, forceAddCommand, rememberOldValue, slist, nlist);
187void KexiTableDesignerViewPrivate::setVisibilityIfNeeded(
const KoProperty::Set& set, KoProperty::Property* prop,
188 bool visible,
bool &changed, CommandGroup *commandGroup )
190 if (prop->isVisible() != visible) {
192 commandGroup->addCommand(
195 prop->setVisible( visible );
200bool KexiTableDesignerViewPrivate::updatePropertiesVisibility(
KexiDB::Field::Type fieldType, KoProperty::Set &set,
201 CommandGroup *commandGroup)
203 bool changed =
false;
204 KoProperty::Property *prop;
207 prop = &set[
"subType"];
208 kexipluginsdbg <<
"subType=" << prop->value().toInt() <<
" type=" << set[
"type"].value().toInt()<< endl;
211 visible = (prop->listData() && prop->listData()->keys.count() > 1 )
212 && set[
"primaryKey"].value().toBool()==
false;
213 setVisibilityIfNeeded( set, prop, visible, changed, commandGroup );
215 prop = &set[
"objectType"];
217 visible = isObjectTypeGroup;
218 setVisibilityIfNeeded( set, prop, visible, changed, commandGroup );
220 prop = &set[
"unsigned"];
222 setVisibilityIfNeeded( set, prop, visible, changed, commandGroup );
224 prop = &set[
"length"];
226 if (prop->isVisible()!=visible) {
229 const int lengthToSet = visible ? KexiDB::Field::defaultTextLength() : 0;
230 setPropertyValueIfNeeded( set,
"length", lengthToSet,
231 commandGroup,
false,
false );
236 setVisibilityIfNeeded( set, prop, visible, changed, commandGroup );
237#ifndef KEXI_NO_UNFINISHED
238 prop = &set[
"precision"];
240 setVisibilityIfNeeded( set, prop, visible, changed, commandGroup );
242 prop = &set[
"visibleDecimalPlaces"];
244 setVisibilityIfNeeded( set, prop, visible, changed, commandGroup );
246 prop = &set[
"unique"];
248 setVisibilityIfNeeded( set, prop, visible, changed, commandGroup );
250 prop = &set[
"indexed"];
252 setVisibilityIfNeeded( set, prop, visible, changed, commandGroup );
254 prop = &set[
"allowEmpty"];
256 setVisibilityIfNeeded( set, prop, visible, changed, commandGroup );
258 prop = &set[
"autoIncrement"];
260 setVisibilityIfNeeded( set, prop, visible, changed, commandGroup );
263#ifdef KEXI_NO_UNFINISHED
264 prop = &set[
"defaultValue"];
265 visible = !isObjectTypeGroup;
266 setVisibilityIfNeeded( set, prop, visible, changed, commandGroup );
272TQString KexiTableDesignerViewPrivate::messageForSavingChanges(
bool &emptyTable,
bool skipWarning)
276 emptyTable = conn->
isEmpty( *designerView->tempData()->table, ok ) && ok;
277 return i18n(
"Do you want to save the design now?")
278 + ( (emptyTable || skipWarning) ? TQString() :
279 (TQString(
"\n\n") + designerView->part()->i18nMessage(
":additional message before saving design",
280 designerView->parentDialog())) );
283void KexiTableDesignerViewPrivate::updateIconForItem(KexiTableItem &item, KoProperty::Set& set)
286 if (!set[
"rowSource"].value().toString().isEmpty() && !set[
"rowSourceType"].value().toString().isEmpty())
289 view->KexiDataAwareObjectInterface::data()->clearRowEditBuffer();
290 view->KexiDataAwareObjectInterface::data()->updateRowEditBuffer(&item, COLUMN_ID_ICON, icon);
291 view->KexiDataAwareObjectInterface::data()->saveRowChanges(item,
true);
294#include "kexitabledesignerview_p.moc"
Provides database connection, allowing queries and data modification.
bool isEmpty(TableSchema &table, bool &success)
bool isAutoIncrementAllowed() const
bool hasEmptyProperty() const
bool isFPNumericType() const
bool isNumericType() const
Undo/redo command used for when changing a property for a table field.
Undo/redo command used when property visibility is changed.
Design view of the Table Designer.
KEXI_DB_EXPORT bool supportsVisibleDecimalPlacesProperty(Field::Type type)