GenericSelectItemDialog.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #ifndef CRYINCLUDE_EDITOR_GENERICSELECTITEMDIALOG_H
  9. #define CRYINCLUDE_EDITOR_GENERICSELECTITEMDIALOG_H
  10. #pragma once
  11. #if !defined(Q_MOC_RUN)
  12. #include <QDialog>
  13. #include <QScopedPointer>
  14. #include "Util/Variable.h"
  15. #endif
  16. // CGenericSelectItem dialog
  17. namespace Ui {
  18. class CGenericSelectItemDialog;
  19. }
  20. class CGenericSelectItemDialog
  21. : public QDialog
  22. {
  23. Q_OBJECT
  24. public:
  25. typedef enum
  26. {
  27. eMODE_LIST, eMODE_TREE
  28. } TDialogMode;
  29. typedef IVariable::IGetCustomItems::SItem SItem;
  30. CGenericSelectItemDialog(QWidget* pParent = nullptr); // standard constructor
  31. virtual ~CGenericSelectItemDialog();
  32. void ShowDescription(bool bShow)
  33. {
  34. m_bShowDesc = bShow;
  35. }
  36. virtual QString GetSelectedItem();
  37. virtual void PreSelectItem(const QString& name)
  38. {
  39. m_preselect = name;
  40. }
  41. void SetMode(TDialogMode inMode)
  42. {
  43. m_mode = inMode;
  44. }
  45. void AllowNew(bool bAllow)
  46. {
  47. m_bAllowNew = bAllow;
  48. }
  49. void SetTreeSeparator(const QString& sep)
  50. {
  51. m_treeSeparator = sep;
  52. }
  53. // Override items which are otherwise fetched by GetItems
  54. void SetItems(const QStringList& items)
  55. {
  56. m_bSet = true;
  57. m_items.resize(0);
  58. m_items.reserve(items.size());
  59. QStringList::const_iterator iter = items.begin();
  60. QStringList::const_iterator iterEnd = items.end();
  61. SItem item;
  62. while (iter != iterEnd)
  63. {
  64. item.name = item.desc = *iter;
  65. m_items.push_back(item);
  66. ++iter;
  67. }
  68. }
  69. // Override items which are otherwise fetched by GetItems
  70. void SetItems(const std::vector<QString>& items)
  71. {
  72. m_bSet = true;
  73. m_items.resize(0);
  74. m_items.reserve(items.size());
  75. std::vector<QString>::const_iterator iter = items.begin();
  76. std::vector<QString>::const_iterator iterEnd = items.end();
  77. SItem item;
  78. while (iter != iterEnd)
  79. {
  80. item.name = item.desc = *iter;
  81. m_items.push_back(item);
  82. ++iter;
  83. }
  84. }
  85. // Override items which are otherwise fetched by GetItems
  86. void SetItems(const std::vector<SItem>& items)
  87. {
  88. m_bSet = true;
  89. m_items = items;
  90. }
  91. void showEvent(QShowEvent* event) override;
  92. enum
  93. {
  94. New = QDialog::Accepted + 1
  95. };
  96. protected:
  97. // Derived Dialogs should override this
  98. virtual void GetItems(std::vector<SItem>& outItems);
  99. // Called whenever an item gets selected
  100. virtual void ItemSelected();
  101. void OnTvnSelchangedTree();
  102. void OnTvnDoubleClick();
  103. void OnLbnSelchangeList();
  104. void OnLbnDoubleClick();
  105. void OnBnClickedNew();
  106. virtual void OnInitDialog();
  107. void ReloadItems();
  108. void ReloadTree();
  109. struct less_qstring_icmp
  110. {
  111. bool operator()(const QString& left, const QString& right) const
  112. {
  113. return QString::compare(left, right, Qt::CaseInsensitive) < 0;
  114. }
  115. };
  116. QString m_preselect;
  117. QString m_selectedItem;
  118. QString m_selectedDesc;
  119. QString m_treeSeparator;
  120. std::vector<SItem> m_items;
  121. TDialogMode m_mode;
  122. bool m_bSet;
  123. bool m_bAllowNew;
  124. bool m_bShowDesc;
  125. QScopedPointer<Ui::CGenericSelectItemDialog> ui;
  126. private:
  127. bool m_initialized;
  128. };
  129. #endif // CRYINCLUDE_EDITOR_GENERICSELECTITEMDIALOG_H