-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwindow.h
More file actions
79 lines (70 loc) · 2.42 KB
/
window.h
File metadata and controls
79 lines (70 loc) · 2.42 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
#ifndef WINDOW_H
#define WINDOW_H
#include <QWidget>
#include <QProcess>
#include <QStandardItem>
#include <QStandardItemModel>
#include <QStyledItemDelegate>
#include <QComboBox>
#include <QLineEdit>
#include "filterproxymodel.h"
QT_BEGIN_NAMESPACE
namespace Ui { class Window; }
QT_END_NAMESPACE
class ComboBoxDelegate : public QStyledItemDelegate
{
Q_OBJECT
public:
virtual QWidget* createEditor(QWidget* parent, const QStyleOptionViewItem&, const QModelIndex& index) const {
auto selections = index.data(Qt::UserRole).value<QStringList>();
auto current = index.data(Qt::DisplayRole).value<QString>();
QComboBox* comboBox = new QComboBox{parent};
comboBox->addItems(selections);
comboBox->setCurrentText(current);
return comboBox;
}
virtual void deleteEditor(QWidget* editor, const QModelIndex&) {
editor->deleteLater();
}
virtual void setEditorData(QWidget* editor, const QModelIndex& index) const {
QComboBox* comboBox = qobject_cast<QComboBox*>(editor);
comboBox->clear();
comboBox->addItems(index.data(Qt::UserRole).value<QStringList>());
comboBox->setCurrentText(index.data(Qt::DisplayRole).value<QString>());
}
virtual void setModelData(QWidget* editor, QAbstractItemModel* model, const QModelIndex& index) const {
QComboBox* comboBox = qobject_cast<QComboBox*>(editor);
model->setData(index, comboBox->currentText(), Qt::DisplayRole);
}
virtual void updateEditorGeometry(QWidget* editor, const QStyleOptionViewItem& option, const QModelIndex&) const {
editor->setGeometry(option.rect);
}
virtual QString displayText(const QVariant& value, const QLocale&) const {
return value.toString();
}
};
class Window : public QWidget
{
Q_OBJECT
public:
Window(QWidget *parent = nullptr);
~Window();
void loadModel();
void save();
void resizeEvent(QResizeEvent* event);
void moveEvent(QMoveEvent* event);
private slots:
void adjustPopupFilter();
void onDataChanged(const QModelIndex& topLeft, const QModelIndex& bottomRight, const QVector<int>& roles);
void nextSave();
protected:
bool eventFilter(QObject* obj, QEvent* event);
private:
QList<QPair<QString, QString>> m_changes;
QProcess m_process{this};
QStandardItemModel m_model;
FilterProxyModel m_filterModel;
QLineEdit m_lineEdit_filter;
Ui::Window *ui;
};
#endif // WINDOW_H