PickObjectDelegate.h 1008 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /*
  2. * PickObjectDelegate.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 <QItemDelegate>
  12. class MapController;
  13. VCMI_LIB_NAMESPACE_BEGIN
  14. class CGObjectInstance;
  15. VCMI_LIB_NAMESPACE_END
  16. class PickObjectDelegate : public QItemDelegate
  17. {
  18. Q_OBJECT
  19. public:
  20. PickObjectDelegate(MapController &);
  21. PickObjectDelegate(MapController &, std::function<bool(const CGObjectInstance *)>);
  22. template<class T>
  23. static bool typedFilter(const CGObjectInstance * o)
  24. {
  25. return dynamic_cast<const T*>(o) != nullptr;
  26. }
  27. QWidget * createEditor(QWidget * parent, const QStyleOptionViewItem & option, const QModelIndex & index) const override;
  28. public slots:
  29. void onObjectPicked(const CGObjectInstance *);
  30. private:
  31. MapController & controller;
  32. std::function<bool(const CGObjectInstance *)> filter;
  33. mutable QModelIndex modelIndex;
  34. };