From d7b6b0627a7d5e0875a263bf9501506a3d8da450 Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Thu, 24 Apr 2008 18:46:14 +0000 Subject: [ADD] New classes for the models [FIX] Stuff cleaned up for better profiling (no inlining until profiler says so) git-svn-id: https://pokegen.svn.sourceforge.net/svnroot/pokegen/trunk@105 6ecfd1a5-f3ed-3746-8530-beee90d26b22 --- pokemodr/models/BaseModel.cpp | 89 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 pokemodr/models/BaseModel.cpp (limited to 'pokemodr/models/BaseModel.cpp') diff --git a/pokemodr/models/BaseModel.cpp b/pokemodr/models/BaseModel.cpp new file mode 100644 index 00000000..bb0392ff --- /dev/null +++ b/pokemodr/models/BaseModel.cpp @@ -0,0 +1,89 @@ +/* + * Copyright 2008 Ben Boeckel + * + * 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 . + */ + +// Header include +#include "BaseModel.h" + +BaseModel::BaseModel(BaseModel* parent, Object* object, const QString& name) : + m_object(object), + m_name(name), + m_parent(parent) +{ +} + +BaseModel* BaseModel::parent() +{ + return m_parent; +} + +// Qt::DropActions BaseModel::supportedDragActions() +// { +// return Qt::CopyAction | Qt::MoveAction; +// } +// +// Qt::DropActions BaseModel::supportedDropActions() +// { +// return Qt::CopyAction | Qt::MoveAction; +// } + +ObjectModel::ObjectModel(BaseModel* parent, Object* object) : + BaseModel(parent, object, "") +{ +} + +Qt::ItemFlags ObjectModel::flags() const +{ + return Qt::ItemIsDragEnabled | Qt::ItemIsSelectable | Qt::ItemIsDropEnabled | Qt::ItemIsEnabled; +} + +GroupModel::GroupModel(BaseModel* parent, Object* object, const QString& name) : + BaseModel(parent, object, name) +{ +} + +GroupModel::~GroupModel() +{ + foreach (ObjectModel* model, m_objects) + delete model; +} + +QVariant GroupModel::data(int role) const +{ + if (role == Qt::DisplayRole) + return m_name; + return QVariant(); +} + +Qt::ItemFlags GroupModel::flags() const +{ + return Qt::ItemIsDropEnabled | Qt::ItemIsEnabled; +} + +bool GroupModel::setData(const QVariant& /*value*/, int /*role = Qt::EditRole*/) +{ + return false; +} + +bool GroupModel::canInsertRows() const +{ + return true; +} + +bool GroupModel::canRemoveRows() const +{ + return true; +} -- cgit