1 /* This file is part of the KDE project 2 Copyright (C) 2004-2012 Jarosław Staniek <staniek@kde.org> 3 4 This program is free software; you can redistribute it and/or 5 modify it under the terms of the GNU Library General Public 6 License as published by the Free Software Foundation; either 7 version 2 of the License, or (at your option) any later version. 8 9 This program is distributed in the hope that it will be useful, 10 but WITHOUT ANY WARRANTY; without even the implied warranty of 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 Library General Public License for more details. 13 14 You should have received a copy of the GNU Library General Public License 15 along with this program; see the file COPYING. If not, write to 16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 17 * Boston, MA 02110-1301, USA. 18 */ 19 20 #ifndef KEXIALTERTABLEDIALOG_P_H 21 #define KEXIALTERTABLEDIALOG_P_H 22 23 #include "kexitabledesignerview.h" 24 #include <kundo2command.h> 25 #include <QByteArray> 26 27 class KexiDataAwarePropertySet; 28 29 namespace KexiTableDesignerCommands 30 { 31 class Command; 32 } 33 34 //! @internal indices for table columns 35 #define COLUMN_ID_ICON 0 36 #define COLUMN_ID_CAPTION 1 37 #define COLUMN_ID_TYPE 2 38 #define COLUMN_ID_DESC 3 39 40 //! @internal 41 class KexiTableDesignerViewPrivate 42 { 43 public: 44 explicit KexiTableDesignerViewPrivate(KexiTableDesignerView* aDesignerView); 45 ~KexiTableDesignerViewPrivate(); 46 47 int generateUniqueId(); 48 49 /*! @internal 50 Sets property \a propertyName in property set \a set to \a newValue. 51 If \a commandGroup is not 0, a new ChangeFieldPropertyCommand object is added there as well. 52 While setting the new value, addHistoryCommand_in_slotPropertyChanged_enabled is set to false, 53 so addHistoryCommand() wont be executed in slotPropertyChanged() as an answer to setting 54 the property. 55 56 If \a forceAddCommand is false (the default) and \a newValue does not differ from curent property value 57 (set[propertyName].value()), ChangeFieldPropertyCommand command is not added to the \a commandGroup. 58 Otherwise, command is always added. 59 60 \a rememberOldValue argument is passed to Property::setValue() 61 62 If \a slist and \a nlist if not NULL and not empty, these are passed to Property::setListData(). 63 If \a slist and \a nlist if not NULL but empty, Property::setListData(0) is called. 64 65 addHistoryCommand_in_slotPropertyChanged_enabled is then set back to the original state. 66 */ 67 void setPropertyValueIfNeeded(const KPropertySet& set, const QByteArray& propertyName, 68 const QVariant& newValue, KexiTableDesignerCommands::Command* commandGroup, 69 bool forceAddCommand = false, bool rememberOldValue = true, 70 KPropertyListData *listData = nullptr); 71 72 /*! Like above but allows to specify \a oldValue. */ 73 void setPropertyValueIfNeeded( 74 const KPropertySet& set, const QByteArray& propertyName, 75 const QVariant& newValue, const QVariant& oldValue, KexiTableDesignerCommands::Command* commandGroup, 76 bool forceAddCommand = false, bool rememberOldValue = true, 77 KPropertyListData *listData = nullptr); 78 79 /*! @internal 80 Used in updatePropertiesVisibility(). 81 Does nothing if visibility should not be changed, i.e. when prop->isVisible()==visible, 82 otherwise sets changed to true and sets visibility of property \a prop to \a visible. 83 */ 84 void setVisibilityIfNeeded(const KPropertySet& set, KProperty* prop, 85 bool visible, bool *changed, KexiTableDesignerCommands::Command *commandGroup); 86 87 bool updatePropertiesVisibility(KDbField::Type fieldType, KPropertySet &set, 88 KexiTableDesignerCommands::Command *commandGroup = 0); 89 90 /*! \return message used to ask user for accepting saving the design. 91 \a emptyTable is set to true if the table designed contains no rows. 92 If \a skipWarning is true, no warning about data loss is appended (useful when 93 only non-physical altering actions will be performed). */ 94 KLocalizedString messageForSavingChanges(bool *emptyTable, bool skipWarning = false); 95 96 /*! Updates icon in the first column, depending on property set \a set. 97 For example, when "rowSource" and "rowSourceType" propertiesa are not empty, 98 "combobox" icon appears. */ 99 void updateIconForRecord(KDbRecordData *data, KPropertySet *set); 100 101 KexiTableDesignerView* designerView; 102 103 KexiTableScrollArea *view; //!< helper 104 105 KDbTableViewData *data; 106 107 KexiDataAwarePropertySet *sets; 108 109 int row; //!< used to know if a new row is selected in slotCellSelected() 110 111 KToggleAction *action_toggle_pkey; 112 113 QAction *contextMenuTitle; 114 115 int uniqueIdCounter; 116 117 //! internal 118 int maxTypeNameTextWidth; 119 //! Set to true in beforeSwitchTo() to avoid asking again in storeData() 120 bool dontAskOnStoreData; 121 122 bool slotTogglePrimaryKeyCalled; 123 124 bool primaryKeyExists; 125 //! Used in slotPropertyChanged() to avoid infinite recursion 126 bool slotPropertyChanged_primaryKey_enabled; 127 //! Used in slotPropertyChanged() to avoid infinite recursion 128 bool slotPropertyChanged_subType_enabled; 129 //! used in slotPropertyChanged() to disable addHistoryCommand() 130 bool addHistoryCommand_in_slotPropertyChanged_enabled; 131 //! used in slotRecordUpdated() to disable addHistoryCommand() 132 bool addHistoryCommand_in_slotRecordUpdated_enabled; 133 //! used in slotAboutToDeleteRecord() to disable addHistoryCommand() 134 bool addHistoryCommand_in_slotAboutToDeleteRecord_enabled; 135 //! used in slotRecordInserted() to disable addHistoryCommand() 136 bool addHistoryCommand_in_slotRecordInserted_enabled; 137 138 //! used to disable slotBeforeCellChanged() 139 bool slotBeforeCellChanged_enabled; 140 141 //! @todo temp; remove this: 142 //! Temporary flag, used for testing the Alter Table machinery. Affects storeData() 143 //! Used in slotExecuteRealAlterTable() to switch on real alter table for a while. 144 bool tempStoreDataUsingRealAlterTable; 145 146 /*! Set to a recent result of calling \ref tristate KexiTableDesignerView::storeData(bool dontAsk). 147 Then, it is used in \ref void KexiTableDesignerView::executeRealAlterTable() 148 to know what return value should be. */ 149 tristate recentResultOfStoreData; 150 151 KActionCollection* historyActionCollection; 152 KUndo2Stack* history; 153 154 //! A set used in KexiTableDesignerView::buildField() to quickly identify 155 //! properties internal to the designer 156 QSet<QByteArray> internalPropertyNames; 157 }; 158 159 #endif 160