1 #ifndef COLUMNDIALOG_H 2 #define COLUMNDIALOG_H 3 4 #include "parser/ast/sqlitecreatetable.h" 5 #include "common/extactioncontainer.h" 6 #include "constraintdialog.h" 7 #include "guiSQLiteStudio_global.h" 8 #include <QDialog> 9 #include <QPointer> 10 11 class ColumnDialogConstraintsModel; 12 class QCheckBox; 13 class QToolButton; 14 15 namespace Ui { 16 class ColumnDialog; 17 } 18 19 class GUI_API_EXPORT ColumnDialog : public QDialog, public ExtActionContainer 20 { 21 Q_OBJECT 22 23 public: 24 enum Action 25 { 26 ADD_CONSTRAINT, 27 EDIT_CONSTRAINT, 28 DEL_CONSTRAINT, 29 MOVE_CONSTRAINT_UP, 30 MOVE_CONSTRAINT_DOWN, 31 ADD_PK, 32 ADD_FK, 33 ADD_UNIQUE, 34 ADD_CHECK, 35 ADD_DEFAULT, 36 ADD_NOT_NULL, 37 ADD_GENERATED, 38 ADD_COLLATE 39 }; 40 41 enum ToolBar 42 { 43 }; 44 45 explicit ColumnDialog(Db* db, QWidget *parent = 0); 46 ~ColumnDialog(); 47 48 void init(); 49 void setColumn(SqliteCreateTable::Column* value); 50 SqliteCreateTable::Column* getModifiedColumn(); 51 QToolBar* getToolBar(int toolbar) const; 52 void disableConstraint(ConstraintDialog::Constraint constraint); 53 54 protected: 55 void changeEvent(QEvent *e); 56 void createActions(); 57 void setupDefShortcuts(); 58 59 private: 60 void addConstraint(ConstraintDialog::Constraint mode); 61 void setupConstraintCheckBoxes(); 62 void editConstraint(SqliteCreateTable::Column::Constraint* constraint); 63 void delConstraint(const QModelIndex& idx); 64 void configureConstraint(SqliteCreateTable::Column::Constraint::Type type); 65 void addEmptyConstraint(SqliteCreateTable::Column::Constraint::Type type); 66 void delAllConstraint(SqliteCreateTable::Column::Constraint::Type type); 67 void constraintToggled(SqliteCreateTable::Column::Constraint::Type type, bool enabled); 68 void updateConstraintState(SqliteCreateTable::Column::Constraint* constraint); 69 QCheckBox* getCheckBoxForConstraint(SqliteCreateTable::Column::Constraint* constraint); 70 QToolButton* getToolButtonForConstraint(SqliteCreateTable::Column::Constraint* constraint); 71 void updateTypeValidations(); 72 void updateTypeForAutoIncr(); 73 bool hasAutoIncr() const; 74 75 Ui::ColumnDialog *ui = nullptr; 76 SqliteCreateTable::ColumnPtr column; 77 ColumnDialogConstraintsModel* constraintsModel = nullptr; 78 QCheckBox* modeCheckBox = nullptr; 79 Db* db = nullptr; 80 bool integerTypeEnforced = false; 81 QSet<ConstraintDialog::Constraint> disabledConstraints; 82 83 private slots: 84 void updateConstraintsToolbarState(); 85 void updateState(); 86 void addConstraint(); 87 void editConstraint(); 88 void editConstraint(const QModelIndex& idx); 89 void delConstraint(); 90 void moveConstraintUp(); 91 void moveConstraintDown(); 92 void addPk(); 93 void addFk(); 94 void addUnique(); 95 void addCheck(); 96 void addCollate(); 97 void addNotNull(); 98 void addGenerated(); 99 void addDefault(); 100 void configurePk(); 101 void configureFk(); 102 void configureUnique(); 103 void configureCheck(); 104 void configureCollate(); 105 void configureGenerated(); 106 void configureNotNull(); 107 void configureDefault(); 108 void pkToggled(bool enabled); 109 void fkToggled(bool enabled); 110 void uniqueToggled(bool enabled); 111 void checkToggled(bool enabled); 112 void collateToggled(bool enabled); 113 void generatedToggled(bool enabled); 114 void notNullToggled(bool enabled); 115 void defaultToggled(bool enabled); 116 void switchMode(bool advanced); 117 void updateValidations(); 118 void updateConstraint(SqliteCreateTable::Column::Constraint* constraint); 119 void updateDataType(); 120 }; 121 122 #endif // COLUMNDIALOG_H 123