Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Kitware
GitHub Repository: Kitware/CMake
Path: blob/master/Source/QtDialog/QCMakeCacheView.h
4998 views
1
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
2
file LICENSE.rst or https://cmake.org/licensing for details. */
3
#pragma once
4
5
#include "QCMake.h"
6
#include "QCMakeSizeType.h"
7
#include <QItemDelegate>
8
#include <QSet>
9
#include <QStandardItemModel>
10
#include <QTreeView>
11
12
class QSortFilterProxyModel;
13
class QCMakeCacheModel;
14
class QCMakeAdvancedFilter;
15
16
/// Qt view class for cache properties
17
class QCMakeCacheView : public QTreeView
18
{
19
Q_OBJECT
20
public:
21
QCMakeCacheView(QWidget* p);
22
23
// retrieve the QCMakeCacheModel storing all the pointers
24
// this isn't necessarily the model one would get from model()
25
QCMakeCacheModel* cacheModel() const;
26
27
// get whether to show advanced entries
28
bool showAdvanced() const;
29
30
QSize sizeHint() const { return QSize(200, 200); }
31
32
// set the search filter string. any property key or value not matching will
33
// be filtered out
34
bool setSearchFilter(QString const&);
35
36
public slots:
37
// set whether to show advanced entries
38
void setShowAdvanced(bool);
39
40
protected:
41
QModelIndex moveCursor(CursorAction, Qt::KeyboardModifiers);
42
bool event(QEvent* e);
43
QCMakeCacheModel* CacheModel;
44
QCMakeAdvancedFilter* AdvancedFilter;
45
QSortFilterProxyModel* SearchFilter;
46
};
47
48
/// Qt model class for cache properties
49
class QCMakeCacheModel : public QStandardItemModel
50
{
51
Q_OBJECT
52
public:
53
QCMakeCacheModel(QObject* parent = nullptr);
54
~QCMakeCacheModel();
55
56
// roles used to retrieve extra data such has help strings, types of
57
// properties, and the advanced flag
58
enum
59
{
60
HelpRole = Qt::ToolTipRole,
61
TypeRole = Qt::UserRole,
62
AdvancedRole,
63
StringsRole,
64
GroupRole
65
};
66
67
enum ViewType
68
{
69
FlatView,
70
GroupView
71
};
72
73
public slots:
74
// set a list of properties. This list will be sorted and grouped according
75
// to prefix. Any property that existed already and which is found in this
76
// list of properties to set will become an old property. All others will
77
// become new properties and be marked red.
78
void setProperties(QCMakePropertyList const& props);
79
80
// set whether to show new properties in red
81
void setShowNewProperties(bool);
82
83
// clear everything from the model
84
void clear();
85
86
// set flag whether the model can currently be edited.
87
void setEditEnabled(bool);
88
89
// insert a new property at a row specifying all the information about the
90
// property
91
bool insertProperty(QCMakeProperty::PropertyType t, QString const& name,
92
QString const& description, QVariant const& value,
93
bool advanced);
94
95
public:
96
// get the properties
97
QCMakePropertyList properties() const;
98
99
// editing enabled
100
bool editEnabled() const;
101
102
// returns how many new properties there are
103
cm_qsizetype newPropertyCount() const;
104
105
// return flags (overloaded to modify flag based on EditEnabled flag)
106
Qt::ItemFlags flags(QModelIndex const& index) const;
107
QModelIndex buddy(QModelIndex const& idx) const;
108
109
// get the data in the model for this property
110
void getPropertyData(QModelIndex const& idx1, QCMakeProperty& prop) const;
111
112
// set the view type
113
void setViewType(ViewType t);
114
ViewType viewType() const;
115
116
protected:
117
bool EditEnabled;
118
cm_qsizetype NewPropertyCount;
119
bool ShowNewProperties;
120
ViewType View;
121
122
// set the data in the model for this property
123
void setPropertyData(QModelIndex const& idx1, QCMakeProperty const& p,
124
bool isNew);
125
126
// breaks up he property list into groups
127
// where each group has the same prefix up to the first underscore
128
static void breakProperties(QSet<QCMakeProperty> const& props,
129
QMap<QString, QCMakePropertyList>& result);
130
131
// gets the prefix of a string up to the first _
132
static QString prefix(QString const& s);
133
};
134
135
/// Qt delegate class for interaction (or other customization)
136
/// with cache properties
137
class QCMakeCacheModelDelegate : public QItemDelegate
138
{
139
Q_OBJECT
140
public:
141
QCMakeCacheModelDelegate(QObject* p);
142
/// create our own editors for cache properties
143
QWidget* createEditor(QWidget* parent, QStyleOptionViewItem const& option,
144
QModelIndex const& index) const;
145
bool editorEvent(QEvent* event, QAbstractItemModel* model,
146
QStyleOptionViewItem const& option,
147
QModelIndex const& index);
148
bool eventFilter(QObject* object, QEvent* event);
149
void setModelData(QWidget* editor, QAbstractItemModel* model,
150
QModelIndex const& index) const;
151
QSize sizeHint(QStyleOptionViewItem const& option,
152
QModelIndex const& index) const;
153
154
QSet<QCMakeProperty> changes() const;
155
void clearChanges();
156
157
protected slots:
158
void setFileDialogFlag(bool);
159
160
protected:
161
bool FileDialogFlag;
162
// record a change to an item in the model.
163
// this simply saves the item in the set of changes
164
void recordChange(QAbstractItemModel* model, QModelIndex const& index);
165
166
// properties changed by user via this delegate
167
QSet<QCMakeProperty> mChanges;
168
};
169
170