QCMakeCacheView.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. /*=========================================================================
  2. Program: CMake - Cross-Platform Makefile Generator
  3. Module: $RCSfile$
  4. Language: C++
  5. Date: $Date$
  6. Version: $Revision$
  7. Copyright (c) 2002 Kitware, Inc., Insight Consortium. All rights reserved.
  8. See Copyright.txt or http://www.cmake.org/HTML/Copyright.html for details.
  9. This software is distributed WITHOUT ANY WARRANTY; without even
  10. the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
  11. PURPOSE. See the above copyright notices for more information.
  12. =========================================================================*/
  13. #ifndef QCMakeCacheView_h
  14. #define QCMakeCacheView_h
  15. #include "QCMake.h"
  16. #include <QTreeView>
  17. #include <QSet>
  18. #include <QStandardItemModel>
  19. #include <QItemDelegate>
  20. class QSortFilterProxyModel;
  21. class QCMakeCacheModel;
  22. class QCMakeAdvancedFilter;
  23. /// Qt view class for cache properties
  24. class QCMakeCacheView : public QTreeView
  25. {
  26. Q_OBJECT
  27. public:
  28. QCMakeCacheView(QWidget* p);
  29. // retrieve the QCMakeCacheModel storing all the pointers
  30. // this isn't necessarily the model one would get from model()
  31. QCMakeCacheModel* cacheModel() const;
  32. // get whether to show advanced entries
  33. bool showAdvanced() const;
  34. QSize sizeHint() const { return QSize(200,200); }
  35. public slots:
  36. // set whether to show advanced entries
  37. void setShowAdvanced(bool);
  38. // set the search filter string. any property key or value not matching will
  39. // be filtered out
  40. void setSearchFilter(const QString&);
  41. protected:
  42. QModelIndex moveCursor(CursorAction, Qt::KeyboardModifiers);
  43. bool event(QEvent* e);
  44. QCMakeCacheModel* CacheModel;
  45. QCMakeAdvancedFilter* AdvancedFilter;
  46. QSortFilterProxyModel* SearchFilter;
  47. };
  48. /// Qt model class for cache properties
  49. class QCMakeCacheModel : public QStandardItemModel
  50. {
  51. Q_OBJECT
  52. public:
  53. QCMakeCacheModel(QObject* parent);
  54. ~QCMakeCacheModel();
  55. // roles used to retrieve extra data such has help strings, types of
  56. // properties, and the advanced flag
  57. enum { HelpRole = Qt::ToolTipRole,
  58. TypeRole = Qt::UserRole,
  59. AdvancedRole,
  60. StringsRole};
  61. enum ViewType { FlatView, GroupView };
  62. public slots:
  63. // set a list of properties. This list will be sorted and grouped according
  64. // to prefix. Any property that existed already and which is found in this
  65. // list of properties to set will become an old property. All others will
  66. // become new properties and be marked red.
  67. void setProperties(const QCMakePropertyList& props);
  68. // clear everything from the model
  69. void clear();
  70. // set flag whether the model can currently be edited.
  71. void setEditEnabled(bool);
  72. // insert a new property at a row specifying all the information about the
  73. // property
  74. bool insertProperty(QCMakeProperty::PropertyType t,
  75. const QString& name, const QString& description,
  76. const QVariant& value, bool advanced);
  77. // set the view type
  78. void setViewType(ViewType t);
  79. ViewType viewType() const;
  80. public:
  81. // get the properties
  82. QCMakePropertyList properties() const;
  83. // editing enabled
  84. bool editEnabled() const;
  85. // returns how many new properties there are
  86. int newPropertyCount() const;
  87. // return flags (overloaded to modify flag based on EditEnabled flag)
  88. Qt::ItemFlags flags (const QModelIndex& index) const;
  89. QModelIndex buddy(const QModelIndex& idx) const;
  90. // get the data in the model for this property
  91. void getPropertyData(const QModelIndex& idx1,
  92. QCMakeProperty& prop) const;
  93. protected:
  94. bool EditEnabled;
  95. int NewPropertyCount;
  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