summaryrefslogtreecommitdiffstats
path: root/pokemodr/PokemodTreeModel.cpp
diff options
context:
space:
mode:
authorBen Boeckel <MathStuf@gmail.com>2008-04-27 15:15:17 +0000
committerBen Boeckel <MathStuf@gmail.com>2008-04-27 15:15:17 +0000
commit807071d35159de0660f9df31c48d5bf895ca3622 (patch)
treea1e9dbdc1e58b91cd2e4a5e472597b0204ccb41d /pokemodr/PokemodTreeModel.cpp
parentf444f5a45e9325644a360f656176d47d7f540f52 (diff)
downloadsigen-807071d35159de0660f9df31c48d5bf895ca3622.tar.gz
sigen-807071d35159de0660f9df31c48d5bf895ca3622.tar.xz
sigen-807071d35159de0660f9df31c48d5bf895ca3622.zip
[FIX] Pokemod objects now know about parents
[FIX] Project includes are now relative [FIX] Headers included for better detection of invalid headers [FIX] Validation code commented out so it can be done better git-svn-id: https://pokegen.svn.sourceforge.net/svnroot/pokegen/trunk@111 6ecfd1a5-f3ed-3746-8530-beee90d26b22
Diffstat (limited to 'pokemodr/PokemodTreeModel.cpp')
-rw-r--r--pokemodr/PokemodTreeModel.cpp49
1 files changed, 25 insertions, 24 deletions
diff --git a/pokemodr/PokemodTreeModel.cpp b/pokemodr/PokemodTreeModel.cpp
index 0bf78e34..5271ba15 100644
--- a/pokemodr/PokemodTreeModel.cpp
+++ b/pokemodr/PokemodTreeModel.cpp
@@ -15,20 +15,21 @@
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-// Qt includes
-#include <QMimeData>
+// Header include
+#include "PokemodTreeModel.h"
// Model includes
#include "models/RootModel.h"
-// Header include
-#include "PokemodTreeModel.h"
+// Qt includes
+#include <QMimeData>
PokemodTreeModel::PokemodTreeModel(const QStringList& pokemods, QObject* parent) :
QAbstractItemModel(parent)
{
+ emit(layoutAboutToBeChanged());
m_root = new RootModel(QList<QVariant>());
- // TODO: construct
+ emit(layoutChanged());
}
PokemodTreeModel::~PokemodTreeModel()
@@ -44,6 +45,11 @@ QVariant PokemodTreeModel::data(const QModelIndex& index, int role) const
return object->data(role);
}
+QVariant PokemodTreeModel::headerData(int /*section*/, Qt::Orientation /*orientation*/, int /*role = Qt::DisplayRole*/) const
+{
+ return QVariant();
+}
+
QModelIndex PokemodTreeModel::index(int row, int /*column*/, const QModelIndex& parent) const
{
if (!parent.isValid())
@@ -68,9 +74,7 @@ QModelIndex PokemodTreeModel::parent(const QModelIndex& index) const
int PokemodTreeModel::rowCount(const QModelIndex& parent) const
{
- if (!parent.isValid())
- return 0;
- BaseModel* object = static_cast<BaseModel*>(parent.internalPointer());
+ BaseModel* object = getItem(parent);
return object->rowCount();
}
int PokemodTreeModel::columnCount(const QModelIndex& /*parent*/) const
@@ -91,17 +95,11 @@ bool PokemodTreeModel::setData(const QModelIndex& index, const QVariant& value,
if (!index.isValid())
return false;
BaseModel* object = static_cast<BaseModel*>(index.internalPointer());
- return object->setData(value, role);
-}
-
-bool PokemodTreeModel::insertColumns(int /*position*/, int /*columns*/, const QModelIndex& /*parent*/)
-{
- return false;
-}
-
-bool PokemodTreeModel::removeColumns(int /*position*/, int /*columns*/, const QModelIndex& /*parent*/)
-{
- return false;
+ emit(layoutAboutToBeChanged());
+ bool success = object->setData(value, role);
+ emit(dataChanged(index, index));
+ emit(layoutChanged());
+ return success;
}
bool PokemodTreeModel::insertRows(int /*position*/, int rows, const QModelIndex& parent)
@@ -109,9 +107,9 @@ bool PokemodTreeModel::insertRows(int /*position*/, int rows, const QModelIndex&
BaseModel* object = getItem(parent);
if (!object->canInsertRows())
return false;
- emit(beginInsertRows(parent, object->rowCount(), object->rowCount() + rows - 1));
+ emit(layoutAboutToBeChanged());
bool success = object->insertRows(rows);
- emit(endInsertRows());
+ emit(layoutChanged());
return success;
}
@@ -120,9 +118,9 @@ bool PokemodTreeModel::removeRows(int position, int rows, const QModelIndex& par
BaseModel* object = getItem(parent);
if (!object->canRemoveRows())
return false;
- emit(beginRemoveRows(parent, position, position + rows - 1));
+ emit(layoutAboutToBeChanged());
bool success = object->removeRows(position, rows);
- emit(endRemoveRows());
+ emit(layoutChanged());
return success;
}
@@ -162,5 +160,8 @@ bool PokemodTreeModel::dropMimeData(const QMimeData* data, Qt::DropAction action
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);
+ emit(layoutAboutToBeChanged());
+ bool success = m_root->setData(data->data("application/x-pokemod+xml"), BaseModel::XmlRole);
+ emit(layoutChanged());
+ return success;
}