QCMakeWidgets.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. file Copyright.txt or https://cmake.org/licensing for details. */
  3. #ifndef QCMakeWidgets_h
  4. #define QCMakeWidgets_h
  5. #include "cmConfigure.h" // IWYU pragma: keep
  6. #include <QComboBox>
  7. #include <QCompleter>
  8. #include <QLineEdit>
  9. class QToolButton;
  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, const 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. #endif