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