OpenMW
apps/opencs/view/world/enumdelegate.hpp
Go to the documentation of this file.
00001 #ifndef CSV_WORLD_ENUMDELEGATE_H
00002 #define CSV_WORLD_ENUMDELEGATE_H
00003 
00004 #include <vector>
00005 
00006 #include <QString>
00007 
00008 #include <components/esm/defs.hpp>
00009 
00010 #include "util.hpp"
00011 
00012 namespace CSVWorld
00013 {
00015     class EnumDelegate : public CommandDelegate
00016     {
00017         protected:
00018 
00019             std::vector<std::pair<int, QString> > mValues;
00020 
00021         private:
00022 
00023             virtual void setModelDataImp (QWidget *editor, QAbstractItemModel *model,
00024                 const QModelIndex& index) const;
00025 
00026             virtual void addCommands (QAbstractItemModel *model,
00027                 const QModelIndex& index, int type) const;
00028 
00029         public:
00030 
00031             EnumDelegate (const std::vector<std::pair<int, QString> >& values,
00032                 QUndoStack& undoStack, QObject *parent);
00033 
00034             virtual QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem& option,
00035                 const QModelIndex& index) const;
00036 
00037             virtual void setEditorData (QWidget *editor, const QModelIndex& index) const;
00038 
00039             virtual void paint (QPainter *painter, const QStyleOptionViewItem& option,
00040                 const QModelIndex& index) const;
00041 
00042     };
00043 
00044     class EnumDelegateFactory : public CommandDelegateFactory
00045     {
00046         protected:
00047             std::vector<std::pair<int, QString> > mValues;
00048 
00049         public:
00050 
00051             EnumDelegateFactory();
00052 
00053             EnumDelegateFactory (const char **names, bool allowNone = false);
00056 
00057             EnumDelegateFactory (const std::vector<std::string>& names, bool allowNone = false);
00059 
00060             virtual CommandDelegate *makeDelegate (QUndoStack& undoStack, QObject *parent) const;
00062 
00063             void add (int value, const QString& name);
00064     };
00065 
00066 
00067 }
00068 
00069 #endif