1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-01-30 12:32:36 +00:00
OpenMW/apps/opencs/view/world/enumdelegate.hpp

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

81 lines
2.6 KiB
C++
Raw Normal View History

#ifndef CSV_WORLD_ENUMDELEGATE_H
#define CSV_WORLD_ENUMDELEGATE_H
2022-10-19 19:02:00 +02:00
#include <string>
#include <utility>
#include <vector>
#include <QString>
2022-10-19 19:02:00 +02:00
#include <apps/opencs/model/world/columnbase.hpp>
#include "util.hpp"
2022-10-19 19:02:00 +02:00
namespace CSMDoc
{
class Document;
}
namespace CSMWorld
{
class CommandDispatcher;
}
namespace CSVWorld
{
/// \brief Integer value that represents an enum and is interacted with via a combobox
class EnumDelegate : public CommandDelegate
{
2013-07-10 21:13:59 -05:00
protected:
std::vector<std::pair<int, QString>> mValues;
2013-07-10 21:13:59 -05:00
int getValueIndex(const QModelIndex& index, int role = Qt::DisplayRole) const;
private:
void setModelDataImp(QWidget* editor, QAbstractItemModel* model, const QModelIndex& index) const override;
virtual void addCommands(QAbstractItemModel* model, const QModelIndex& index, int type) const;
2022-09-22 21:26:05 +03:00
public:
EnumDelegate(const std::vector<std::pair<int, QString>>& values, CSMWorld::CommandDispatcher* dispatcher,
CSMDoc::Document& document, QObject* parent);
QWidget* createEditor(
QWidget* parent, const QStyleOptionViewItem& option, const QModelIndex& index) const override;
QWidget* createEditor(QWidget* parent, const QStyleOptionViewItem& option, const QModelIndex& index,
CSMWorld::ColumnBase::Display display = CSMWorld::ColumnBase::Display_None) const override;
void setEditorData(QWidget* editor, const QModelIndex& index, bool tryDisplay = false) const override;
void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const override;
2015-06-16 14:18:47 +03:00
QSize sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const override;
};
class EnumDelegateFactory : public CommandDelegateFactory
{
2013-07-10 21:13:59 -05:00
protected:
std::vector<std::pair<int, QString>> mValues;
2022-09-22 21:26:05 +03:00
public:
EnumDelegateFactory();
2013-04-02 14:15:22 +02:00
EnumDelegateFactory(const char** names, bool allowNone = false);
///< \param names Array of char pointer with a 0-pointer as end mark
2013-04-02 14:15:22 +02:00
/// \param allowNone Use value of -1 for "none selected" (empty string)
EnumDelegateFactory(const std::vector<std::pair<int, std::string>>& names, bool allowNone = false);
/// \param allowNone Use value of -1 for "none selected" (empty string)
CommandDelegate* makeDelegate(
CSMWorld::CommandDispatcher* dispatcher, CSMDoc::Document& document, QObject* parent) const override;
///< The ownership of the returned CommandDelegate is transferred to the caller.
void add(int value, const QString& name);
};
}
2013-07-10 21:13:59 -05:00
#endif