# # # patch "src/model/Ancestors.cpp" # from [81d57af07ba418801dbf929278e71d5a8bf4262c] # to [39d7b349ea3738d08ccd4a37e70c830876d02ce9] # # patch "src/model/Ancestors.h" # from [9ab08563cff3421ca54a529d985aff8f475f6105] # to [8588c2bcb2731b1202362baa3a8038198becbde9] # ============================================================ --- src/model/Ancestors.cpp 81d57af07ba418801dbf929278e71d5a8bf4262c +++ src/model/Ancestors.cpp 39d7b349ea3738d08ccd4a37e70c830876d02ce9 @@ -1,6 +1,6 @@ /*************************************************************************** - * Copyright (C) 2006 by Jean-Louis Fuchs * - * address@hidden * + * Copyright (C) 2006 by Jean-Louis Fuchs * + * 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 * @@ -19,83 +19,77 @@ ***************************************************************************/ #include "Ancestors.h" -#include "Toposort.h" #include "Monotone.h" #include -Ancestors::Ancestors(QObject *parent) - : QAbstractItemModel(parent) +Ancestors::Ancestors(QObject * parent, const QString & db) + : QAbstractItemModel(parent), AutomateCommand(db) { selRevisions = new RevisionList(); - mtnDelegate = new MonotoneDelegate(this); } Ancestors::~Ancestors() { if (selRevisions) - { - selRevisions->clear(); - delete selRevisions; - } - - delete mtnDelegate; + { + selRevisions->clear(); + delete selRevisions; + } } -bool Ancestors::readAncestors(const QStringList & parents) +void Ancestors::readAncestors(const QStringList & parents) { - // clear current attributes list + // clear current attributes list selRevisions->clear(); // reset the view reset(); - QStringList cmd; - cmd.append("ancestors"); - cmd << parents; - - return mtnDelegate->triggerCommand(cmd); + MonotoneTask task(QStringList() << "ancestors" << parents); + AutomateCommand::enqueueTask(task); } -bool Ancestors::handleError(int errCode) +void Ancestors::processTaskResult(const MonotoneTask & task) { - // we can't handle syntax and other basic errors - if (errCode == 1) return false; + if (task.getReturnCode() == 2) + { + emit invalidAncestor(task.getOutputUtf8()); + } - // since there is no other indication we assume that errCode 2 - // is always fired if a invalid Ancestor syntax has been given - emit invalidAncestor(AutomateCommand::data); - - return true; -} - -void Ancestors::parseOutput() -{ - if (selRevisions > 0) - { - selRevisions->clear(); - delete selRevisions; - selRevisions = new RevisionList( - AutomateCommand::data.split('\n', QString::SkipEmptyParts) + if (task.getReturnCode() != 0) + { + C(QString("Command returned with a non-zero return code (%1)") + .arg(task.getOutputUtf8())); + return; + } + + if (selRevisions > 0) + { + selRevisions->clear(); + delete selRevisions; + selRevisions = new RevisionList( + task.getOutputUtf8().split('\n', QString::SkipEmptyParts) ); - // reset the view - reset(); - } + // reset the view + reset(); + } // signal that we've finished (whoever listens to that) - emit AncestorsRead(); + emit ancestorsRead(); } -int Ancestors::columnCount(const QModelIndex &parent) const +int Ancestors::columnCount(const QModelIndex & parent) const { - return 1; + Q_UNUSED(parent); + return 1; } -QVariant Ancestors::data(const QModelIndex &index, int role) const +QVariant Ancestors::data(const QModelIndex & index, int role) const { - if (!index.isValid()) - { - return QVariant(); - } + if (!index.isValid()) + { + return QVariant(); + } if (role == Qt::FontRole) { @@ -106,16 +100,16 @@ QVariant Ancestors::data(const QModelInd } if (role == Qt::DisplayRole) - { + { int row = index.row(); if (row >= selRevisions->size()) return QVariant(); return QVariant(selRevisions->at(row)); } - return QVariant(); + return QVariant(); } -Qt::ItemFlags Ancestors::flags(const QModelIndex &index) const +Qt::ItemFlags Ancestors::flags(const QModelIndex & index) const { if (index.isValid()) { @@ -126,19 +120,21 @@ QVariant Ancestors::headerData(int secti QVariant Ancestors::headerData(int section, Qt::Orientation orientation, int role) const { - if (orientation == Qt::Horizontal && role == Qt::DisplayRole) - { + Q_UNUSED(section); + if (orientation == Qt::Horizontal && role == Qt::DisplayRole) + { return QVariant(tr("Revision ID")); } return QVariant(); } -int Ancestors::rowCount(const QModelIndex& parent) const +int Ancestors::rowCount(const QModelIndex & parent) const { - return selRevisions->size(); + Q_UNUSED(parent); + return selRevisions->size(); } -QModelIndex Ancestors::index(int row, int column, const QModelIndex& parent) const +QModelIndex Ancestors::index(int row, int column, const QModelIndex & parent) const { if (!hasIndex(row, column, parent)) { @@ -148,8 +144,9 @@ QModelIndex Ancestors::index(int row, in return createIndex(row, column, 0); } -QModelIndex Ancestors::parent(const QModelIndex& index) const +QModelIndex Ancestors::parent(const QModelIndex & index) const { + Q_UNUSED(index); return QModelIndex(); } ============================================================ --- src/model/Ancestors.h 9ab08563cff3421ca54a529d985aff8f475f6105 +++ src/model/Ancestors.h 8588c2bcb2731b1202362baa3a8038198becbde9 @@ -22,7 +22,6 @@ #define ANCESTORS_H #include "AutomateCommand.h" -#include "MonotoneDelegate.h" #include @@ -32,31 +31,29 @@ public: { Q_OBJECT public: - Ancestors(QObject*); + Ancestors(QObject *, const QString &); virtual ~Ancestors(); // needed Qt Model methods - QVariant data(const QModelIndex&, int) const; - Qt::ItemFlags flags(const QModelIndex&) const; + 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; + 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 readAncestors(const QStringList &); + void readAncestors(const QStringList &); signals: - void AncestorsRead(); + void ancestorsRead(); void invalidAncestor(QString); private: - void parseOutput(); - bool handleError(int); - RevisionList *selRevisions; - bool sorted; - MonotoneDelegate * mtnDelegate; + void processTaskResult(const MonotoneTask &); + RevisionList * selRevisions; + bool sorted; }; #endif