# # # patch "src/model/Select.cpp" # from [677dba9de437975a3ff1c1cb3de567fececa6da0] # to [530e813a342d5a623f5318b8e7a75fd02443f491] # # patch "src/model/Select.h" # from [4cd0672f6e74967d8262447329783fc812682110] # to [b0894a2dde22e024f8db52fea72fcc918234b6e1] # ============================================================ --- src/model/Select.cpp 677dba9de437975a3ff1c1cb3de567fececa6da0 +++ src/model/Select.cpp 530e813a342d5a623f5318b8e7a75fd02443f491 @@ -19,83 +19,63 @@ ***************************************************************************/ #include "Select.h" -#include "Toposort.h" -#include "Monotone.h" #include -Select::Select(QObject *parent) - : QAbstractItemModel(parent) +Select::Select(QObject * parent, const QString & db) + : QAbstractItemModel(parent), AutomateCommand(db) { selRevisions = new RevisionList(); - mtnDelegate = new MonotoneDelegate(this); } Select::~Select() { - if (selRevisions) - { - selRevisions->clear(); - delete selRevisions; - } - - delete mtnDelegate; + delete selRevisions; } -bool Select::readSelection(const QString & selector) +void Select::readSelection(const QString & selector) { - // clear current attributes list + // clear current attributes list selRevisions->clear(); // reset the view reset(); - QStringList cmd; - cmd.append("select"); - cmd.append(selector); - - return mtnDelegate->triggerCommand(cmd); + MonotoneTask task(QStringList() << "select" << selector); + AutomateCommand::enqueueTask(task); } -bool Select::handleError(int errCode) +void Select::processTaskResult(const MonotoneTask & task) { - // we can't handle syntax and other basic errors - if (errCode == 1) return false; - // since there is no other indication we assume that errCode 2 // is always fired if a invalid selector syntax has been given - emit invalidSelection(AutomateCommand::data); - - return true; -} - -void Select::parseOutput() -{ - if (selRevisions > 0) - { - selRevisions->clear(); - delete selRevisions; - selRevisions = new RevisionList( - AutomateCommand::data.split('\n', QString::SkipEmptyParts) - ); - // reset the view - reset(); - } - + if (task.getReturnCode() == 2) + { + emit invalidSelection(task.getOutputUtf8()); + return; + } + + delete selRevisions; + selRevisions = new RevisionList( + task.getOutputUtf8().split('\n', QString::SkipEmptyParts) + ); + // reset the view + reset(); // signal that we've finished (whoever listens to that) emit selectionRead(); } -int Select::columnCount(const QModelIndex &parent) const +int Select::columnCount(const QModelIndex & parent) const { - return 1; + Q_UNUSED(parent); + return 1; } -QVariant Select::data(const QModelIndex &index, int role) const +QVariant Select::data(const QModelIndex & index, int role) const { - if (!index.isValid()) - { - return QVariant(); - } + if (!index.isValid()) + { + return QVariant(); + } if (role == Qt::FontRole) { @@ -106,13 +86,13 @@ QVariant Select::data(const QModelIndex } 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 Select::flags(const QModelIndex &index) const @@ -126,19 +106,21 @@ QVariant Select::headerData(int section, QVariant Select::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 Select::rowCount(const QModelIndex& parent) const +int Select::rowCount(const QModelIndex & parent) const { - return selRevisions->size(); + Q_UNUSED(parent); + return selRevisions->size(); } -QModelIndex Select::index(int row, int column, const QModelIndex& parent) const +QModelIndex Select::index(int row, int column, const QModelIndex & parent) const { if (!hasIndex(row, column, parent)) { @@ -148,8 +130,9 @@ QModelIndex Select::index(int row, int c return createIndex(row, column, 0); } -QModelIndex Select::parent(const QModelIndex& index) const +QModelIndex Select::parent(const QModelIndex & index) const { + Q_UNUSED(index); return QModelIndex(); } ============================================================ --- src/model/Select.h 4cd0672f6e74967d8262447329783fc812682110 +++ src/model/Select.h b0894a2dde22e024f8db52fea72fcc918234b6e1 @@ -22,7 +22,6 @@ #define SELECT_H #include "AutomateCommand.h" -#include "MonotoneDelegate.h" #include @@ -32,31 +31,31 @@ public: { Q_OBJECT public: - Select(QObject*); + Select(QObject *, const QString &); virtual ~Select(); // 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 readSelection(const QString &); + void readSelection(const QString &); signals: void selectionRead(); void invalidSelection(QString); private: - void parseOutput(); - bool handleError(int); - RevisionList *selRevisions; - bool sorted; - MonotoneDelegate * mtnDelegate; + void processTaskResult(const MonotoneTask &); + + RevisionList * selRevisions; + bool sorted; }; #endif +