PickObjectDelegate.h 1.0 KB

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