QCMakeCacheView.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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 <QAbstractTableModel>
  18. #include <QItemDelegate>
  19. class QSortFilterProxyModel;
  20. class QCMakeCacheModel;
  21. /// Qt view class for cache properties
  22. class QCMakeCacheView : public QTreeView
  23. {
  24. Q_OBJECT
  25. public:
  26. QCMakeCacheView(QWidget* p);
  27. // retrieve the QCMakeCacheModel storing all the pointers
  28. // this isn't necessarily the model one would get from model()
  29. QCMakeCacheModel* cacheModel() const;
  30. // get whether to show advanced entries
  31. bool showAdvanced() const;
  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. void showEvent(QShowEvent* e);
  41. bool Init;
  42. QCMakeCacheModel* CacheModel;
  43. QSortFilterProxyModel* AdvancedFilter;
  44. QSortFilterProxyModel* SearchFilter;
  45. };
  46. /// Qt model class for cache properties
  47. class QCMakeCacheModel : public QAbstractItemModel
  48. {
  49. Q_OBJECT
  50. public:
  51. QCMakeCacheModel(QObject* parent);
  52. ~QCMakeCacheModel();
  53. // roles used to retrieve extra data such has help strings, types of
  54. // properties, and the advanced flag
  55. enum { HelpRole = Qt::UserRole, TypeRole, AdvancedRole };
  56. public slots:
  57. // set a list of properties. This list will be sorted and grouped according
  58. // to prefix. Any property that existed already and which is found in this
  59. // list of properties to set will become an old property. All others will
  60. // become new properties and be marked red.
  61. void setProperties(const QCMakePropertyList& props);
  62. // clear everything from the model
  63. void clear();
  64. // set flag whether the model can currently be edited.
  65. void setEditEnabled(bool);
  66. // remove properties from the model
  67. bool removeRows(int row, int count, const QModelIndex& idx);
  68. // insert a new property at a row specifying all the information about the
  69. // property
  70. bool insertProperty(QCMakeProperty::PropertyType t,
  71. const QString& name, const QString& description,
  72. const QVariant& value, bool advanced);
  73. public:
  74. // satisfy [pure] virtuals
  75. QModelIndex index (int row, int column, const QModelIndex& parent = QModelIndex()) const;
  76. int columnCount (const QModelIndex& parent) const;
  77. QVariant data (const QModelIndex& index, int role = Qt::DisplayRole) const;
  78. QModelIndex parent (const QModelIndex& index) const;
  79. int rowCount (const QModelIndex& parent = QModelIndex()) const;
  80. QVariant headerData (int section, Qt::Orientation orient, int role) const;
  81. Qt::ItemFlags flags (const QModelIndex& index) const;
  82. bool setData (const QModelIndex& index, const QVariant& value, int role);
  83. QModelIndex buddy (const QModelIndex& index) const;
  84. bool hasChildren (const QModelIndex& index) const;
  85. // get the properties
  86. QCMakePropertyList properties() const;
  87. // editing enabled
  88. bool editEnabled() const;
  89. // returns if there are any new properties
  90. bool hasNewProperties() const;
  91. protected:
  92. QList<QPair<QString, QCMakePropertyList> > NewProperties;
  93. QList<QPair<QString, QCMakePropertyList> > Properties;
  94. bool EditEnabled;
  95. // gets the internal data for a model index, if it exists
  96. const QCMakeProperty* propertyForIndex(const QModelIndex& idx) const;
  97. const QPair<QString,QCMakePropertyList>* propertyListForIndex(const QModelIndex& idx) const;
  98. bool isNewProperty(const QModelIndex& idx) const;
  99. // breaks up he property list into groups
  100. // where each group has the same prefix up to the first underscore
  101. static void breakProperties(const QSet<QCMakeProperty>& props,
  102. QMap<QString, QCMakePropertyList>& result);
  103. // gets the prefix of a string up to the first _
  104. static QString prefix(const QString& s);
  105. };
  106. /// Qt delegate class for interaction (or other customization)
  107. /// with cache properties
  108. class QCMakeCacheModelDelegate : public QItemDelegate
  109. {
  110. Q_OBJECT
  111. public:
  112. QCMakeCacheModelDelegate(QObject* p);
  113. /// create our own editors for cache properties
  114. QWidget* createEditor(QWidget* parent, const QStyleOptionViewItem& option,
  115. const QModelIndex& index ) const;
  116. bool editorEvent (QEvent* event, QAbstractItemModel* model,
  117. const QStyleOptionViewItem& option, const QModelIndex& index);
  118. bool eventFilter(QObject* object, QEvent* event);
  119. protected slots:
  120. void setFileDialogFlag(bool);
  121. protected:
  122. bool FileDialogFlag;
  123. };
  124. #endif