heroartifactswidget.h 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /*
  2. * heroartifactswidget.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 "../../lib/mapObjects/CGHeroInstance.h"
  13. namespace Ui {
  14. class HeroArtifactsWidget;
  15. }
  16. class HeroArtifactsWidget : public QDialog
  17. {
  18. Q_OBJECT
  19. public:
  20. explicit HeroArtifactsWidget(CGHeroInstance &, QWidget *parent = nullptr);
  21. ~HeroArtifactsWidget();
  22. void obtainData();
  23. void commitChanges();
  24. private slots:
  25. void onSaveArtifact(int32_t artifactIndex, ArtifactPosition slot);
  26. void on_addButton_clicked();
  27. void on_removeButton_clicked();
  28. private:
  29. enum Column
  30. {
  31. SLOT, ARTIFACT
  32. };
  33. Ui::HeroArtifactsWidget * ui;
  34. CGHeroInstance & hero;
  35. CArtifactFittingSet fittingSet;
  36. void addArtifactToTable(int32_t artifactIndex, ArtifactPosition slot);
  37. };
  38. class HeroArtifactsDelegate : public QStyledItemDelegate
  39. {
  40. Q_OBJECT
  41. public:
  42. using QStyledItemDelegate::QStyledItemDelegate;
  43. HeroArtifactsDelegate(CGHeroInstance &);
  44. QWidget * createEditor(QWidget * parent, const QStyleOptionViewItem & option, const QModelIndex & index) const override;
  45. void setEditorData(QWidget * editor, const QModelIndex & index) const override;
  46. void setModelData(QWidget * editor, QAbstractItemModel * model, const QModelIndex & index) const override;
  47. private:
  48. CGHeroInstance & hero;
  49. };