QCMakeCacheView.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. /*============================================================================
  2. CMake - Cross Platform Makefile Generator
  3. Copyright 2000-2009 Kitware, Inc., Insight Software Consortium
  4. Distributed under the OSI-approved BSD License (the "License");
  5. see accompanying file Copyright.txt for details.
  6. This software is distributed WITHOUT ANY WARRANTY; without even the
  7. implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  8. See the License for more information.
  9. ============================================================================*/
  10. #ifndef QCMakeCacheView_h
  11. #define QCMakeCacheView_h
  12. #include "QCMake.h"
  13. #include <QTreeView>
  14. #include <QSet>
  15. #include <QStandardItemModel>
  16. #include <QItemDelegate>
  17. class QSortFilterProxyModel;
  18. class QCMakeCacheModel;
  19. class QCMakeAdvancedFilter;
  20. /// Qt view class for cache properties
  21. class QCMakeCacheView : public QTreeView
  22. {
  23. Q_OBJECT
  24. public:
  25. QCMakeCacheView(QWidget* p);
  26. // retrieve the QCMakeCacheModel storing all the pointers
  27. // this isn't necessarily the model one would get from model()
  28. QCMakeCacheModel* cacheModel() const;
  29. // get whether to show advanced entries
  30. bool showAdvanced() const;
  31. QSize sizeHint() const { return QSize(200,200); }
  32. public slots:
  33. // set whether to show advanced entries
  34. void setShowAdvanced(bool);
  35. // set the search filter string. any property key or value not matching will
  36. // be filtered out
  37. void setSearchFilter(const QString&);
  38. protected:
  39. QModelIndex moveCursor(CursorAction, Qt::KeyboardModifiers);
  40. bool event(QEvent* e);
  41. QCMakeCacheModel* CacheModel;
  42. QCMakeAdvancedFilter* AdvancedFilter;
  43. QSortFilterProxyModel* SearchFilter;
  44. };
  45. /// Qt model class for cache properties
  46. class QCMakeCacheModel : public QStandardItemModel
  47. {
  48. Q_OBJECT
  49. public:
  50. QCMakeCacheModel(QObject* parent);
  51. ~QCMakeCacheModel();
  52. // roles used to retrieve extra data such has help strings, types of
  53. // properties, and the advanced flag
  54. enum { HelpRole = Qt::ToolTipRole,
  55. TypeRole = Qt::UserRole,
  56. AdvancedRole,
  57. StringsRole};
  58. enum ViewType { FlatView, GroupView };
  59. public slots:
  60. // set a list of properties. This list will be sorted and grouped according
  61. // to prefix. Any property that existed already and which is found in this
  62. // list of properties to set will become an old property. All others will
  63. // become new properties and be marked red.
  64. void setProperties(const QCMakePropertyList& props);
  65. // set whether to show new properties in red
  66. void setShowNewProperties(bool);
  67. // clear everything from the model
  68. void clear();
  69. // set flag whether the model can currently be edited.
  70. void setEditEnabled(bool);
  71. // insert a new property at a row specifying all the information about the
  72. // property
  73. bool insertProperty(QCMakeProperty::PropertyType t,
  74. const QString& name, const QString& description,
  75. const QVariant& value, bool advanced);
  76. // set the view type
  77. void setViewType(ViewType t);
  78. ViewType viewType() const;
  79. public:
  80. // get the properties
  81. QCMakePropertyList properties() const;
  82. // editing enabled
  83. bool editEnabled() const;
  84. // returns how many new properties there are
  85. int newPropertyCount() const;
  86. // return flags (overloaded to modify flag based on EditEnabled flag)
  87. Qt::ItemFlags flags (const QModelIndex& index) const;
  88. QModelIndex buddy(const QModelIndex& idx) const;
  89. // get the data in the model for this property
  90. void getPropertyData(const QModelIndex& idx1,
  91. QCMakeProperty& prop) const;
  92. protected:
  93. bool EditEnabled;
  94. int NewPropertyCount;
  95. bool ShowNewProperties;
  96. ViewType View;
  97. // set the data in the model for this property
  98. void setPropertyData(const QModelIndex& idx1,
  99. const QCMakeProperty& p, bool isNew);
  100. // breaks up he property list into groups
  101. // where each group has the same prefix up to the first underscore
  102. static void breakProperties(const QSet<QCMakeProperty>& props,
  103. QMap<QString, QCMakePropertyList>& result);
  104. // gets the prefix of a string up to the first _
  105. static QString prefix(const QString& s);
  106. };
  107. /// Qt delegate class for interaction (or other customization)
  108. /// with cache properties
  109. class QCMakeCacheModelDelegate : public QItemDelegate
  110. {
  111. Q_OBJECT
  112. public:
  113. QCMakeCacheModelDelegate(QObject* p);
  114. /// create our own editors for cache properties
  115. QWidget* createEditor(QWidget* parent, const QStyleOptionViewItem& option,
  116. const QModelIndex& index ) const;
  117. bool editorEvent (QEvent* event, QAbstractItemModel* model,
  118. const QStyleOptionViewItem& option, const QModelIndex& index);
  119. bool eventFilter(QObject* object, QEvent* event);
  120. void setModelData(QWidget * editor, QAbstractItemModel * model, const QModelIndex & index ) const;
  121. QSize sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const;
  122. QSet<QCMakeProperty> changes() const;
  123. void clearChanges();
  124. protected slots:
  125. void setFileDialogFlag(bool);
  126. protected:
  127. bool FileDialogFlag;
  128. // record a change to an item in the model.
  129. // this simply saves the item in the set of changes
  130. void recordChange(QAbstractItemModel* model, const QModelIndex& index);
  131. // properties changed by user via this delegate
  132. QSet<QCMakeProperty> mChanges;
  133. };
  134. #endif