aboutsummaryrefslogtreecommitdiffstats
path: root/SQLiteStudio3/guiSQLiteStudio/constraints/tablepkanduniquepanel.h
blob: 10921157c9a7b1af4a7adefa265c2c5198dcc5e4 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#ifndef PRIMARYKEYANDUNIQUEPANEL_H
#define PRIMARYKEYANDUNIQUEPANEL_H

#include "parser/ast/sqlitecreatetable.h"
#include "constraintpanel.h"
#include "guiSQLiteStudio_global.h"
#include <QStringListModel>

namespace Ui {
    class TablePrimaryKeyAndUniquePanel;
}

class QGridLayout;
class QSignalMapper;

class GUI_API_EXPORT TablePrimaryKeyAndUniquePanel : public ConstraintPanel
{
        Q_OBJECT

    public:
        explicit TablePrimaryKeyAndUniquePanel(QWidget *parent = 0);
        ~TablePrimaryKeyAndUniquePanel();

        bool validate();
        void storeConfiguration();

    protected:
        void changeEvent(QEvent *e);
        void constraintAvailable();
        virtual void readConstraint();

        Ui::TablePrimaryKeyAndUniquePanel *ui = nullptr;
        QGridLayout* columnsLayout = nullptr;

        /**
         * @brief totalColumns
         * Used to count columns created by buildColumns().
         * It's a workaround for QGridLayout::rowCount(), which doesn't return
         * number of visible rows, but instead a number of allocated rows,
         * which isn't useful in any way.
         * This variable lets us to avoid asking for widgets from rows
         * that does not exist.
         */
        int totalColumns = 0;

    private:
        void init();
        void readCollations();
        void buildColumns();
        void buildColumn(SqliteCreateTable::Column* column, int row);
        int getColumnIndex(const QString& colName);

        QStringListModel collations;
        QSignalMapper* columnSignalMapping = nullptr;

    private slots:
        void updateColumnState(int colIdx);

    protected slots:
        virtual void updateState();
};

#endif // PRIMARYKEYANDUNIQUEPANEL_H