Resync
[CMakeLuaTailorHgBridge.git] / CMakeLua / Source / QtDialog / QCMakeCacheView.h
blob82cd676026cb482d230e84385e64afd51a0a401f
1 /*=========================================================================
3 Program: CMake - Cross-Platform Makefile Generator
4 Module: $RCSfile: QCMakeCacheView.h,v $
5 Language: C++
6 Date: $Date: 2009-03-12 15:19:27 $
7 Version: $Revision: 1.22 $
9 Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
10 See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
12 This software is distributed WITHOUT ANY WARRANTY; without even
13 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 PURPOSE. See the above copyright notices for more information.
16 =========================================================================*/
18 #ifndef QCMakeCacheView_h
19 #define QCMakeCacheView_h
21 #include "QCMake.h"
22 #include <QTreeView>
23 #include <QStandardItemModel>
24 #include <QItemDelegate>
26 class QSortFilterProxyModel;
27 class QCMakeCacheModel;
28 class QCMakeAdvancedFilter;
30 /// Qt view class for cache properties
31 class QCMakeCacheView : public QTreeView
33 Q_OBJECT
34 public:
35 QCMakeCacheView(QWidget* p);
37 // retrieve the QCMakeCacheModel storing all the pointers
38 // this isn't necessarily the model one would get from model()
39 QCMakeCacheModel* cacheModel() const;
41 // get whether to show advanced entries
42 bool showAdvanced() const;
44 QSize sizeHint(int) { return QSize(200,200); }
46 public slots:
47 // set whether to show advanced entries
48 void setShowAdvanced(bool);
49 // set the search filter string. any property key or value not matching will
50 // be filtered out
51 void setSearchFilter(const QString&);
53 protected:
54 QModelIndex moveCursor(CursorAction, Qt::KeyboardModifiers);
55 bool event(QEvent* e);
56 QCMakeCacheModel* CacheModel;
57 QCMakeAdvancedFilter* AdvancedFilter;
58 QSortFilterProxyModel* SearchFilter;
61 /// Qt model class for cache properties
62 class QCMakeCacheModel : public QStandardItemModel
64 Q_OBJECT
65 public:
66 QCMakeCacheModel(QObject* parent);
67 ~QCMakeCacheModel();
69 // roles used to retrieve extra data such has help strings, types of
70 // properties, and the advanced flag
71 enum { HelpRole = Qt::ToolTipRole,
72 TypeRole = Qt::UserRole,
73 AdvancedRole,
74 StringsRole};
76 enum ViewType { FlatView, GroupView };
78 public slots:
79 // set a list of properties. This list will be sorted and grouped according
80 // to prefix. Any property that existed already and which is found in this
81 // list of properties to set will become an old property. All others will
82 // become new properties and be marked red.
83 void setProperties(const QCMakePropertyList& props);
85 // clear everything from the model
86 void clear();
88 // set flag whether the model can currently be edited.
89 void setEditEnabled(bool);
91 // insert a new property at a row specifying all the information about the
92 // property
93 bool insertProperty(QCMakeProperty::PropertyType t,
94 const QString& name, const QString& description,
95 const QVariant& value, bool advanced);
97 // set the view type
98 void setViewType(ViewType t);
99 ViewType viewType() const;
101 public:
102 // get the properties
103 QCMakePropertyList properties() const;
105 // editing enabled
106 bool editEnabled() const;
108 // returns how many new properties there are
109 int newPropertyCount() const;
111 // return flags (overloaded to modify flag based on EditEnabled flag)
112 Qt::ItemFlags flags (const QModelIndex& index) const;
113 QModelIndex buddy(const QModelIndex& idx) const;
115 protected:
116 bool EditEnabled;
117 int NewPropertyCount;
118 ViewType View;
120 // set the data in the model for this property
121 void setPropertyData(const QModelIndex& idx1,
122 const QCMakeProperty& p, bool isNew);
123 // get the data in the model for this property
124 void getPropertyData(const QModelIndex& idx1,
125 QCMakeProperty& prop) const;
127 // breaks up he property list into groups
128 // where each group has the same prefix up to the first underscore
129 static void breakProperties(const QSet<QCMakeProperty>& props,
130 QMap<QString, QCMakePropertyList>& result);
132 // gets the prefix of a string up to the first _
133 static QString prefix(const QString& s);
137 /// Qt delegate class for interaction (or other customization)
138 /// with cache properties
139 class QCMakeCacheModelDelegate : public QItemDelegate
141 Q_OBJECT
142 public:
143 QCMakeCacheModelDelegate(QObject* p);
144 /// create our own editors for cache properties
145 QWidget* createEditor(QWidget* parent, const QStyleOptionViewItem& option,
146 const QModelIndex& index ) const;
147 bool editorEvent (QEvent* event, QAbstractItemModel* model,
148 const QStyleOptionViewItem& option, const QModelIndex& index);
149 bool eventFilter(QObject* object, QEvent* event);
150 protected slots:
151 void setFileDialogFlag(bool);
152 protected:
153 bool FileDialogFlag;
156 #endif