-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfigdialog.h
More file actions
142 lines (110 loc) · 4.15 KB
/
configdialog.h
File metadata and controls
142 lines (110 loc) · 4.15 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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#ifndef CONFIGDIALOG_H
#define CONFIGDIALOG_H
//#include "qscrollarea.h"
#include <QDialog>
#include <QScrollArea>
#include <QFormLayout>
#include <QLineEdit>
#include <QPushButton>
#include <QFileDialog>
#include <QComboBox>
#include <QLabel>
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QWidget>
#include <QJsonObject>
#include <QJsonArray>
#include <QJsonDocument>
//#include <map>
#include <vector>
class VariableWidget : public QWidget {
Q_OBJECT
public:
VariableWidget(QWidget *parent = nullptr) : QWidget(parent) {
QHBoxLayout *layout = new QHBoxLayout(this);
QComboBox *comboBox = new QComboBox();
comboBox->addItems(QStringList() << "定值" << "列" << "行"); // << "滑动条");
QLineEdit *nameEdit = new QLineEdit();
QLineEdit *rangeEdit = new QLineEdit();
QPushButton *deleteButton = new QPushButton("删除");
// 设置占位符文本
nameEdit->setPlaceholderText("变量名");
nameEdit->setObjectName("nameEdit");
nameEdit->setMaximumWidth(80);
rangeEdit->setPlaceholderText("值/范围");
rangeEdit->setObjectName("rangeEdit");
layout->addWidget(nameEdit);
layout->addWidget(comboBox);
layout->addWidget(rangeEdit);
layout->addWidget(deleteButton);
connect(deleteButton, &QPushButton::clicked, this, &VariableWidget::onDeleteClicked);
}
signals:
void deleteClicked(VariableWidget *widget);
private slots:
void onDeleteClicked() {
emit deleteClicked(this);
}
};
struct VariableConfig {
int type; // 变量类型
QStringList range; // 变量范围
};
class ConfigDialog : public QDialog {
Q_OBJECT
public:
explicit ConfigDialog(QWidget *parent = nullptr,
const QJsonObject &configData = [](){
QJsonObject defaultState;
defaultState["ConfigNotSaved"] = true;
return defaultState;}()
);
virtual ~ConfigDialog();
// 保存配置
QJsonObject saveState() const;
// 恢复配置
void restoreState(const QJsonObject &state);
// 保存配置到文件
static bool saveConfigToFile(const QString &filePath, const QJsonObject &state);
// 从文件加载配置,参数是文件路径和存到的地方
static bool loadConfigFromFile(const QString &filePath, QJsonObject &state);
std::map<QString, VariableConfig> getVariableConfigs() const;
QString getImageName() const { return pictureName->text(); }
QString getImagePath() const { return folderPathEdit->text(); }
QString getXAxisLabel() const { return xAxisLabel->text(); }
QString getYAxisLabel() const { return yAxisLabel->text(); }
QString getSecXAxisLabel() const { return secXAxisLabel->text(); }
QString getSecYAxisLabel() const { return secYAxisLabel->text(); }
// 获得一个QString代表的格式,first是字符串,second表示这个字符串是否是变量,是变量的话会在之后的环节替换为值
// 变量以 `' 括起来
static std::vector<std::pair<QString, int>> getStrVarConfig(const QString&);
private slots:
void selectImagePath() {
QString directory = QFileDialog::getExistingDirectory(this, tr("选择图片文件夹"), QDir::homePath());
if (!directory.isEmpty()) {
folderPathEdit->setText(directory);
}
}
void onAddVariableClicked() {
VariableWidget *variable = new VariableWidget();
connect(variable, &VariableWidget::deleteClicked, this, &ConfigDialog::onDeleteVariableClicked);
variablesLayout->addWidget(variable);
variableWidgets.append(variable);
}
void onDeleteVariableClicked(VariableWidget *widget) {
variableWidgets.removeAll(widget);
variablesLayout->removeWidget(widget);
widget->deleteLater();
}
private:
QLineEdit *gridSizeEdit;
QLineEdit *folderPathEdit;
QLineEdit *pictureName;
QLineEdit *xAxisLabel;
QLineEdit *yAxisLabel;
QLineEdit *secXAxisLabel;
QLineEdit *secYAxisLabel;
QVBoxLayout *variablesLayout;
QList<VariableWidget *> variableWidgets;
};
#endif // CONFIGDIALOG_H