diff options
| author | Ben Boeckel <MathStuf@gmail.com> | 2008-04-25 21:09:05 +0000 |
|---|---|---|
| committer | Ben Boeckel <MathStuf@gmail.com> | 2008-04-25 21:09:05 +0000 |
| commit | e13073c4357b2b85eba8a015f38e9f69f4d1799c (patch) | |
| tree | c301321da7066a8722469947f024b60a382ca77b | |
| parent | 74c06767a1a698705e8c486d77ccf11838c87a4d (diff) | |
[FIX] Drag/Drop should work (in theory)
git-svn-id: https://pokegen.svn.sourceforge.net/svnroot/pokegen/trunk@109 6ecfd1a5-f3ed-3746-8530-beee90d26b22
40 files changed, 213 insertions, 279 deletions
@@ -1,4 +1,11 @@ ----------------- +Rev: 109 +Date: 25 April 2008 +User: MathStuf +----------------- +[FIX] Drag/Drop should work (in theory) + +----------------- Rev: 108 Date: 25 April 2008 User: MathStuf diff --git a/pokemodr/PokemodTreeModel.cpp b/pokemodr/PokemodTreeModel.cpp index c2abd9a3..a06f9af9 100644 --- a/pokemodr/PokemodTreeModel.cpp +++ b/pokemodr/PokemodTreeModel.cpp @@ -15,6 +15,9 @@ * with this program. If not, see <http://www.gnu.org/licenses/>. */ +// Qt includes +#include <QMimeData> + // Header include #include "PokemodTreeModel.h" @@ -130,4 +133,30 @@ BaseModel* PokemodTreeModel::getItem(const QModelIndex& index) const return m_root; } +QStringList PokemodTreeModel::mimeTypes() const +{ + return QStringList() << "application/x-pokemod+xml"; +} +QMimeData* PokemodTreeModel::mimeData(const QModelIndexList& indexes) const +{ + QMimeData *mimeData = new QMimeData(); + if ((indexes.size() == 1) && indexes[0].isValid()) + { + QDomDocument xml; + xml.setContent(data(indexes[0], BaseModel::XmlRole).toString()); + mimeData->setData("application/x-pokemod+xml", xml.toByteArray()); + } + return mimeData; +} + +bool PokemodTreeModel::dropMimeData(const QMimeData* data, Qt::DropAction action, int row, int column, const QModelIndex& parent) +{ + if (action == Qt::IgnoreAction) + return true; + if (!data->hasFormat("application/x-pokemod+xml")) + return false; + if (parent.isValid()) + return setData(parent, data->data("application/x-pokemod+xml"), BaseModel::XmlRole); + return m_root->setData(data->data("application/x-pokemod+xml"), BaseModel::XmlRole); +} diff --git a/pokemodr/PokemodTreeModel.h b/pokemodr/PokemodTreeModel.h index 43c84b33..56c3ab23 100644 --- a/pokemodr/PokemodTreeModel.h +++ b/pokemodr/PokemodTreeModel.h @@ -52,6 +52,12 @@ class PokemodTreeModel : public QAbstractItemModel bool insertRows(int /*position*/, int rows, const QModelIndex& parent = QModelIndex()); bool removeRows(int position, int rows, const QModelIndex& parent = QModelIndex()); + + Qt::DropActions supportedDragActions(); + Qt::DropActions supportedDropActions(); + QStringList mimeTypes() const; + QMimeData* mimeData(const QModelIndexList& indexes) const; + bool dropMimeData(const QMimeData* data, Qt::DropAction action, int row, int column, const QModelIndex& parent); private: BaseModel* getItem(const QModelIndex& index) const; diff --git a/pokemodr/TODO b/pokemodr/TODO index b2a88392..21fcf866 100644 --- a/pokemodr/TODO +++ b/pokemodr/TODO @@ -7,6 +7,8 @@ MoveEffect Update GUI to see new methods +Set sub class stuff by passing it on to subclasses via setData + Drag and drop stuff Flag widget diff --git a/pokemodr/models/AbilityEffectModel.cpp b/pokemodr/models/AbilityEffectModel.cpp index ce6602b6..b6221562 100644 --- a/pokemodr/models/AbilityEffectModel.cpp +++ b/pokemodr/models/AbilityEffectModel.cpp @@ -38,7 +38,13 @@ QVariant AbilityEffectModel::data(int role) const { if (role == Qt::DisplayRole) return AbilityEffect::EffectStr[static_cast<AbilityEffect*>(m_object)->effect()]; - else if (role == Qt::UserRole) + else if (role == BaseModel::XmlRole) + { + QDomDocument xml(m_object->className()); + xml.appendChild(m_object->save()); + return xml.toString(); + } + else if (role == BaseModel::WidgetRole) { // TODO: AbilityEffectUI // QWidget* widget = new AbilityEffectUI(static_cast<AbilityEffect*>(m_object), NULL); @@ -49,7 +55,7 @@ QVariant AbilityEffectModel::data(int role) const bool AbilityEffectModel::setData(const QVariant& value, int role) { - if (role == Qt::UserRole) + if (role == BaseModel::XmlRole) { if (value.canConvert<QString>()) { @@ -73,8 +79,3 @@ int AbilityEffectModel::indexNumber() const { // TODO: get effect index } - -// bool AbilityEffectModel::dropMimeData(const QMimeData* data, Qt::DropAction action, int row, int column) -// { -// // TODO: drag/drop -// } diff --git a/pokemodr/models/AbilityEffectModel.h b/pokemodr/models/AbilityEffectModel.h index 76b338d3..867c742b 100644 --- a/pokemodr/models/AbilityEffectModel.h +++ b/pokemodr/models/AbilityEffectModel.h @@ -32,8 +32,6 @@ class AbilityEffectModel : public ObjectModel bool setData(const QVariant& value, int role = Qt::EditRole); int indexNumber() const; - -// bool dropMimeData(const QMimeData* data, Qt::DropAction action, int row, int column); }; #endif diff --git a/pokemodr/models/AbilityModel.cpp b/pokemodr/models/AbilityModel.cpp index c19bcab0..13b3707b 100644 --- a/pokemodr/models/AbilityModel.cpp +++ b/pokemodr/models/AbilityModel.cpp @@ -48,7 +48,13 @@ QVariant AbilityModel::data(int role) const { if (role == Qt::DisplayRole) return static_cast<Ability*>(m_object)->name(); - else if (role == Qt::UserRole) + else if (role == BaseModel::XmlRole) + { + QDomDocument xml(m_object->className()); + xml.appendChild(m_object->save()); + return xml.toString(); + } + else if (role == BaseModel::WidgetRole) { QWidget* widget = new AbilityUI(static_cast<Ability*>(m_object), NULL); return QVariant::fromValue(widget); @@ -63,7 +69,7 @@ int AbilityModel::rowCount() const bool AbilityModel::setData(const QVariant& value, int role) { - if (role == Qt::UserRole) + if (role == BaseModel::XmlRole) { if (value.canConvert<QString>()) { @@ -113,11 +119,6 @@ bool AbilityModel::removeRows(const int position, const int rows) return true; } -// bool AbilityModel::dropMimeData(const QMimeData* data, Qt::DropAction action, int row, int column) -// { -// // TODO: drag/drop -// } - void AbilityModel::setupData() { Ability* ability = static_cast<Ability*>(m_object); diff --git a/pokemodr/models/AbilityModel.h b/pokemodr/models/AbilityModel.h index 0a012845..7219b806 100644 --- a/pokemodr/models/AbilityModel.h +++ b/pokemodr/models/AbilityModel.h @@ -41,8 +41,6 @@ class AbilityModel : public GroupObjectModel bool insertRows(const int rows); bool removeRows(const int position, const int rows); - -// bool dropMimeData(const QMimeData* data, Qt::DropAction action, int row, int column); private: void setupData(); void clearData(); diff --git a/pokemodr/models/BadgeModel.cpp b/pokemodr/models/BadgeModel.cpp index e1f55da2..5776526b 100644 --- a/pokemodr/models/BadgeModel.cpp +++ b/pokemodr/models/BadgeModel.cpp @@ -42,7 +42,13 @@ QVariant BadgeModel::data(int role) const { if (role == Qt::DisplayRole) return static_cast<Badge*>(m_object)->name(); - else if (role == Qt::UserRole) + else if (role == BaseModel::XmlRole) + { + QDomDocument xml(m_object->className()); + xml.appendChild(m_object->save()); + return xml.toString(); + } + else if (role == BaseModel::WidgetRole) { QWidget* widget = new BadgeUI(static_cast<Badge*>(m_object), NULL); return QVariant::fromValue(widget); @@ -52,7 +58,7 @@ QVariant BadgeModel::data(int role) const bool BadgeModel::setData(const QVariant& value, int role) { - if (role == Qt::UserRole) + if (role == BaseModel::XmlRole) { if (value.canConvert<QString>()) { @@ -76,8 +82,3 @@ int BadgeModel::indexNumber() const { return m_object->pokemod()->badgeIndex(m_object->id()); } - -// bool BadgeModel::dropMimeData(const QMimeData* data, Qt::DropAction action, int row, int column) -// { -// // TODO: drag/drop -// } diff --git a/pokemodr/models/BadgeModel.h b/pokemodr/models/BadgeModel.h index 20777d39..92981d14 100644 --- a/pokemodr/models/BadgeModel.h +++ b/pokemodr/models/BadgeModel.h @@ -32,8 +32,6 @@ class BadgeModel : public ObjectModel bool setData(const QVariant& value, int role = Qt::EditRole); int indexNumber() const; - -// bool dropMimeData(const QMimeData* data, Qt::DropAction action, int row, int column); }; #endif diff --git a/pokemodr/models/BaseModel.cpp b/pokemodr/models/BaseModel.cpp index b1241803..79cf68ce 100644 --- a/pokemodr/models/BaseModel.cpp +++ b/pokemodr/models/BaseModel.cpp @@ -50,6 +50,16 @@ Qt::ItemFlags BaseObjectModel::flags() const return Qt::ItemIsDragEnabled | Qt::ItemIsSelectable | Qt::ItemIsDropEnabled | Qt::ItemIsEnabled; } +Qt::DropActions BaseObjectModel::supportedDragActions() +{ + return Qt::CopyAction | Qt::MoveAction; +} + +Qt::DropActions BaseObjectModel::supportedDropActions() +{ + return Qt::CopyAction | Qt::MoveAction; +} + ObjectModel::ObjectModel(BaseModel* parent, Object* object) : BaseObjectModel(parent, object) { @@ -142,6 +152,16 @@ bool GroupModel::canRemoveRows() const return true; } +Qt::DropActions GroupModel::supportedDragActions() +{ + return 0; +} + +Qt::DropActions GroupModel::supportedDropActions() +{ + return Qt::CopyAction | Qt::MoveAction; +} + void GroupModel::clearData() { foreach (BaseObjectModel* model, m_objects) diff --git a/pokemodr/models/BaseModel.h b/pokemodr/models/BaseModel.h index e422266a..b0eec613 100644 --- a/pokemodr/models/BaseModel.h +++ b/pokemodr/models/BaseModel.h @@ -51,16 +51,13 @@ class BaseModel virtual bool canRemoveRows() const = 0; virtual bool removeRows(const int position, const int rows) = 0; -// virtual bool dropMimeData(const QMimeData* data, Qt::DropAction action, int row, int column) = 0; -// -// Qt::DropActions supportedDragActions() -// { -// return Qt::CopyAction | Qt::MoveAction; -// } -// Qt::DropActions supportedDropActions() -// { -// return Qt::CopyAction | Qt::MoveAction; -// } + virtual Qt::DropActions supportedDragActions() = 0; + virtual Qt::DropActions supportedDropActions() = 0; + + virtual QString type() const = 0; + + static const int XmlRole = Qt::UserRole; + static const int WidgetRole = Qt::UserRole + 1; protected: Object* m_object; QString m_name; @@ -91,7 +88,13 @@ class BaseObjectModel : public BaseModel virtual bool canRemoveRows() const = 0; virtual bool removeRows(const int position, const int rows) = 0; -// virtual bool dropMimeData(const QMimeData* data, Qt::DropAction action, int row, int column) = 0; + Qt::DropActions supportedDragActions(); + Qt::DropActions supportedDropActions(); + + QString type() const + { + return m_object->className(); + } }; class ObjectModel : public BaseObjectModel @@ -115,8 +118,6 @@ class ObjectModel : public BaseObjectModel bool canRemoveRows() const; bool removeRows(const int /*position*/, const int /*rows*/); - -// virtual bool dropMimeData(const QMimeData* data, Qt::DropAction action, int row, int column) = 0; }; class GroupObjectModel : public BaseObjectModel @@ -140,8 +141,6 @@ class GroupObjectModel : public BaseObjectModel bool canRemoveRows() const; virtual bool removeRows(const int position, const int rows) = 0; - -// virtual bool dropMimeData(const QMimeData* data, Qt::DropAction action, int row, int column) = 0; protected: virtual void setupData() = 0; virtual void clearData() = 0; @@ -168,7 +167,13 @@ class GroupModel : public BaseModel bool canRemoveRows() const; virtual bool removeRows(const int position, const int rows) = 0; -// virtual bool dropMimeData(const QMimeData* data, Qt::DropAction action, int row, int column) = 0; + Qt::DropActions supportedDragActions(); + Qt::DropActions supportedDropActions(); + + QString type() const + { + return ""; + } protected: QList<BaseObjectModel*> m_objects; private: diff --git a/pokemodr/models/CoinListModel.cpp b/pokemodr/models/CoinListModel.cpp index fcbadf4b..a66a8a35 100644 --- a/pokemodr/models/CoinListModel.cpp +++ b/pokemodr/models/CoinListModel.cpp @@ -48,7 +48,13 @@ QVariant CoinListModel::data(int role) const { if (role == Qt::DisplayRole) return static_cast<CoinList*>(m_object)->name(); - else if (role == Qt::UserRole) + else if (role == BaseModel::XmlRole) + { + QDomDocument xml(m_object->className()); + xml.appendChild(m_object->save()); + return xml.toString(); + } + else if (role == BaseModel::WidgetRole) { QWidget* widget = new CoinListUI(static_cast<CoinList*>(m_object), NULL); return QVariant::fromValue(widget); @@ -63,7 +69,7 @@ int CoinListModel::rowCount() const bool CoinListModel::setData(const QVariant& value, int role) { - if (role == Qt::UserRole) + if (role == BaseModel::XmlRole) { if (value.canConvert<QString>()) { @@ -113,11 +119,6 @@ bool CoinListModel::removeRows(const int position, const int rows) return true; } -// bool CoinListModel::dropMimeData(const QMimeData* data, Qt::DropAction action, int row, int column) -// { -// // TODO: drag/drop -// } - void CoinListModel::setupData() { CoinList* coinList = static_cast<CoinList*>(m_object); diff --git a/pokemodr/models/CoinListModel.h b/pokemodr/models/CoinListModel.h index b3503771..ad75dbdb 100644 --- a/pokemodr/models/CoinListModel.h +++ b/pokemodr/models/CoinListModel.h @@ -41,8 +41,6 @@ class CoinListModel : public GroupObjectModel bool insertRows(const int rows); bool removeRows(const int position, const int rows); - -// bool dropMimeData(const QMimeData* data, Qt::DropAction action, int row, int column); private: void setupData(); void clearData(); diff --git a/pokemodr/models/CoinListObjectModel.cpp b/pokemodr/models/CoinListObjectModel.cpp index 086eb700..0176b7e2 100644 --- a/pokemodr/models/CoinListObjectModel.cpp +++ b/pokemodr/models/CoinListObjectModel.cpp @@ -49,7 +49,13 @@ QVariant CoinListObjectModel::data(int role) const else if (object->type() == CoinListObject::Species) return m_object->pokemod()->species(object->object())->name(); } - else if (role == Qt::UserRole) + else if (role == BaseModel::XmlRole) + { + QDomDocument xml(m_object->className()); + xml.appendChild(m_object->save()); + return xml.toString(); + } + else if (role == BaseModel::WidgetRole) { QWidget* widget = new CoinListObjectUI(static_cast<CoinListObject*>(m_object), NULL); return QVariant::fromValue(widget); @@ -59,7 +65,7 @@ QVariant CoinListObjectModel::data(int role) const bool CoinListObjectModel::setData(const QVariant& value, int role) { - if (role == Qt::UserRole) + if (role == BaseModel::XmlRole) { if (value.canConvert<QString>()) { @@ -83,8 +89,3 @@ int CoinListObjectModel::indexNumber() const { // TODO: get index number } - -// bool CoinListObjectModel::dropMimeData(const QMimeData* data, Qt::DropAction action, int row, int column) -// { -// // TODO: drag/drop -// } diff --git a/pokemodr/models/CoinListObjectModel.h b/pokemodr/models/CoinListObjectModel.h index f9482b40..8ab37164 100644 --- a/pokemodr/models/CoinListObjectModel.h +++ b/pokemodr/models/CoinListObjectModel.h @@ -32,8 +32,6 @@ class CoinListObjectModel : public ObjectModel bool setData(const QVariant& value, int role = Qt::EditRole); int indexNumber() const; - -// bool dropMimeData(const QMimeData* data, Qt::DropAction action, int row, int column); }; #endif diff --git a/pokemodr/models/DialogModel.cpp b/pokemodr/models/DialogModel.cpp index e2d7eb3a..a39d160b 100644 --- a/pokemodr/models/DialogModel.cpp +++ b/pokemodr/models/DialogModel.cpp @@ -42,7 +42,13 @@ QVariant DialogModel::data(int role) const { if (role == Qt::DisplayRole) return static_cast<Dialog*>(m_object)->dialog(); - else if (role == Qt::UserRole) + else if (role == BaseModel::XmlRole) + { + QDomDocument xml(m_object->className()); + xml.appendChild(m_object->save()); + return xml.toString(); + } + else if (role == BaseModel::WidgetRole) { // TODO: DialogUI // QWidget* widget = new DialogUI(static_cast<Dialog*>(m_object), NULL); @@ -53,7 +59,7 @@ QVariant DialogModel::data(int role) const bool DialogModel::setData(const QVariant& value, int role) { - if (role == Qt::UserRole) + if (role == BaseModel::XmlRole) { if (value.canConvert<QString>()) { @@ -77,8 +83,3 @@ int DialogModel::indexNumber() const { return m_object->pokemod()->dialogIndex(m_object->id()); } - -// bool DialogModel::dropMimeData(const QMimeData* data, Qt::DropAction action, int row, int column) -// { -// // TODO: drag/drop -// } diff --git a/pokemodr/models/DialogModel.h b/pokemodr/models/DialogModel.h index 06380829..5902ae4f 100644 --- a/pokemodr/models/DialogModel.h +++ b/pokemodr/models/DialogModel.h @@ -32,8 +32,6 @@ class DialogModel : public ObjectModel bool setData(const QVariant& value, int role = Qt::EditRole); int indexNumber() const; - -// bool dropMimeData(const QMimeData* data, Qt::DropAction action, int row, int column); }; #endif diff --git a/pokemodr/models/EggGroupModel.cpp b/pokemodr/models/EggGroupModel.cpp index 9ef089fb..5702706a 100644 --- a/pokemodr/models/EggGroupModel.cpp +++ b/pokemodr/models/EggGroupModel.cpp @@ -42,7 +42,13 @@ QVariant EggGroupModel::data(int role) const { if (role == Qt::DisplayRole) return static_cast<EggGroup*>(m_object)->name(); - else if (role == Qt::UserRole) + else if (role == BaseModel::XmlRole) + { + QDomDocument xml(m_object->className()); + xml.appendChild(m_object->save()); + return xml.toString(); + } + else if (role == BaseModel::WidgetRole) { QWidget* widget = new EggGroupUI(static_cast<EggGroup*>(m_object), NULL); return QVariant::fromValue(widget); @@ -52,7 +58,7 @@ QVariant EggGroupModel::data(int role) const bool EggGroupModel::setData(const QVariant& value, int role) { - if (role == Qt::UserRole) + if (role == BaseModel::XmlRole) { if (value.canConvert<QString>()) { @@ -76,8 +82,3 @@ int EggGroupModel::indexNumber() const { return m_object->pokemod()->eggGroupIndex(m_object->id()); } - -// bool EggGroupModel::dropMimeData(const QMimeData* data, Qt::DropAction action, int row, int column) -// { -// // TODO: drag/drop -// } diff --git a/pokemodr/models/EggGroupModel.h b/pokemodr/models/EggGroupModel.h index a01167fb..c90aad31 100644 --- a/pokemodr/models/EggGroupModel.h +++ b/pokemodr/models/EggGroupModel.h @@ -32,8 +32,6 @@ class EggGroupModel : public ObjectModel bool setData(const QVariant& value, int role = Qt::EditRole); int indexNumber() const; - -// bool dropMimeData(const QMimeData* data, Qt::DropAction action, int row, int column); }; #endif diff --git a/pokemodr/models/ItemTypeModel.cpp b/pokemodr/models/ItemTypeModel.cpp index 8021cb6b..0fa25883 100644 --- a/pokemodr/models/ItemTypeModel.cpp +++ b/pokemodr/models/ItemTypeModel.cpp @@ -42,7 +42,13 @@ QVariant ItemTypeModel::data(int role) const { if (role == Qt::DisplayRole) return static_cast<ItemType*>(m_object)->name(); - else if (role == Qt::UserRole) + else if (role == BaseModel::XmlRole) + { + QDomDocument xml(m_object->className()); + xml.appendChild(m_object->save()); + return xml.toString(); + } + else if (role == BaseModel::WidgetRole) { QWidget* widget = new ItemTypeUI(static_cast<ItemType*>(m_object), NULL); return QVariant::fromValue(widget); @@ -52,7 +58,7 @@ QVariant ItemTypeModel::data(int role) const bool ItemTypeModel::setData(const QVariant& value, int role) { - if (role == Qt::UserRole) + if (role == BaseModel::XmlRole) { if (value.canConvert<QString>()) { @@ -76,8 +82,3 @@ int ItemTypeModel::indexNumber() const { return m_object->pokemod()->itemTypeIndex(m_object->id()); } - -// bool ItemTypeModel::dropMimeData(const QMimeData* data, Qt::DropAction action, int row, int column) -// { -// // TODO: drag/drop -// } diff --git a/pokemodr/models/ItemTypeModel.h b/pokemodr/models/ItemTypeModel.h index 08702d6d..6db72f93 100644 --- a/pokemodr/models/ItemTypeModel.h +++ b/pokemodr/models/ItemTypeModel.h @@ -32,8 +32,6 @@ class ItemTypeModel : public ObjectModel bool setData(const QVariant& value, int role = Qt::EditRole); int indexNumber() const; - -// bool dropMimeData(const QMimeData* data, Qt::DropAction action, int row, int column); }; #endif diff --git a/pokemodr/models/NatureModel.cpp b/pokemodr/models/NatureModel.cpp index 1e750173..d832c0f4 100644 --- a/pokemodr/models/NatureModel.cpp +++ b/pokemodr/models/NatureModel.cpp @@ -42,7 +42,13 @@ QVariant NatureModel::data(int role) const { if (role == Qt::DisplayRole) return static_cast<Nature*>(m_object)->name(); - else if (role == Qt::UserRole) + else if (role == BaseModel::XmlRole) + { + QDomDocument xml(m_object->className()); + xml.appendChild(m_object->save()); + return xml.toString(); + } + else if (role == BaseModel::WidgetRole) { QWidget* widget = new NatureUI(static_cast<Nature*>(m_object), NULL); return QVariant::fromValue(widget); @@ -52,7 +58,7 @@ QVariant NatureModel::data(int role) const bool NatureModel::setData(const QVariant& value, int role) { - if (role == Qt::UserRole) + if (role == BaseModel::XmlRole) { if (value.canConvert<QString>()) { @@ -76,8 +82,3 @@ int NatureModel::indexNumber() const { return m_object->pokemod()->natureIndex(m_object->id()); } - -// bool NatureModel::dropMimeData(const QMimeData* data, Qt::DropAction action, int row, int column) -// { -// // TODO: drag/drop -// } diff --git a/pokemodr/models/NatureModel.h b/pokemodr/models/NatureModel.h index 78e9714b..89a00b61 100644 --- a/pokemodr/models/NatureModel.h +++ b/pokemodr/models/NatureModel.h @@ -32,8 +32,6 @@ class NatureModel : public ObjectModel bool setData(const QVariant& value, int role = Qt::EditRole); int indexNumber() const; - -// bool dropMimeData(const QMimeData* data, Qt::DropAction action, int row, int column); }; #endif diff --git a/pokemodr/models/PokemodModel.cpp b/pokemodr/models/PokemodModel.cpp index 4ea6e7a1..73ecf36e 100644 --- a/pokemodr/models/PokemodModel.cpp +++ b/pokemodr/models/PokemodModel.cpp @@ -96,11 +96,6 @@ bool AbilityGroupModel::removeRows(const int position, const int rows) return true; } -// bool AbilityGroupModel::dropMimeData(const QMimeData* data, Qt::DropAction action, int row, int column) -// { -// // TODO: drag/drop -// } - BadgeGroupModel::BadgeGroupModel(BaseModel* parent, Object* object) : GroupModel(parent, object, "Badges") { @@ -141,11 +136,6 @@ bool BadgeGroupModel::removeRows(const int position, const int rows) return true; } -// bool BadgeGroupModel::dropMimeData(const QMimeData* data, Qt::DropAction action, int row, int column) -// { -// // TODO: drag/drop -// } - CoinListGroupModel::CoinListGroupModel(BaseModel* parent, Object* object) : GroupModel(parent, object, "Coin Lists") { @@ -186,11 +176,6 @@ bool CoinListGroupModel::removeRows(const int position, const int rows) return true; } -// bool CoinListGroupModel::dropMimeData(const QMimeData* data, Qt::DropAction action, int row, int column) -// { -// // TODO: drag/drop -// } - DialogGroupModel::DialogGroupModel(BaseModel* parent, Object* object) : GroupModel(parent, object, "Dialogs") { @@ -231,11 +216,6 @@ bool DialogGroupModel::removeRows(const int position, const int rows) return true; } -// bool DialogGroupModel::dropMimeData(const QMimeData* data, Qt::DropAction action, int row, int column) -// { -// // TODO: drag/drop -// } - EggGroupGroupModel::EggGroupGroupModel(BaseModel* parent, Object* object) : GroupModel(parent, object, "Egg Groups") { @@ -276,11 +256,6 @@ bool EggGroupGroupModel::removeRows(const int position, const int rows) return true; } -// bool EggGroupGroupModel::dropMimeData(const QMimeData* data, Qt::DropAction action, int row, int column) -// { -// // TODO: drag/drop -// } - ItemGroupModel::ItemGroupModel(BaseModel* parent, Object* object) : GroupModel(parent, object, "Items") { @@ -323,11 +298,6 @@ bool ItemGroupModel::removeRows(const int position, const int rows) return true; } -// bool ItemGroupModel::dropMimeData(const QMimeData* data, Qt::DropAction action, int row, int column) -// { -// // TODO: drag/drop -// } - ItemTypeGroupModel::ItemTypeGroupModel(BaseModel* parent, Object* object) : GroupModel(parent, object, "Item Types") { @@ -368,11 +338,6 @@ bool ItemTypeGroupModel::removeRows(const int position, const int rows) return true; } -// bool ItemTypeGroupModel::dropMimeData(const QMimeData* data, Qt::DropAction action, int row, int column) -// { -// // TODO: drag/drop -// } - MapGroupModel::MapGroupModel(BaseModel* parent, Object* object) : GroupModel(parent, object, "Maps") { @@ -415,11 +380,6 @@ bool MapGroupModel::removeRows(const int position, const int rows) return true; } -// bool MapGroupModel::dropMimeData(const QMimeData* data, Qt::DropAction action, int row, int column) -// { -// // TODO: drag/drop -// } - MoveGroupModel::MoveGroupModel(BaseModel* parent, Object* object) : GroupModel(parent, object, "Moves") { @@ -462,11 +422,6 @@ bool MoveGroupModel::removeRows(const int position, const int rows) return true; } -// bool MoveGroupModel::dropMimeData(const QMimeData* data, Qt::DropAction action, int row, int column) -// { -// // TODO: drag/drop -// } - NatureGroupModel::NatureGroupModel(BaseModel* parent, Object* object) : GroupModel(parent, object, "Natures") { @@ -507,11 +462,6 @@ bool NatureGroupModel::removeRows(const int position, const int rows) return true; } -// bool NatureGroupModel::dropMimeData(const QMimeData* data, Qt::DropAction action, int row, int column) -// { -// // TODO: drag/drop -// } - SpeciesGroupModel::SpeciesGroupModel(BaseModel* parent, Object* object) : GroupModel(parent, object, "Species") { @@ -554,11 +504,6 @@ bool SpeciesGroupModel::removeRows(const int position, const int rows) return true; } -// bool SpeciesGroupModel::dropMimeData(const QMimeData* data, Qt::DropAction action, int row, int column) -// { -// // TODO: drag/drop -// } - StoreGroupModel::StoreGroupModel(BaseModel* parent, Object* object) : GroupModel(parent, object, "Stores") { @@ -599,11 +544,6 @@ bool StoreGroupModel::removeRows(const int position, const int rows) return true; } -// bool StoreGroupModel::dropMimeData(const QMimeData* data, Qt::DropAction action, int row, int column) -// { -// // TODO: drag/drop -// } - TileGroupModel::TileGroupModel(BaseModel* parent, Object* object) : GroupModel(parent, object, "Tiles") { @@ -644,11 +584,6 @@ bool TileGroupModel::removeRows(const int position, const int rows) return true; } -// bool TileGroupModel::dropMimeData(const QMimeData* data, Qt::DropAction action, int row, int column) -// { -// // TODO: drag/drop -// } - TimeGroupModel::TimeGroupModel(BaseModel* parent, Object* object) : GroupModel(parent, object, "Times") { @@ -689,11 +624,6 @@ bool TimeGroupModel::removeRows(const int position, const int rows) return true; } -// bool TimeGroupModel::dropMimeData(const QMimeData* data, Qt::DropAction action, int row, int column) -// { -// // TODO: drag/drop -// } - TrainerGroupModel::TrainerGroupModel(BaseModel* parent, Object* object) : GroupModel(parent, object, "Trainers") { @@ -734,11 +664,6 @@ bool TrainerGroupModel::removeRows(const int position, const int rows) return true; } -// bool TrainerGroupModel::dropMimeData(const QMimeData* data, Qt::DropAction action, int row, int column) -// { -// // TODO: drag/drop -// } - TypeGroupModel::TypeGroupModel(BaseModel* parent, Object* object) : GroupModel(parent, object, "Types") { @@ -779,11 +704,6 @@ bool TypeGroupModel::removeRows(const int position, const int rows) return true; } -// bool TypeGroupModel::dropMimeData(const QMimeData* data, Qt::DropAction action, int row, int column) -// { -// // TODO: drag/drop -// } - PokemodModel::PokemodModel(BaseModel* parent, Object* object) : GroupObjectModel(parent, object) { @@ -799,7 +719,13 @@ QVariant PokemodModel::data(int role) const { if (role == Qt::DisplayRole) return static_cast<Pokemod*>(m_object)->title(); - else if (role == Qt::UserRole) + else if (role == BaseModel::XmlRole) + { + QDomDocument xml(m_object->className()); + xml.appendChild(m_object->save()); + return xml.toString(); + } + else if (role == BaseModel::WidgetRole) { QWidget* widget = new PokemodUI(static_cast<Pokemod*>(m_object), NULL); return QVariant::fromValue(widget); @@ -814,7 +740,7 @@ int PokemodModel::rowCount() const bool PokemodModel::setData(const QVariant& value, int role) { - if (role == Qt::UserRole) + if (role == BaseModel::XmlRole) { if (value.canConvert<QString>()) { @@ -913,11 +839,6 @@ bool PokemodModel::removeRows(const int position, const int rows) return false; } -// bool PokemodModel::dropMimeData(const QMimeData* data, Qt::DropAction action, int row, int column) -// { -// // TODO: drag/drop -// } - void PokemodModel::setupData() { m_rules = new RulesModel(this, static_cast<Pokemod*>(m_object)->rules()); diff --git a/pokemodr/models/PokemodModel.h b/pokemodr/models/PokemodModel.h index eed1275d..cec2951f 100644 --- a/pokemodr/models/PokemodModel.h +++ b/pokemodr/models/PokemodModel.h @@ -35,8 +35,6 @@ class AbilityGroupModel : public GroupModel bool insertRows(const int rows); bool removeRows(const int position, const int rows); - -// bool dropMimeData(const QMimeData* data, Qt::DropAction action, int row, int column); }; class BadgeGroupModel : public GroupModel @@ -52,8 +50,6 @@ class BadgeGroupModel : public GroupModel bool insertRows(const int rows); bool removeRows(const int position, const int rows); - -// bool dropMimeData(const QMimeData* data, Qt::DropAction action, int row, int column); }; class CoinListGroupModel : public GroupModel @@ -69,8 +65,6 @@ class CoinListGroupModel : public GroupModel bool insertRows(const int rows); bool removeRows(const int position, const int rows); - -// bool dropMimeData(const QMimeData* data, Qt::DropAction action, int row, int column); }; class DialogGroupModel : public GroupModel @@ -86,8 +80,6 @@ class DialogGroupModel : public GroupModel bool insertRows(const int rows); bool removeRows(const int position, const int rows); - -// bool dropMimeData(const QMimeData* data, Qt::DropAction action, int row, int column); }; class EggGroupGroupModel : public GroupModel @@ -103,8 +95,6 @@ class EggGroupGroupModel : public GroupModel bool insertRows(const int rows); bool removeRows(const int position, const int rows); - -// bool dropMimeData(const QMimeData* data, Qt::DropAction action, int row, int column); }; class ItemGroupModel : public GroupModel @@ -120,8 +110,6 @@ class ItemGroupModel : public GroupModel bool insertRows(const int rows); bool removeRows(const int position, const int rows); - -// bool dropMimeData(const QMimeData* data, Qt::DropAction action, int row, int column); }; class ItemTypeGroupModel : public GroupModel @@ -137,8 +125,6 @@ class ItemTypeGroupModel : public GroupModel bool insertRows(const int rows); bool removeRows(const int position, const int rows); - -// bool dropMimeData(const QMimeData* data, Qt::DropAction action, int row, int column); }; class MapGroupModel : public GroupModel @@ -154,8 +140,6 @@ class MapGroupModel : public GroupModel bool insertRows(const int rows); bool removeRows(const int position, const int rows); - -// bool dropMimeData(const QMimeData* data, Qt::DropAction action, int row, int column); }; class MoveGroupModel : public GroupModel @@ -171,8 +155,6 @@ class MoveGroupModel : public GroupModel bool insertRows(const int rows); bool removeRows(const int position, const int rows); - -// bool dropMimeData(const QMimeData* data, Qt::DropAction action, int row, int column); }; class NatureGroupModel : public GroupModel @@ -188,8 +170,6 @@ class NatureGroupModel : public GroupModel bool insertRows(const int rows); bool removeRows(const int position, const int rows); - -// bool dropMimeData(const QMimeData* data, Qt::DropAction action, int row, int column); }; class SpeciesGroupModel : public GroupModel @@ -205,8 +185,6 @@ class SpeciesGroupModel : public GroupModel bool insertRows(const int rows); bool removeRows(const int position, const int rows); - -// bool dropMimeData(const QMimeData* data, Qt::DropAction action, int row, int column); }; class StoreGroupModel : public GroupModel @@ -222,8 +200,6 @@ class StoreGroupModel : public GroupModel bool insertRows(const int rows); bool removeRows(const int position, const int rows); - -// bool dropMimeData(const QMimeData* data, Qt::DropAction action, int row, int column); }; class TileGroupModel : public GroupModel @@ -239,8 +215,6 @@ class TileGroupModel : public GroupModel bool insertRows(const int rows); bool removeRows(const int position, const int rows); - -// bool dropMimeData(const QMimeData* data, Qt::DropAction action, int row, int column); }; class TimeGroupModel : public GroupModel @@ -256,8 +230,6 @@ class TimeGroupModel : public GroupModel bool insertRows(const int rows); bool removeRows(const int position, const int rows); - -// bool dropMimeData(const QMimeData* data, Qt::DropAction action, int row, int column); }; class TrainerGroupModel : public GroupModel @@ -273,8 +245,6 @@ class TrainerGroupModel : public GroupModel bool insertRows(const int rows); bool removeRows(const int position, const int rows); - -// bool dropMimeData(const QMimeData* data, Qt::DropAction action, int row, int column); }; class TypeGroupModel : public GroupModel @@ -290,8 +260,6 @@ class TypeGroupModel : public GroupModel bool insertRows(const int rows); bool removeRows(const int position, const int rows); - -// bool dropMimeData(const QMimeData* data, Qt::DropAction action, int row, int column); }; class PokemodModel : public GroupObjectModel @@ -311,8 +279,6 @@ class PokemodModel : public GroupObjectModel bool insertRows(const int rows); bool removeRows(const int position, const int rows); - -// bool dropMimeData(const QMimeData* data, Qt::DropAction action, int row, int column); private: void setupData(); void clearData(); diff --git a/pokemodr/models/RootModel.cpp b/pokemodr/models/RootModel.cpp index 52e5021d..ad5bd7b7 100644 --- a/pokemodr/models/RootModel.cpp +++ b/pokemodr/models/RootModel.cpp @@ -83,8 +83,3 @@ bool RootModel::removeRows(const int position, const int rows) } return true; } - -// bool RootModel::dropMimeData(const QMimeData* data, Qt::DropAction action, int row, int column) -// { -// // TODO: drag/drop -// } diff --git a/pokemodr/models/RootModel.h b/pokemodr/models/RootModel.h index 9c494aa3..d93e214b 100644 --- a/pokemodr/models/RootModel.h +++ b/pokemodr/models/RootModel.h @@ -43,8 +43,6 @@ class RootModel : public BaseModel inline bool canRemoveRows() const; inline bool removeRows(const int position, const int rows); - -// bool dropMimeData(const QMimeData* data, Qt::DropAction action, int row, int column); private: QList<PokemodModel*> m_pokemods; }; diff --git a/pokemodr/models/RulesModel.cpp b/pokemodr/models/RulesModel.cpp index 1f592c94..6b52b482 100644 --- a/pokemodr/models/RulesModel.cpp +++ b/pokemodr/models/RulesModel.cpp @@ -41,7 +41,13 @@ QVariant RulesModel::data(int role) const { if (role == Qt::DisplayRole) return "Rules"; - else if (role == Qt::UserRole) + else if (role == BaseModel::XmlRole) + { + QDomDocument xml(m_object->className()); + xml.appendChild(m_object->save()); + return xml.toString(); + } + else if (role == BaseModel::WidgetRole) { QWidget* widget = new RulesUI(static_cast<Rules*>(m_object), NULL); return QVariant::fromValue(widget); @@ -51,7 +57,7 @@ QVariant RulesModel::data(int role) const bool RulesModel::setData(const QVariant& value, int role) { - if (role == Qt::UserRole) + if (role == BaseModel::XmlRole) { if (value.canConvert<QString>()) { @@ -75,8 +81,3 @@ int RulesModel::indexNumber() const { return 0; } - -// bool RulesModel::dropMimeData(const QMimeData* data, Qt::DropAction action, int row, int column) -// { -// // TODO: drag/drop -// } diff --git a/pokemodr/models/RulesModel.h b/pokemodr/models/RulesModel.h index 6177434e..1ce9f070 100644 --- a/pokemodr/models/RulesModel.h +++ b/pokemodr/models/RulesModel.h @@ -32,8 +32,6 @@ class RulesModel : public ObjectModel bool setData(const QVariant& value, int role = Qt::EditRole); int indexNumber() const; - -// bool dropMimeData(const QMimeData* data, Qt::DropAction action, int row, int column); }; #endif diff --git a/pokemodr/models/StoreModel.cpp b/pokemodr/models/StoreModel.cpp index 37dd199e..acf100fd 100644 --- a/pokemodr/models/StoreModel.cpp +++ b/pokemodr/models/StoreModel.cpp @@ -42,7 +42,13 @@ QVariant StoreModel::data(int role) const { if (role == Qt::DisplayRole) return static_cast<Store*>(m_object)->name(); - else if (role == Qt::UserRole) + else if (role == BaseModel::XmlRole) + { + QDomDocument xml(m_object->className()); + xml.appendChild(m_object->save()); + return xml.toString(); + } + else if (role == BaseModel::WidgetRole) { QWidget* widget = new StoreUI(static_cast<Store*>(m_object), NULL); return QVariant::fromValue(widget); @@ -52,7 +58,7 @@ QVariant StoreModel::data(int role) const bool StoreModel::setData(const QVariant& value, int role) { - if (role == Qt::UserRole) + if (role == BaseModel::XmlRole) { if (value.canConvert<QString>()) { @@ -76,8 +82,3 @@ int StoreModel::indexNumber() const { return m_object->pokemod()->storeIndex(m_object->id()); } - -// bool StoreModel::dropMimeData(const QMimeData* data, Qt::DropAction action, int row, int column) -// { -// // TODO: drag/drop -// } diff --git a/pokemodr/models/StoreModel.h b/pokemodr/models/StoreModel.h index af343146..e269c70b 100644 --- a/pokemodr/models/StoreModel.h +++ b/pokemodr/models/StoreModel.h @@ -32,8 +32,6 @@ class StoreModel : public ObjectModel bool setData(const QVariant& value, int role = Qt::EditRole); int indexNumber() const; - -// bool dropMimeData(const QMimeData* data, Qt::DropAction action, int row, int column); }; #endif diff --git a/pokemodr/models/TileModel.cpp b/pokemodr/models/TileModel.cpp index 06e8e280..3bca9275 100644 --- a/pokemodr/models/TileModel.cpp +++ b/pokemodr/models/TileModel.cpp @@ -42,7 +42,13 @@ QVariant TileModel::data(int role) const { if (role == Qt::DisplayRole) return static_cast<Tile*>(m_object)->name(); - else if (role == Qt::UserRole) + else if (role == BaseModel::XmlRole) + { + QDomDocument xml(m_object->className()); + xml.appendChild(m_object->save()); + return xml.toString(); + } + else if (role == BaseModel::WidgetRole) { QWidget* widget = new TileUI(static_cast<Tile*>(m_object), NULL); return QVariant::fromValue(widget); @@ -52,7 +58,7 @@ QVariant TileModel::data(int role) const bool TileModel::setData(const QVariant& value, int role) { - if (role == Qt::UserRole) + if (role == BaseModel::XmlRole) { if (value.canConvert<QString>()) { @@ -76,8 +82,3 @@ int TileModel::indexNumber() const { return m_object->pokemod()->tileIndex(m_object->id()); } - -// bool TileModel::dropMimeData(const QMimeData* data, Qt::DropAction action, int row, int column) -// { -// // TODO: drag/drop -// } diff --git a/pokemodr/models/TileModel.h b/pokemodr/models/TileModel.h index 6ea2f404..e390f42f 100644 --- a/pokemodr/models/TileModel.h +++ b/pokemodr/models/TileModel.h @@ -32,8 +32,6 @@ class TileModel : public ObjectModel bool setData(const QVariant& value, int role = Qt::EditRole); int indexNumber() const; - -// bool dropMimeData(const QMimeData* data, Qt::DropAction action, int row, int column); }; #endif diff --git a/pokemodr/models/TimeModel.cpp b/pokemodr/models/TimeModel.cpp index d58245b9..4fac20ce 100644 --- a/pokemodr/models/TimeModel.cpp +++ b/pokemodr/models/TimeModel.cpp @@ -42,7 +42,13 @@ QVariant TimeModel::data(int role) const { if (role == Qt::DisplayRole) return static_cast<Time*>(m_object)->name(); - else if (role == Qt::UserRole) + else if (role == BaseModel::XmlRole) + { + QDomDocument xml(m_object->className()); + xml.appendChild(m_object->save()); + return xml.toString(); + } + else if (role == BaseModel::WidgetRole) { QWidget* widget = new TimeUI(static_cast<Time*>(m_object), NULL); return QVariant::fromValue(widget); @@ -52,7 +58,7 @@ QVariant TimeModel::data(int role) const bool TimeModel::setData(const QVariant& value, int role) { - if (role == Qt::UserRole) + if (role == BaseModel::XmlRole) { if (value.canConvert<QString>()) { @@ -76,8 +82,3 @@ int TimeModel::indexNumber() const { return m_object->pokemod()->timeIndex(m_object->id()); } - -// bool TimeModel::dropMimeData(const QMimeData* data, Qt::DropAction action, int row, int column) -// { -// // TODO: drag/drop -// } diff --git a/pokemodr/models/TimeModel.h b/pokemodr/models/TimeModel.h index 20ef1901..2b7865d3 100644 --- a/pokemodr/models/TimeModel.h +++ b/pokemodr/models/TimeModel.h @@ -32,8 +32,6 @@ class TimeModel : public ObjectModel bool setData(const QVariant& value, int role = Qt::EditRole); int indexNumber() const; - -// bool dropMimeData(const QMimeData* data, Qt::DropAction action, int row, int column); }; #endif diff --git a/pokemodr/models/TrainerModel.cpp b/pokemodr/models/TrainerModel.cpp index 0b3a47e5..1fef0eea 100644 --- a/pokemodr/models/TrainerModel.cpp +++ b/pokemodr/models/TrainerModel.cpp @@ -42,7 +42,13 @@ QVariant TrainerModel::data(int role) const { if (role == Qt::DisplayRole) return static_cast<Trainer*>(m_object)->name(); - else if (role == Qt::UserRole) + else if (role == BaseModel::XmlRole) + { + QDomDocument xml(m_object->className()); + xml.appendChild(m_object->save()); + return xml.toString(); + } + else if (role == BaseModel::WidgetRole) { QWidget* widget = new TrainerUI(static_cast<Trainer*>(m_object), NULL); return QVariant::fromValue(widget); @@ -52,7 +58,7 @@ QVariant TrainerModel::data(int role) const bool TrainerModel::setData(const QVariant& value, int role) { - if (role == Qt::UserRole) + if (role == BaseModel::XmlRole) { if (value.canConvert<QString>()) { @@ -76,8 +82,3 @@ int TrainerModel::indexNumber() const { return m_object->pokemod()->trainerIndex(m_object->id()); } - -// bool TrainerModel::dropMimeData(const QMimeData* data, Qt::DropAction action, int row, int column) -// { -// // TODO: drag/drop -// } diff --git a/pokemodr/models/TrainerModel.h b/pokemodr/models/TrainerModel.h index c90ad911..e2d40e0a 100644 --- a/pokemodr/models/TrainerModel.h +++ b/pokemodr/models/TrainerModel.h @@ -32,8 +32,6 @@ class TrainerModel : public ObjectModel bool setData(const QVariant& value, int role = Qt::EditRole); int indexNumber() const; - -// bool dropMimeData(const QMimeData* data, Qt::DropAction action, int row, int column); }; #endif diff --git a/pokemodr/models/TypeModel.cpp b/pokemodr/models/TypeModel.cpp index 37c0a6d5..b3678ab1 100644 --- a/pokemodr/models/TypeModel.cpp +++ b/pokemodr/models/TypeModel.cpp @@ -42,7 +42,13 @@ QVariant TypeModel::data(int role) const { if (role == Qt::DisplayRole) return static_cast<Type*>(m_object)->name(); - else if (role == Qt::UserRole) + else if (role == BaseModel::XmlRole) + { + QDomDocument xml(m_object->className()); + xml.appendChild(m_object->save()); + return xml.toString(); + } + else if (role == BaseModel::WidgetRole) { QWidget* widget = new TypeUI(static_cast<Type*>(m_object), NULL); return QVariant::fromValue(widget); @@ -52,7 +58,7 @@ QVariant TypeModel::data(int role) const bool TypeModel::setData(const QVariant& value, int role) { - if (role == Qt::UserRole) + if (role == BaseModel::XmlRole) { if (value.canConvert<QString>()) { @@ -76,8 +82,3 @@ int TypeModel::indexNumber() const { return m_object->pokemod()->typeIndex(m_object->id()); } - -// bool TypeModel::dropMimeData(const QMimeData* data, Qt::DropAction action, int row, int column) -// { -// // TODO: drag/drop -// } diff --git a/pokemodr/models/TypeModel.h b/pokemodr/models/TypeModel.h index bc4e1952..9c9afaf6 100644 --- a/pokemodr/models/TypeModel.h +++ b/pokemodr/models/TypeModel.h @@ -32,8 +32,6 @@ class TypeModel : public ObjectModel bool setData(const QVariant& value, int role = Qt::EditRole); int indexNumber() const; - -// bool dropMimeData(const QMimeData* data, Qt::DropAction action, int row, int column); }; #endif |
