validator.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /*
  2. * validator.h, part of VCMI engine
  3. *
  4. * Authors: listed in file AUTHORS in main folder
  5. *
  6. * License: GNU General Public License v2.0 or later
  7. * Full text of license available in license.txt file, in main folder
  8. *
  9. */
  10. #pragma once
  11. #include <QDialog>
  12. #include <set>
  13. VCMI_LIB_NAMESPACE_BEGIN
  14. class CMap;
  15. VCMI_LIB_NAMESPACE_END
  16. namespace Ui {
  17. class Validator;
  18. }
  19. class Validator : public QDialog
  20. {
  21. Q_OBJECT
  22. public:
  23. struct Issue
  24. {
  25. QString message;
  26. bool critical;
  27. Issue(const QString & m, bool c): message(m), critical(c) {}
  28. bool operator <(const Issue & other) const
  29. {
  30. return message < other.message;
  31. }
  32. };
  33. public:
  34. explicit Validator(const CMap * map, QWidget *parent = nullptr);
  35. ~Validator();
  36. static std::set<Issue> validate(const CMap * map);
  37. private:
  38. Ui::Validator *ui;
  39. QRect screenGeometry;
  40. void showValidationResults(const CMap * map);
  41. void adjustWindowSize();
  42. };
  43. class ValidatorItemDelegate : public QStyledItemDelegate
  44. {
  45. public:
  46. explicit ValidatorItemDelegate(QObject * parent = nullptr) : QStyledItemDelegate(parent)
  47. {
  48. screenGeometry = QApplication::primaryScreen()->availableGeometry();
  49. }
  50. int itemPaddingBottom = 14;
  51. int iconPadding = 4;
  52. int textOffsetForIcon = 30;
  53. int textPaddingRight = 10;
  54. int minItemWidth = 350;
  55. int screenMargin = 350; // some reserved space from screenWidth; used if text.width > screenWidth - screenMargin
  56. const int offsetForIcon = iconPadding + textOffsetForIcon;
  57. void paint(QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index) const override;
  58. QSize sizeHint(const QStyleOptionViewItem & option, const QModelIndex & index) const override;
  59. private:
  60. QRect screenGeometry;
  61. };