diff options
| author | Ben Boeckel <MathStuf@gmail.com> | 2009-02-23 11:34:15 -0500 |
|---|---|---|
| committer | Ben Boeckel <MathStuf@gmail.com> | 2009-02-23 11:34:15 -0500 |
| commit | 18efef142da109d395d3d9761225a4936dee9e4d (patch) | |
| tree | fc86c72b59cd2739a4c63e0cfbaf5e864c08b4d7 /sigmodr/models/BaseModel.cpp | |
| parent | 7aff48012c3040a675543a0ff3d23af6cb8a8638 (diff) | |
| download | sigen-18efef142da109d395d3d9761225a4936dee9e4d.tar.gz sigen-18efef142da109d395d3d9761225a4936dee9e4d.tar.xz sigen-18efef142da109d395d3d9761225a4936dee9e4d.zip | |
Moved the tree for sigmods in sigmodr to a library
Diffstat (limited to 'sigmodr/models/BaseModel.cpp')
| -rw-r--r-- | sigmodr/models/BaseModel.cpp | 141 |
1 files changed, 0 insertions, 141 deletions
diff --git a/sigmodr/models/BaseModel.cpp b/sigmodr/models/BaseModel.cpp deleted file mode 100644 index 643e62d3..00000000 --- a/sigmodr/models/BaseModel.cpp +++ /dev/null @@ -1,141 +0,0 @@ -/* - * Copyright 2008-2009 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/>. - */ - -// Header include -#include "BaseModel.h" - -// Sigmod includes -#include "../../sigmod/Object.h" - -// KDE includes -#include <KApplication> -#include <KMessageBox> -#include <KUrl> -#include <KIO/NetAccess> - -// Qt includes -#include <QtCore/QFile> -#include <QtXml/QDomDocument> - -const int Sigmodr::BaseModel::TypeRole = Qt::UserRole; -const int Sigmodr::BaseModel::DropAcceptRole = Qt::UserRole + 1; -const int Sigmodr::BaseModel::XmlRole = Qt::UserRole + 2; -const int Sigmodr::BaseModel::WidgetRole = Qt::UserRole + 3; -const int Sigmodr::BaseModel::ContextMenuRole = Qt::UserRole + 4; - -Sigmodr::BaseModel::BaseModel(BaseModel* parent, Sigmod::Object* object, const QString& name) : - m_parent(parent), - m_object(object), - m_name(name) -{ -} - -Sigmodr::BaseModel::~BaseModel() -{ -} - -QVariant Sigmodr::BaseModel::data(int role) const -{ - if (role == Sigmodr::BaseModel::TypeRole) - return type(); - else if (role == Sigmodr::BaseModel::DropAcceptRole) - return types(); - return QVariant(); -} - -Sigmodr::BaseModel* Sigmodr::BaseModel::parent() -{ - return m_parent; -} - -int Sigmodr::BaseModel::indexNumber() const -{ - if (m_parent) - return m_parent->findChild(const_cast<BaseModel*>(this)); - return -1; -} - -QString Sigmodr::BaseModel::type() const -{ - return ""; -} - -const Sigmod::Object* Sigmodr::BaseModel::object() const -{ - return m_object; -} - -bool Sigmodr::BaseModel::loadFromData(const QString& data, QDomDocument* xml) const -{ - bool loaded = false; - QString error; - int line; - int column; - KUrl url(data); - if (url.isValid()) - { - QString path; - const bool local = url.isLocalFile(); - if (local) - path = url.path(); - else - { - if (!KIO::NetAccess::download(url, path, KApplication::kApplication()->activeWindow())) - { - KMessageBox::error(KApplication::kApplication()->activeWindow(), KIO::NetAccess::lastErrorString(), "KIO Error"); - return false; - } - } - QFile file(path); - if (file.open(QIODevice::ReadOnly)) - { - if (!xml->setContent(&file, &error, &line, &column)) - { - KMessageBox::error(KApplication::kApplication()->activeWindow(), QString("%1 at line %2, column %3").arg(error).arg(line).arg(column), "XML Error"); - loaded = false; - } - } - else - { - KMessageBox::error(KApplication::kApplication()->activeWindow(), file.errorString(), "File Error"); - loaded = false; - } - file.close(); - if (!local) - KIO::NetAccess::removeTempFile(path); - } - else if (xml->setContent(data, &error, &line, &column)) - loaded = true; - else - KMessageBox::error(KApplication::kApplication()->activeWindow(), QString("%1 at line %2, column %3").arg(error).arg(line).arg(column), "XML Error"); - return loaded; -} - -void Sigmodr::BaseModel::childRowChanged(const int row) -{ - QList<int> indexes; - indexes << indexNumber() << row; - emit(rowsChanged(indexes)); -} - -void Sigmodr::BaseModel::childRowsChanged(const QList<int>& rows) -{ - QList<int> indexes; - indexes << indexNumber() << rows; - emit(rowsChanged(indexes)); -} - |
