|
1 | 1 | #pragma once |
2 | 2 |
|
3 | 3 | #include <QtCore/QAbstractItemModel> |
| 4 | +#include <QtCore/QHash> |
4 | 5 | #include <QtCore/QItemSelection> |
5 | 6 | #include <QtCore/QModelIndex> |
| 7 | +#include <QtCore/QPointer> |
6 | 8 | #include <QtCore/QRegularExpression> |
7 | 9 | #include <QtCore/QSize> |
8 | 10 | #include <QtCore/QSortFilterProxyModel> |
| 11 | +#include <QtCore/QStringList> |
9 | 12 | #include <QtCore/QTimer> |
10 | 13 | #include <QtCore/QVariant> |
11 | 14 | #include <QtGui/QMouseEvent> |
|
19 | 22 | #include <QtWidgets/QStyledItemDelegate> |
20 | 23 | #include <QtWidgets/QTableWidget> |
21 | 24 | #include <QtWidgets/QTreeView> |
| 25 | +#include <QtWidgets/QVBoxLayout> |
22 | 26 |
|
23 | 27 | #include <map> |
24 | 28 | #include <optional> |
|
30 | 34 | #include "render.h" |
31 | 35 | #include "menus.h" |
32 | 36 | #include "clickablelabel.h" |
| 37 | +#include "theme.h" |
33 | 38 |
|
34 | 39 | /*! |
35 | 40 |
|
@@ -145,6 +150,50 @@ class BINARYNINJAUIAPI SettingsOutlineProxyModel : public QSortFilterProxyModel |
145 | 150 | }; |
146 | 151 |
|
147 | 152 |
|
| 153 | +/*! |
| 154 | + \ingroup settingsview |
| 155 | +
|
| 156 | + Editor widget for array-of-string settings. Renders one editable row per item |
| 157 | + plus a top row for adding new entries. Used by SettingsEditor in place of the |
| 158 | + raw JSON QLineEdit for settings whose value is a list of strings. |
| 159 | +*/ |
| 160 | +class BINARYNINJAUIAPI ArrayStringSettingEditor : public QWidget |
| 161 | +{ |
| 162 | + Q_OBJECT |
| 163 | + |
| 164 | + private: |
| 165 | + QStringList m_enumValues; |
| 166 | + bool m_readOnly = false; |
| 167 | + QVBoxLayout* m_rowLayout = nullptr; |
| 168 | + QWidget* m_addRowWidget = nullptr; |
| 169 | + QLineEdit* m_addLineEdit = nullptr; |
| 170 | + QComboBox* m_addComboBox = nullptr; |
| 171 | + CustomStyleFlatToolButton* m_addButton = nullptr; |
| 172 | + std::vector<QWidget*> m_rows; |
| 173 | + |
| 174 | + QLineEdit* addRowInputField() const; |
| 175 | + void clearRows(); |
| 176 | + QString currentAddText() const; |
| 177 | + void appendRow(const QString& text); |
| 178 | + |
| 179 | + private Q_SLOTS: |
| 180 | + void onAddClicked(); |
| 181 | + void onRowEditingFinished(); |
| 182 | + void onRowRemoveClicked(); |
| 183 | + |
| 184 | + public: |
| 185 | + ArrayStringSettingEditor(QWidget* parent, const QStringList& enumValues, bool readOnly); |
| 186 | + |
| 187 | + void setValues(const QStringList& values); |
| 188 | + QStringList values() const; |
| 189 | + void clearAddText(); |
| 190 | + |
| 191 | + Q_SIGNALS: |
| 192 | + void changed(); |
| 193 | + void geometryChanged(); |
| 194 | +}; |
| 195 | + |
| 196 | + |
148 | 197 | /*! |
149 | 198 | \ingroup settingsview |
150 | 199 | */ |
@@ -176,6 +225,7 @@ class BINARYNINJAUIAPI SettingsEditor : public QWidget |
176 | 225 | QSpinBox* m_spinBox = nullptr; |
177 | 226 | QComboBox* m_comboBox = nullptr; |
178 | 227 | QTableWidget* m_objectTable = nullptr; |
| 228 | + ArrayStringSettingEditor* m_stringListEditor = nullptr; |
179 | 229 | std::set<QString> m_validComboSelections; |
180 | 230 | std::vector<std::pair<std::string, Json::ValueType>> m_objectTableColumns; |
181 | 231 | Json::StreamWriterBuilder m_builder; |
@@ -219,6 +269,8 @@ class BINARYNINJAUIAPI SettingsEditor : public QWidget |
219 | 269 | void updateDoubleNumberSetting(double value); |
220 | 270 | void updateIntNumberSetting(int value); |
221 | 271 | void updateObjectSetting(); |
| 272 | + void updateStringListSetting(); |
| 273 | + void onStringListGeometryChanged(); |
222 | 274 | void addArraySetting(const QString& text); |
223 | 275 | void resetSetting(); |
224 | 276 | void resetAllSettings(BNSettingsScope scope); |
@@ -268,6 +320,7 @@ class BINARYNINJAUIAPI SettingsDelegate : public QStyledItemDelegate |
268 | 320 | QPersistentModelIndex m_scrollAnchorIdx; |
269 | 321 | int m_scrollAnchorOffset = 0; |
270 | 322 | bool m_resizing = false; |
| 323 | + mutable QHash<QPersistentModelIndex, QPointer<SettingsEditor>> m_settingEditors; |
271 | 324 |
|
272 | 325 | QTreeView* m_treeView; |
273 | 326 | std::function<void(const QModelIndex& index)> m_hoverAction = nullptr; |
|
0 commit comments