File: fkcombobox.h

package info (click to toggle)
sqlitestudio 3.4.21%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 54,880 kB
  • sloc: ansic: 406,208; cpp: 123,872; yacc: 2,692; tcl: 497; sh: 462; xml: 426; makefile: 19
file content (63 lines) | stat: -rw-r--r-- 2,079 bytes parent folder | download
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 FKCOMBOBOX_H
#define FKCOMBOBOX_H

#include <QComboBox>
#include "datagrid/sqlquerymodelcolumn.h"

class SqlQueryModel;
class SqlQueryView;
class Db;

class FkComboBox : public QComboBox
{
    Q_OBJECT

    public:
        FkComboBox(QWidget *parent, int dropDownViewMinWidth = -1);

        static QString getSqlForFkEditor(Db* db, SqlQueryModelColumn* columnModel, const QVariant& currentValue);
        static qlonglong getRowCountForFkEditor(Db* db, const QString& query, bool* isError);

        static const qlonglong MAX_ROWS_FOR_FK = 10000L;
        static const int FK_CELL_LENGTH_LIMIT = 30;

        void init(Db* db, SqlQueryModelColumn* columnModel);
        void setValue(const QVariant& value);
        QVariant getValue(bool* manualValueUsed = nullptr, bool* ok = nullptr) const;

    private:
        class FkComboShowFilter : public QObject
        {
            public:
                explicit FkComboShowFilter(FkComboBox* parentCombo);
                bool eventFilter(QObject *obj, QEvent *event);
        };

        void init();
        void updateComboViewGeometry(bool initial) const;
        void updateCurrentItemIndex(const QString& value = QString());
        int getFkViewHeaderWidth(bool includeScrollBar) const;
        QString getSql() const;

        static QString resolveImplicitColumn(Db *db, SqlQueryModelColumn* columnModel, SqlQueryModelColumn::ConstraintFk*& fk, QHash<QString, int>& implicitFkColumnIdxByTable, QHash<QString, QStringList>& implicitFkColumnsByTable);

        int dropDownViewMinWidth;
        SqlQueryView* comboView = nullptr;
        SqlQueryModel* comboModel = nullptr;
        SqlQueryModelColumn* columnModel = nullptr;
        QString beforeLoadValue;
        QVariant sourceValue;
        bool disableValueChangeNotifications = false;
        QString oldValue;

    private slots:
        void fkDataAboutToLoad();
        void fkDataReady();
        void fkDataFailed(const QString& errorText);
        void notifyValueModified();

    signals:
        void valueModified();
};

#endif // FKCOMBOBOX_H