QCMakeCacheView.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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 <QStandardItemModel>
  18. #include <QItemDelegate>
  19. class QSortFilterProxyModel;
  20. class QCMakeCacheModel;
  21. class QCMakeAdvancedFilter;
  22. /// Qt view class for cache properties
  23. class QCMakeCacheView : public QTreeView
  24. {
  25. Q_OBJECT
  26. public:
  27. QCMakeCacheView(QWidget* p);
  28. // retrieve the QCMakeCacheModel storing all the pointers
  29. // this isn't necessarily the model one would get from model()
  30. QCMakeCacheModel* cacheModel() const;
  31. // get whether to show advanced entries
  32. bool showAdvanced() const;
  33. QSize sizeHint(int) { return QSize(200,200); }
  34. public slots:
  35. // set whether to show advanced entries
  36. void setShowAdvanced(bool);
  37. // set the search filter string. any property key or value not matching will
  38. // be filtered out
  39. void setSearchFilter(const QString&);
  40. protected:
  41. QModelIndex moveCursor(CursorAction, Qt::KeyboardModifiers);
  42. bool event(QEvent* e);
  43. QCMakeCacheModel* CacheModel;
  44. QCMakeAdvancedFilter* AdvancedFilter;
  45. QSortFilterProxyModel* SearchFilter;
  46. };
  47. /// Qt model class for cache properties
  48. class QCMakeCacheModel : public QStandardItemModel
  49. {
  50. Q_OBJECT
  51. public:
  52. QCMakeCacheModel(QObject* parent);
  53. ~QCMakeCacheModel();
  54. // roles used to retrieve extra data such has help strings, types of
  55. // properties, and the advanced flag
  56. enum { HelpRole = Qt::ToolTipRole,
  57. TypeRole = Qt::UserRole,
  58. AdvancedRole,
  59. StringsRole};
  60. enum ViewType { FlatView, GroupView };
  61. public slots:
  62. // set a list of properties. This list will be sorted and grouped according
  63. // to prefix. Any property that existed already and which is found in this
  64. // list of properties to set will become an old property. All others will
  65. // become new properties and be marked red.
  66. void setProperties(const QCMakePropertyList& props);
  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. protected:
  90. bool EditEnabled;
  91. int NewPropertyCount;
  92. ViewType View;
  93. // set the data in the model for this property
  94. void setPropertyData(const QModelIndex& idx1,
  95. const QCMakeProperty& p, bool isNew);
  96. // get the data in the model for this property
  97. void getPropertyData(const QModelIndex& idx1,
  98. QCMakeProperty& prop) 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