diff options
| author | Ben Boeckel <MathStuf@gmail.com> | 2008-08-26 18:23:31 +0000 |
|---|---|---|
| committer | Ben Boeckel <MathStuf@gmail.com> | 2008-08-26 18:23:31 +0000 |
| commit | 940e5d4b55bbd1261bf0ccb3a915b79cf2a240c8 (patch) | |
| tree | 68d3ebfe3f0763d4dbcd7e642b065f6cde73fb8c /pokemodr/ValidationDialog.cpp | |
| parent | aa5ecfc2ac5c1b9c250159d01f1e83799e88eb45 (diff) | |
| download | sigen-940e5d4b55bbd1261bf0ccb3a915b79cf2a240c8.tar.gz sigen-940e5d4b55bbd1261bf0ccb3a915b79cf2a240c8.tar.xz sigen-940e5d4b55bbd1261bf0ccb3a915b79cf2a240c8.zip | |
[FIX] Fixed some minor typos
[FIX] Abstracted validation out to ValidationDialog
[FIX] Added stat and Direction getters for Pokemod
git-svn-id: https://pokegen.svn.sourceforge.net/svnroot/pokegen/trunk@244 6ecfd1a5-f3ed-3746-8530-beee90d26b22
Diffstat (limited to 'pokemodr/ValidationDialog.cpp')
| -rw-r--r-- | pokemodr/ValidationDialog.cpp | 107 |
1 files changed, 107 insertions, 0 deletions
diff --git a/pokemodr/ValidationDialog.cpp b/pokemodr/ValidationDialog.cpp new file mode 100644 index 00000000..a9310c7e --- /dev/null +++ b/pokemodr/ValidationDialog.cpp @@ -0,0 +1,107 @@ +/* + * 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/>. + */ + +// Header include +#include "ValidationDialog.h" + +// Pokemod includes +#include "../pokemod/Object.h" + +// Qt includes +#include <QtGui/QLabel> +#include <QtGui/QTreeWidget> +#include <QtGui/QVBoxLayout> + +// KDE includes +#include <KColorScheme> +#include <KMessageBox> +#include <KProgressDialog> + +Pokemodr::ValidationDialog::ValidationDialog(Pokemod::Object* object, QWidget* parent) : + QWidget(parent), + m_valTree(new QTreeWidget), + m_errors(0), + m_warnings(0) +{ + KProgressDialog* progress = new KProgressDialog(this, "Validating", "Please wait"); + progress->progressBar()->setRange(0, 0); + progress->setAllowCancel(false); + progress->setModal(true); + progress->show(); + m_valTree->setHeaderHidden(true); + m_parents.push(ObjectErrorCount(m_valTree->invisibleRootItem(), 0)); + connect(object, SIGNAL(valMessage(QString)), this, SLOT(addMessage(QString))); + connect(object, SIGNAL(valWarning(QString)), this, SLOT(addWarning(QString))); + connect(object, SIGNAL(valError(QString)), this, SLOT(addError(QString))); + object->validate(); + delete progress; + if (m_parents.top().second) + { + m_valTree->addTopLevelItem(m_parents.top().first); + KDialog* dialog = new KDialog(this); + dialog->setCaption("Validation Messages"); + dialog->setButtons(KDialog::Ok); + QWidget* widget = new QWidget(this); + QVBoxLayout* layout = new QVBoxLayout(widget); + layout->addWidget(new QLabel(QString("Warnings: %1\nErrors: %2").arg(m_warnings).arg(m_errors), widget)); + layout->addWidget(m_valTree); + dialog->setMainWidget(widget); + dialog->exec(); + delete dialog; + } + else + KMessageBox::information(this, "No messages", "Validation"); + disconnect(object, SIGNAL(valMessage(QString)), this, SLOT(addMessage(QString))); + disconnect(object, SIGNAL(valWarning(QString)), this, SLOT(addWarning(QString))); + disconnect(object, SIGNAL(valError(QString)), this, SLOT(addError(QString))); +} + +void Pokemodr::ValidationDialog::insertMessage(const QString& msg, const QBrush& brush) +{ + ++m_parents.top().second; + QTreeWidgetItem* item = new QTreeWidgetItem(m_parents.top().first, QStringList(msg)); + item->setBackground(0, brush); +} + +void Pokemodr::ValidationDialog::addMessage(const QString& msg) +{ + if (msg.startsWith("++")) + m_parents.push(ObjectErrorCount(new QTreeWidgetItem(QStringList(msg.mid(2))), 0)); + else if (msg.startsWith("--")) + { + ObjectErrorCount count = m_parents.pop(); + if (count.second) + { + m_parents.top().first->addChild(count.first); + ++m_parents.top().second; + } + } + else + insertMessage(msg, KStatefulBrush(KColorScheme::View, KColorScheme::PositiveBackground).brush(QPalette::Normal)); +} + +void Pokemodr::ValidationDialog::addError(const QString& msg) +{ + insertMessage(msg, KStatefulBrush(KColorScheme::View, KColorScheme::NegativeBackground).brush(QPalette::Normal)); + ++m_errors; +} + +void Pokemodr::ValidationDialog::addWarning(const QString& msg) +{ + insertMessage(msg, KStatefulBrush(KColorScheme::View, KColorScheme::NeutralBackground).brush(QPalette::Normal)); + ++m_warnings; +} |
