summaryrefslogtreecommitdiffstats
path: root/pokemodr/models/CoinListModel.cpp
diff options
context:
space:
mode:
authorBen Boeckel <MathStuf@gmail.com>2008-04-24 20:21:59 +0000
committerBen Boeckel <MathStuf@gmail.com>2008-04-24 20:21:59 +0000
commit446fcd9248d4cef74e905c485ef767a94a8463ec (patch)
tree66fa3e7a0536303395bd5b88abb6e1b2cacc8383 /pokemodr/models/CoinListModel.cpp
parentd7b6b0627a7d5e0875a263bf9501506a3d8da450 (diff)
downloadsigen-446fcd9248d4cef74e905c485ef767a94a8463ec.tar.gz
sigen-446fcd9248d4cef74e905c485ef767a94a8463ec.tar.xz
sigen-446fcd9248d4cef74e905c485ef767a94a8463ec.zip
[ADD] More model classes
[FIX] Minor things within the models git-svn-id: https://pokegen.svn.sourceforge.net/svnroot/pokegen/trunk@106 6ecfd1a5-f3ed-3746-8530-beee90d26b22
Diffstat (limited to 'pokemodr/models/CoinListModel.cpp')
-rw-r--r--pokemodr/models/CoinListModel.cpp140
1 files changed, 140 insertions, 0 deletions
diff --git a/pokemodr/models/CoinListModel.cpp b/pokemodr/models/CoinListModel.cpp
new file mode 100644
index 00000000..a7c6b892
--- /dev/null
+++ b/pokemodr/models/CoinListModel.cpp
@@ -0,0 +1,140 @@
+/*
+ * Copyright 2008 Ben Boeckel <MathStuf@gmail.com>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+// Qt includes
+#include <QDomDocument>
+#include <QFile>
+
+// Pokemod includes
+#include <CoinList.h>
+#include <CoinListObject.h>
+#include <Pokemod.h>
+
+// PokeModr includes
+#include "CoinListUI.h"
+
+// Model includes
+#include "CoinListObjectModel.h"
+
+// Header include
+#include "CoinListModel.h"
+
+CoinListModel::CoinListModel(BaseModel* parent, Object* object) :
+ ObjectModel(parent, object)
+{
+ CoinList* coinList = static_cast<CoinList*>(m_object);
+ for (int i = 0; i < coinList->objectCount(); ++i)
+ m_objects.append(new CoinListObjectModel(this, coinList->object(i)));
+}
+
+CoinListModel::~CoinListModel()
+{
+ // TODO: destruct
+}
+
+QVariant CoinListModel::data(int role) const
+{
+ if (role == Qt::DisplayRole)
+ return static_cast<CoinList*>(m_object)->name();
+ else if (role == Qt::UserRole)
+ {
+ QWidget* widget = new CoinListUI(static_cast<CoinList*>(m_object), NULL);
+ return QVariant::fromValue(widget);
+ }
+ return QVariant();
+}
+
+int CoinListModel::rowCount() const
+{
+ return 0;
+}
+
+bool CoinListModel::setData(const QVariant& value, int role)
+{
+ if (role == Qt::UserRole)
+ {
+ // TODO: reset objects
+ if (value.canConvert<void*>())
+ {
+ *static_cast<CoinList*>(m_object) = *static_cast<CoinList*>(value.value<void*>());
+ return true;
+ }
+ else if (value.canConvert<QString>())
+ {
+ QFile file(value.toString());
+ QDomDocument xml;
+ if (file.open(QIODevice::ReadOnly))
+ {
+ if (xml.setContent(&file))
+ {
+ if (xml.doctype().name() == m_object->className())
+ m_object->load(xml.documentElement());
+ }
+ file.close();
+ }
+ else if (xml.setContent(value.toString()))
+ {
+ if (xml.doctype().name() == m_object->className())
+ m_object->load(xml.documentElement());
+ }
+ }
+ }
+ return false;
+}
+
+BaseModel* CoinListModel::childItem(const int row)
+{
+ return m_objects[row];
+}
+
+int CoinListModel::indexNumber() const
+{
+ return m_object->pokemod()->coinListIndex(m_object->id());
+}
+
+bool CoinListModel::canInsertRows() const
+{
+ return true;
+}
+
+bool CoinListModel::insertRows(const int rows)
+{
+ for (int i = 0; i < rows; ++i)
+ m_objects.append(new CoinListObjectModel(this, static_cast<CoinList*>(m_object)->newObject()));
+ return true;
+}
+
+bool CoinListModel::canRemoveRows() const
+{
+ return true;
+}
+
+bool CoinListModel::removeRows(const int position, const int rows)
+{
+ for (int i = 0; i < rows; ++i)
+ {
+ static_cast<CoinList*>(m_object)->deleteObject(position);
+ delete m_objects[position];
+ m_objects.removeAt(position);
+ }
+ return true;
+}
+
+// bool CoinListModel::dropMimeData(const QMimeData* data, Qt::DropAction action, int row, int column)
+// {
+// // TODO: drag/drop
+// }