QCMakeWidgets.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. file Copyright.txt or https://cmake.org/licensing for details. */
  3. #pragma once
  4. #include "cmConfigure.h" // IWYU pragma: keep
  5. #include <QComboBox>
  6. #include <QCompleter>
  7. #include <QLineEdit>
  8. class QToolButton;
  9. class QSortFilterProxyModel;
  10. // common widgets for Qt based CMake
  11. /// Editor widget for editing paths or file paths
  12. class QCMakeFileEditor : public QLineEdit
  13. {
  14. Q_OBJECT
  15. public:
  16. QCMakeFileEditor(QWidget* p, QString var);
  17. protected slots:
  18. virtual void chooseFile() = 0;
  19. signals:
  20. void fileDialogExists(bool);
  21. protected:
  22. void resizeEvent(QResizeEvent* e);
  23. QToolButton* ToolButton;
  24. QString Variable;
  25. };
  26. /// editor widget for editing files
  27. class QCMakePathEditor : public QCMakeFileEditor
  28. {
  29. Q_OBJECT
  30. public:
  31. QCMakePathEditor(QWidget* p = nullptr, const QString& var = QString());
  32. void chooseFile();
  33. };
  34. /// editor widget for editing paths
  35. class QCMakeFilePathEditor : public QCMakeFileEditor
  36. {
  37. Q_OBJECT
  38. public:
  39. QCMakeFilePathEditor(QWidget* p = nullptr, const QString& var = QString());
  40. void chooseFile();
  41. };
  42. /// completer class that returns native cmake paths
  43. class QCMakeFileCompleter : public QCompleter
  44. {
  45. Q_OBJECT
  46. public:
  47. QCMakeFileCompleter(QObject* o, bool dirs);
  48. virtual QString pathFromIndex(const QModelIndex& idx) const;
  49. };
  50. // editor for strings
  51. class QCMakeComboBox : public QComboBox
  52. {
  53. Q_OBJECT
  54. Q_PROPERTY(QString value READ currentText WRITE setValue USER true);
  55. public:
  56. QCMakeComboBox(QWidget* p, QStringList strings)
  57. : QComboBox(p)
  58. {
  59. this->addItems(strings);
  60. }
  61. void setValue(const QString& v)
  62. {
  63. int i = this->findText(v);
  64. if (i != -1) {
  65. this->setCurrentIndex(i);
  66. }
  67. }
  68. };
  69. namespace QtCMake {
  70. bool setSearchFilter(QSortFilterProxyModel* model,
  71. const QString& searchString);
  72. void setSearchFilterColor(QLineEdit* edit, bool valid);
  73. }