forked from sqlitebrowser/sqlitebrowser
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExtendedTableWidget.h
More file actions
101 lines (78 loc) · 3.24 KB
/
ExtendedTableWidget.h
File metadata and controls
101 lines (78 loc) · 3.24 KB
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#ifndef EXTENDEDTABLEWIDGET_H
#define EXTENDEDTABLEWIDGET_H
#include <QTableView>
#include <QStyledItemDelegate>
#include <QSortFilterProxyModel>
#include <unordered_set>
#include "sql/Query.h"
class QMenu;
class QMimeData;
class QDropEvent;
class QDragMoveEvent;
class FilterTableHeader;
namespace sqlb { class ObjectIdentifier; }
// Filter proxy model that only accepts distinct non-empty values.
class UniqueFilterModel : public QSortFilterProxyModel
{
Q_OBJECT
public:
explicit UniqueFilterModel(QObject* parent = nullptr);
bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const override;
private:
std::unordered_set<std::string> m_uniqueValues;
};
// We use this class to provide editor widgets for the ExtendedTableWidget. It's used for every cell in the table view.
class ExtendedTableWidgetEditorDelegate : public QStyledItemDelegate
{
Q_OBJECT
public:
explicit ExtendedTableWidgetEditorDelegate(QObject* parent = nullptr);
QWidget* createEditor(QWidget* parent, const QStyleOptionViewItem& option, const QModelIndex& index) const override;
void setEditorData(QWidget* editor, const QModelIndex& index) const override;
void setModelData(QWidget* editor, QAbstractItemModel* model, const QModelIndex& index) const override;
void updateEditorGeometry(QWidget* editor, const QStyleOptionViewItem& option, const QModelIndex& index) const override;
};
class ExtendedTableWidget : public QTableView
{
Q_OBJECT
public:
explicit ExtendedTableWidget(QWidget* parent = nullptr);
FilterTableHeader* filterHeader() { return m_tableHeader; }
public:
std::unordered_set<int> selectedCols() const;
int numVisibleRows() const;
void sortByColumns(const std::vector<sqlb::SortedColumn>& columns);
public slots:
void reloadSettings();
void selectTableLine(int lineToSelect);
void selectTableLines(int firstLine, int count);
void selectAll() override;
void openPrintDialog();
signals:
void foreignKeyClicked(const sqlb::ObjectIdentifier& table, const QString& column, const QByteArray& value);
void switchTable(bool next); // 'next' parameter is set to true if next table should be selected and to false if previous table should be selected
void openFileFromDropEvent(QString);
void selectedRowsToBeDeleted();
void editCondFormats(int column);
private:
void copyMimeData(const QModelIndexList& fromIndices, QMimeData* mimeData, const bool withHeaders, const bool inSQL);
void copy(const bool withHeaders, const bool inSQL);
void paste();
void useAsFilter(const QString& filterOperator, bool binary = false, const QString& operatorSuffix = "");
void duplicateUpperCell();
static std::vector<std::vector<QByteArray>> m_buffer;
static QString m_generatorStamp;
private slots:
void vscrollbarChanged(int value);
void cellClicked(const QModelIndex& index);
protected:
void keyPressEvent(QKeyEvent* event) override;
void updateGeometries() override;
void dragEnterEvent(QDragEnterEvent* event) override;
void dragMoveEvent(QDragMoveEvent* event) override;
void dropEvent(QDropEvent* event) override;
FilterTableHeader* m_tableHeader;
QMenu* m_contextMenu;
ExtendedTableWidgetEditorDelegate* m_editorDelegate;
};
#endif