OpenMW
|
00001 #ifndef CSV_WORLD_UTIL_H 00002 #define CSV_WORLD_UTIL_H 00003 00004 #include <map> 00005 00006 #include <QAbstractTableModel> 00007 #include <QStyledItemDelegate> 00008 00009 #include "../../model/world/columnbase.hpp" 00010 00011 class QUndoStack; 00012 00013 namespace CSVWorld 00014 { 00018 class NastyTableModelHack : public QAbstractTableModel 00019 { 00020 QAbstractItemModel& mModel; 00021 QVariant mData; 00022 00023 public: 00024 00025 NastyTableModelHack (QAbstractItemModel& model); 00026 00027 int rowCount (const QModelIndex & parent = QModelIndex()) const; 00028 00029 int columnCount (const QModelIndex & parent = QModelIndex()) const; 00030 00031 QVariant data (const QModelIndex & index, int role = Qt::DisplayRole) const; 00032 00033 bool setData (const QModelIndex &index, const QVariant &value, int role = Qt::EditRole); 00034 00035 QVariant getData() const; 00036 }; 00037 00038 class CommandDelegate; 00039 00040 class CommandDelegateFactory 00041 { 00042 public: 00043 00044 virtual ~CommandDelegateFactory(); 00045 00046 virtual CommandDelegate *makeDelegate (QUndoStack& undoStack, QObject *parent) const = 0; 00048 }; 00049 00050 class CommandDelegateFactoryCollection 00051 { 00052 static CommandDelegateFactoryCollection *sThis; 00053 std::map<CSMWorld::ColumnBase::Display, CommandDelegateFactory *> mFactories; 00054 00055 private: 00056 00057 // not implemented 00058 CommandDelegateFactoryCollection (const CommandDelegateFactoryCollection&); 00059 CommandDelegateFactoryCollection& operator= (const CommandDelegateFactoryCollection&); 00060 00061 public: 00062 00063 CommandDelegateFactoryCollection(); 00064 00065 ~CommandDelegateFactoryCollection(); 00066 00067 void add (CSMWorld::ColumnBase::Display display, CommandDelegateFactory *factory); 00071 00072 CommandDelegate *makeDelegate (CSMWorld::ColumnBase::Display display, QUndoStack& undoStack, 00073 QObject *parent) const; 00077 00078 static const CommandDelegateFactoryCollection& get(); 00079 00080 }; 00081 00083 class CommandDelegate : public QStyledItemDelegate 00084 { 00085 Q_OBJECT 00086 00087 QUndoStack& mUndoStack; 00088 bool mEditLock; 00089 00090 protected: 00091 00092 QUndoStack& getUndoStack() const; 00093 00094 virtual void setModelDataImp (QWidget *editor, QAbstractItemModel *model, 00095 const QModelIndex& index) const; 00096 00097 public: 00098 00099 CommandDelegate (QUndoStack& undoStack, QObject *parent); 00100 00101 virtual void setModelData (QWidget *editor, QAbstractItemModel *model, 00102 const QModelIndex& index) const; 00103 00104 virtual QWidget *createEditor (QWidget *parent, const QStyleOptionViewItem& option, 00105 const QModelIndex& index) const; 00106 00107 void setEditLock (bool locked); 00108 00109 bool isEditLocked() const; 00110 00111 virtual bool updateEditorSetting (const QString &settingName, const QString &settingValue); 00113 00114 private slots: 00115 00116 virtual void slotUpdateEditorSetting (const QString &settingName, const QString &settingValue) {} 00117 }; 00118 } 00119 00120 #endif