QCMakeCacheView.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  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 <QTableView>
  17. #include <QAbstractTableModel>
  18. #include <QCheckBox>
  19. #include <QLineEdit>
  20. #include <QItemDelegate>
  21. #include <QSortFilterProxyModel>
  22. #include <QCompleter>
  23. class QCMakeCacheModel;
  24. class QToolButton;
  25. /// Qt view class for cache properties
  26. class QCMakeCacheView : public QTableView
  27. {
  28. Q_OBJECT
  29. public:
  30. QCMakeCacheView(QWidget* p);
  31. QCMakeCacheModel* cacheModel() const;
  32. bool showAdvanced() const;
  33. public slots:
  34. void setShowAdvanced(bool);
  35. void setSearchFilter(const QString&);
  36. protected:
  37. QModelIndex moveCursor(CursorAction, Qt::KeyboardModifiers);
  38. void showEvent(QShowEvent* e);
  39. bool Init;
  40. QCMakeCacheModel* CacheModel;
  41. QSortFilterProxyModel* AdvancedFilter;
  42. QSortFilterProxyModel* SearchFilter;
  43. };
  44. /// Qt model class for cache properties
  45. class QCMakeCacheModel : public QAbstractTableModel
  46. {
  47. Q_OBJECT
  48. public:
  49. QCMakeCacheModel(QObject* parent);
  50. ~QCMakeCacheModel();
  51. enum { HelpRole = Qt::UserRole, TypeRole, AdvancedRole };
  52. public slots:
  53. void setProperties(const QCMakeCachePropertyList& props);
  54. void clear();
  55. void setEditEnabled(bool);
  56. bool removeRows(int row, int count, const QModelIndex& idx = QModelIndex());
  57. bool insertRows(int row, int num, const QModelIndex&);
  58. public:
  59. // satisfy [pure] virtuals
  60. int columnCount (const QModelIndex& parent) const;
  61. QVariant data (const QModelIndex& index, int role = Qt::DisplayRole) const;
  62. QModelIndex parent (const QModelIndex& index) const;
  63. int rowCount (const QModelIndex& parent = QModelIndex()) const;
  64. QVariant headerData (int section, Qt::Orientation orient, int role) const;
  65. Qt::ItemFlags flags (const QModelIndex& index) const;
  66. bool setData (const QModelIndex& index, const QVariant& value, int role);
  67. QModelIndex buddy (const QModelIndex& index) const;
  68. // get the properties
  69. QCMakeCachePropertyList properties() const;
  70. // editing enabled
  71. bool editEnabled() const;
  72. int newCount() const;
  73. protected:
  74. QCMakeCachePropertyList Properties;
  75. int NewCount;
  76. bool EditEnabled;
  77. };
  78. /// Qt delegate class for interaction (or other customization)
  79. /// with cache properties
  80. class QCMakeCacheModelDelegate : public QItemDelegate
  81. {
  82. Q_OBJECT
  83. public:
  84. QCMakeCacheModelDelegate(QObject* p);
  85. /// create our own editors for cache properties
  86. QWidget* createEditor(QWidget* parent, const QStyleOptionViewItem& option,
  87. const QModelIndex& index ) const;
  88. bool editorEvent (QEvent* event, QAbstractItemModel* model,
  89. const QStyleOptionViewItem& option, const QModelIndex& index);
  90. bool eventFilter(QObject* object, QEvent* event);
  91. protected slots:
  92. void setFileDialogFlag(bool);
  93. protected:
  94. bool FileDialogFlag;
  95. };
  96. /// Editor widget for editing paths or file paths
  97. class QCMakeCacheFileEditor : public QLineEdit
  98. {
  99. Q_OBJECT
  100. public:
  101. QCMakeCacheFileEditor(QWidget* p, const QString& var);
  102. protected slots:
  103. virtual void chooseFile() = 0;
  104. signals:
  105. void fileDialogExists(bool);
  106. protected:
  107. void resizeEvent(QResizeEvent* e);
  108. QToolButton* ToolButton;
  109. QString Variable;
  110. };
  111. class QCMakeCachePathEditor : public QCMakeCacheFileEditor
  112. {
  113. Q_OBJECT
  114. public:
  115. QCMakeCachePathEditor(QWidget* p = NULL, const QString& var = QString());
  116. void chooseFile();
  117. };
  118. class QCMakeCacheFilePathEditor : public QCMakeCacheFileEditor
  119. {
  120. Q_OBJECT
  121. public:
  122. QCMakeCacheFilePathEditor(QWidget* p = NULL, const QString& var = QString());
  123. void chooseFile();
  124. };
  125. /// completer class that returns native cmake paths
  126. class QCMakeFileCompleter : public QCompleter
  127. {
  128. public:
  129. QCMakeFileCompleter(QObject* o, bool dirs);
  130. virtual QString pathFromIndex(const QModelIndex& idx) const;
  131. };
  132. #endif