# # # patch "src/model/Branches.cpp" # from [728808cda07a8491fa0f3f6d7c32c64e6a1dde06] # to [ae0c27ed7f2086e4990ffaa2ad0d22462586e890] # # patch "src/model/Branches.h" # from [4dc8ac62813551f8ce888bb840ce1676e80aa849] # to [731c2a00b2e67f3f5045f6c4a641a5be87358276] # ============================================================ --- src/model/Branches.cpp 728808cda07a8491fa0f3f6d7c32c64e6a1dde06 +++ src/model/Branches.cpp ae0c27ed7f2086e4990ffaa2ad0d22462586e890 @@ -19,54 +19,55 @@ ***************************************************************************/ #include "Branches.h" -#include "Monotone.h" -Branches::Branches(QObject * parent, bool display_tree) - : QAbstractItemModel(parent), tree(display_tree) +Branches::Branches(QObject * parent, const QString & db, bool display_tree) + : QAbstractItemModel(parent), AutomateCommand(db), tree(display_tree) { builder = 0; - mtnDelegate = new MonotoneDelegate(this); } Branches::~Branches() { if(builder) delete builder; - delete mtnDelegate; } -bool Branches::readBranches() +void Branches::readBranches() { branches.clear(); reset(); - QStringList cmd; - cmd << "branches"; - - return mtnDelegate->triggerCommand(cmd); + MonotoneTask task(QStringList() << "branches"); + AutomateCommand::enqueueTask(task); } -void Branches::parseOutput() +void Branches::processTaskResult(const MonotoneTask & task) { + if (task.getReturnCode() != 0) + { + C(QString("Command returned with a non-zero return code (%1)") + .arg(task.getOutputUtf8())); + return; + } + branches.setHorizontalHeaderItem(0, new QStandardItem(tr("Branches"))); if(tree) { - QStandardItem *root = new QStandardItem("*"); + QStandardItem * root = new QStandardItem("*"); root->setData("*", Qt::ToolTipRole); branches.appendRow(root); builder = new TreeBuilder(root, this); - builder->addList(AutomateCommand::data); + builder->addList(task.getOutputUtf8()); } else { - QStringList branchList = AutomateCommand::data.split("\n"); - - QStringListIterator iterator(branchList); + QStringList branchList = task.getOutputUtf8().split("\n"); + QStringListIterator iterator(branchList); while(iterator.hasNext()) { QString it = iterator.next(); - QStandardItem *item = new QStandardItem(it); + QStandardItem * item = new QStandardItem(it); item->setData(it, Qt::ToolTipRole); branches.appendRow(item); } @@ -76,75 +77,75 @@ void Branches::parseOutput() emit branchesRead(); } -int Branches::columnCount(const QModelIndex &parent) const +int Branches::columnCount(const QModelIndex & parent) const { QStandardItem * item = branchFromIndex(parent); - if(item) + if (item) + { return item->columnCount(); - else - return branches.columnCount(); + } + return branches.columnCount(); } -QVariant Branches::data(const QModelIndex &index, int role) const +QVariant Branches::data(const QModelIndex & index, int role) const { QStandardItem * item = branchFromIndex(index); - if(item) + if (item) + { return item->data(role); - else - return QVariant(); + } + return QVariant(); } -//FIXME: Do we need this? - -/*Qt::ItemFlags Branches::flags(const QModelIndex &index) const -{ - return branchFromIndex(index)->flags(); -}*/ - QVariant Branches::headerData(int section, Qt::Orientation orientation, int role) const { return branches.headerData(section, orientation, role); } -int Branches::rowCount(const QModelIndex& parent) const +int Branches::rowCount(const QModelIndex & parent) const { QStandardItem * item = branchFromIndex(parent); - if(item) + if (item) + { return item->rowCount(); - else - return branches.rowCount(); + } + return branches.rowCount(); } -QModelIndex Branches::index(int row, int column, const QModelIndex& parent) const +QModelIndex Branches::index(int row, int column, const QModelIndex & parent) const { return createIndex(row, column, getBranchItem(row, column, parent)); } -QModelIndex Branches::parent(const QModelIndex& index) const +QModelIndex Branches::parent(const QModelIndex & index) const { QStandardItem * item = branchFromIndex(index); - if(item) + if (item) { QStandardItem * parent = item->parent(); - if(parent) + if (parent) + { return createIndex(parent->row(), parent->column(), parent); - } - + } + } return QModelIndex(); } -void * Branches::getBranchItem(int row, int column, const QModelIndex& index) const +QStandardItem * Branches::getBranchItem(int row, int column, const QModelIndex & index) const { - if(index.isValid()) - return ((QStandardItem *) index.internalPointer())->child(row, column); - else - return branches.item(row, column); + if (index.isValid()) + { + return static_cast(index.internalPointer())->child(row, column); + } + return 0; } -QStandardItem * Branches::branchFromIndex(const QModelIndex& index) const +QStandardItem * Branches::branchFromIndex(const QModelIndex & index) const { - if(index.isValid()) - return static_cast(index.internalPointer()); - else - return 0; + if (index.isValid()) + { + return static_cast(index.internalPointer()); + } + return 0; } + ============================================================ --- src/model/Branches.h 4dc8ac62813551f8ce888bb840ce1676e80aa849 +++ src/model/Branches.h 731c2a00b2e67f3f5045f6c4a641a5be87358276 @@ -1,21 +1,21 @@ /*************************************************************************** - * Copyright (C) 2006 by Thomas Keller * - * address@hidden * - * * - * 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 2 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, write to the * - * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + * Copyright (C) 2006 by Thomas Keller * + * address@hidden * + * * + * 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 2 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, write to the * + * Free Software Foundation, Inc., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ #ifndef BRANCHES_H @@ -23,41 +23,39 @@ #include "AutomateCommand.h" #include "TreeBuilder.h" -#include "MonotoneDelegate.h" #include #include class Branches : public QAbstractItemModel, public AutomateCommand { - Q_OBJECT + Q_OBJECT public: - Branches(QObject *, bool); - virtual ~Branches(); - - // needed Qt Model methods - QVariant data(const QModelIndex&, int) const; - //Qt::ItemFlags flags(const QModelIndex&) const; - QVariant headerData(int, Qt::Orientation, int) const; - QModelIndex index(int, int, const QModelIndex&) const; - QModelIndex parent(const QModelIndex&) const; - int rowCount(const QModelIndex&) const; - int columnCount(const QModelIndex&) const; + Branches(QObject *, const QString &, bool); + virtual ~Branches(); + + // needed Qt Model methods + QVariant data(const QModelIndex &, int) const; + QVariant headerData(int, Qt::Orientation, int) const; + QModelIndex index(int, int, const QModelIndex &) const; + QModelIndex parent(const QModelIndex &) const; + int rowCount(const QModelIndex &) const; + int columnCount(const QModelIndex &) const; public slots: - bool readBranches(); + void readBranches(); signals: - void branchesRead(void); + void branchesRead(void); private: - bool tree; - TreeBuilder *builder; - void parseOutput(); - QStandardItemModel branches; - void * getBranchItem(int row, int column, const QModelIndex& index) const; - QStandardItem * branchFromIndex(const QModelIndex& index) const; - MonotoneDelegate * mtnDelegate; + void processTaskResult(const MonotoneTask &); + QStandardItem * getBranchItem(int row, int column, const QModelIndex & index) const; + QStandardItem * branchFromIndex(const QModelIndex & index) const; + + bool tree; + TreeBuilder * builder; + QStandardItemModel branches; }; #endif