# # # patch "guitone/src/model/Select.cpp" # from [167da2be5f3a07ef973f2e3b9592fb4f6aa01c93] # to [c385f3d183a9d4530d59eb290f9e235dcd66afdf] # # patch "guitone/src/model/Select.h" # from [a0102a15bb222d70d94da1c3dcc2947ce8c83be4] # to [4cd0672f6e74967d8262447329783fc812682110] # # patch "guitone/src/model/Toposort.cpp" # from [e543b413709dec4578f95bf61b3a15784586613b] # to [7f548bfe49275afd3ffb52d16a1d2e5bb4f90615] # # patch "guitone/src/model/Toposort.h" # from [0293c8830b9190570f4efc069a915c68c90bdd22] # to [5b7f580568b3c8aa58a2ae4ea02105b8a22c3f35] # # patch "guitone/src/monotone/Monotone.cpp" # from [50f518b7e88f7406f1c8b19978fe380c051362f6] # to [34e58702be2f72aadce3fb1bf40a4af6a4d595ba] # # patch "guitone/src/view/dialogs/SwitchWorkspaceRevision.cpp" # from [570cf04bb15e85496ba5f94ba2fb53fe2bc224c8] # to [916581c5b85ce84e225dc24554ec6b2bc421af28] # # patch "guitone/src/view/dialogs/SwitchWorkspaceRevision.h" # from [9b8c093dc71843dd9af1fcc2eafb073119515d2a] # to [8e9ba9782eaafa5700552d409af2a6a7db0f9bb4] # ============================================================ --- guitone/src/model/Select.cpp 167da2be5f3a07ef973f2e3b9592fb4f6aa01c93 +++ guitone/src/model/Select.cpp c385f3d183a9d4530d59eb290f9e235dcd66afdf @@ -28,9 +28,7 @@ Select::Select(QObject *parent) : QAbstractItemModel(parent) { selRevisions = new RevisionList(); - sorted = false; - toposort = 0; - mtnDelegate = new MonotoneDelegate(this); + mtnDelegate = new MonotoneDelegate(this); } Select::~Select() @@ -41,13 +39,11 @@ Select::~Select() delete selRevisions; } - if (toposort) delete toposort; - delete mtnDelegate; + delete mtnDelegate; } -bool Select::readSelection(const QString & selector, bool sorted) +bool Select::readSelection(const QString & selector) { - Select::sorted = sorted; // clear current attributes list selRevisions->clear(); // reset the view @@ -72,41 +68,19 @@ bool Select::handleError(int errCode) return true; } -void Select::dataReady() -{ - selRevisions = new RevisionList(toposort->getAutomateData().split('\n')); - - // reset the view - reset(); - - // signal that we've finished (whoever listens to that) - emit selectionRead(); -} - void Select::parseOutput() { if (selRevisions > 0) { selRevisions->clear(); delete selRevisions; - selRevisions = 0; selRevisions = new RevisionList(AutomateCommand::data.split('\n')); // reset the view reset(); } - if(sorted) - { - if(!toposort) toposort = new Toposort(this); - connect(toposort, SIGNAL(sortedSelectionReady()), this, SLOT(dataReady())); - QStringList data = AutomateCommand::data.split("\n"); - data.removeLast(); - toposort->sortSelection(data); - } - else - { - // signal that we've finished (whoever listens to that) - emit selectionRead(); - } + + // signal that we've finished (whoever listens to that) + emit selectionRead(); } int Select::columnCount(const QModelIndex &parent) const @@ -168,8 +142,9 @@ QModelIndex Select::index(int row, int c { return QModelIndex(); } - //QString *rev = new QString(selRevisions->at(row)); - return createIndex(row, column, 0); + + QString *rev = new QString(selRevisions->at(row)); + return createIndex(row, column, rev); } QModelIndex Select::parent(const QModelIndex& index) const ============================================================ --- guitone/src/model/Select.h a0102a15bb222d70d94da1c3dcc2947ce8c83be4 +++ guitone/src/model/Select.h 4cd0672f6e74967d8262447329783fc812682110 @@ -27,7 +27,6 @@ typedef QStringList RevisionList; #include typedef QStringList RevisionList; -class Toposort; class Select : public QAbstractItemModel, public AutomateCommand { @@ -46,7 +45,7 @@ public slots: int columnCount(const QModelIndex&) const; public slots: - bool readSelection(const QString &, bool sorted = false); + bool readSelection(const QString &); signals: void selectionRead(); @@ -57,11 +56,7 @@ private: bool handleError(int); RevisionList *selRevisions; bool sorted; - Toposort * toposort; MonotoneDelegate * mtnDelegate; - -private slots: - void dataReady(); }; #endif ============================================================ --- guitone/src/model/Toposort.cpp e543b413709dec4578f95bf61b3a15784586613b +++ guitone/src/model/Toposort.cpp 7f548bfe49275afd3ffb52d16a1d2e5bb4f90615 @@ -19,135 +19,105 @@ ***************************************************************************/ #include "Toposort.h" -#include "../monotone/Monotone.h" +#include "Monotone.h" -#include +#include +#include -Toposort::Toposort(QObject *parent) : QAbstractItemModel(parent) +Toposort::Toposort(QObject *parent) : QSortFilterProxyModel(parent) { - selRevisions = new RevisionList(); - mtnDelegate = new MonotoneDelegate(this); + ordRevisions = new RevisionMap(); + mtnDelegate = new MonotoneDelegate(this); + showRows = false; + + connect( + this, SIGNAL(modelReset()), + this, SLOT(sortModel()) + ); } Toposort::~Toposort() { - if (selRevisions) + if (ordRevisions) { - selRevisions->clear(); - delete selRevisions; + ordRevisions->clear(); + delete ordRevisions; } delete mtnDelegate; } -bool Toposort::sortSelection(const QStringList &selection) +bool Toposort::lessThan(const QModelIndex &left, const QModelIndex &right) { - // clear current attributes list - selRevisions->clear(); - // reset the view - reset(); + QString leftRev = sourceModel()->data(left).toString(); + QString rightRev = sourceModel()->data(right).toString(); - QStringList cmd; - cmd.append("toposort"); - //QStringList args; - cmd << selection; - - return mtnDelegate->triggerCommand(cmd); -} - -bool Toposort::handleError(int errCode) -{ - // 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 the data is not sortable; - emit sortingImpossible(AutomateCommand::data); - - return true; -} - -void Toposort::parseOutput() -{ - if (selRevisions > 0) + if (!ordRevisions->contains(leftRev) || !ordRevisions->contains(leftRev)) { - selRevisions->clear(); - delete selRevisions; + qDebug("Toposort::lessThan: one or both revisions not found,"); + return false; } - selRevisions = new RevisionList(AutomateCommand::data.split("\n")); - - // reset the view - reset(); - - // signal that we've finished (whoever listens to that) - emit sortedSelectionReady(); + return ordRevisions->value(leftRev) < ordRevisions->value(rightRev); } -int Toposort::columnCount(const QModelIndex &parent) const +bool Toposort::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const { - return 1; + return showRows; } -QVariant Toposort::data(const QModelIndex &index, int role) const +void Toposort::sortModel() { - if (!index.isValid()) - { - return QVariant(); - } + showRows = false; + ordRevisions->clear(); - if (role == Qt::FontRole) + int row = 0; + QModelIndex current = sourceModel()->index(row,0); + if (!current.isValid()) { - QFont font; - font.setStyleHint(QFont::Courier); - font.setFamily("Courier"); - return QVariant(font); + qDebug("Toposort::sortModel: no items found in source model"); + return; } + qDebug("building rev list"); - if (role == Qt::DisplayRole) - { - int row = index.row(); - if (row >= selRevisions->size()) return QVariant(); - return QVariant(selRevisions->at(row)); + QStringList revs; + do + { + QString rev = current.data().toString(); + // skip everything what does not look like a revision id + if (rev.size() == 40) + { + revs.append(rev); + } + current = current.sibling(++row, 0); + if (!current.isValid()) break; } + while (true); - return QVariant(); -} - -Qt::ItemFlags Toposort::flags(const QModelIndex &index) const -{ - if (index.isValid()) + qDebug("calling toposort"); + QStringList cmd; + cmd.append("toposort"); + cmd << revs; + + if (!mtnDelegate->triggerCommand(cmd)) { - return Qt::ItemIsEnabled | Qt::ItemIsSelectable; + qDebug("Toposort::sortModel: cannot trigger toposort command"); } - return 0; } -QVariant Toposort::headerData(int section, Qt::Orientation orientation, int role) const -{ - if (orientation == Qt::Horizontal && role == Qt::DisplayRole) - { - return QVariant(tr("Revision ID")); - } - return QVariant(); -} - -int Toposort::rowCount(const QModelIndex& parent) const -{ - return selRevisions->size(); -} - -QModelIndex Toposort::index(int row, int column, const QModelIndex& parent) const -{ - if (!hasIndex(row, column, parent)) +void Toposort::parseOutput() +{ + QStringList sortedRevs(AutomateCommand::data.split("\n")); + for (int i=0, j=sortedRevs.size(); iinsert(sortedRevs.at(i), i); } - //QString *rev = new QString(selRevisions->at(row)); - return createIndex(row, column, 0); + + showRows = true; + reset(); + + qDebug("Toposort:parseOutput: revisions sorted"); + + // signal that we've finished (whoever listens to that) + emit sortingFinished(); } -QModelIndex Toposort::parent(const QModelIndex& index) const -{ - return QModelIndex(); -} - ============================================================ --- guitone/src/model/Toposort.h 0293c8830b9190570f4efc069a915c68c90bdd22 +++ guitone/src/model/Toposort.h 5b7f580568b3c8aa58a2ae4ea02105b8a22c3f35 @@ -24,39 +24,32 @@ #include "AutomateCommand.h" #include "MonotoneDelegate.h" -#include -#include +#include +#include -typedef QStringList RevisionList; +typedef QMap RevisionMap; -class Toposort : public QAbstractItemModel, public AutomateCommand +class Toposort : public QSortFilterProxyModel, public AutomateCommand { Q_OBJECT public: Toposort(QObject*); virtual ~Toposort(); - - // 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; -public slots: - bool sortSelection(const QStringList&); - signals: - void sortedSelectionReady(); - void sortingImpossible(QString); - + void sortingFinished(); + private: void parseOutput(); - bool handleError(int); - RevisionList * selRevisions; + bool lessThan(const QModelIndex &, const QModelIndex &); + bool filterAcceptsRow(int, const QModelIndex &) const; + + RevisionMap * ordRevisions; MonotoneDelegate * mtnDelegate; + bool showRows; + +private slots: + void sortModel(); }; #endif //TOPOSOT_H ============================================================ --- guitone/src/monotone/Monotone.cpp 50f518b7e88f7406f1c8b19978fe380c051362f6 +++ guitone/src/monotone/Monotone.cpp 34e58702be2f72aadce3fb1bf40a4af6a4d595ba @@ -402,7 +402,7 @@ void Monotone::writeStdin(const QStringL Q_ASSERT(command.size() > 0); - commandLine += "l"; + commandLine += "l"; for (int i=0, c=command.size(); isetSourceModel(selectorModel); + // set initial completer setCompleter(0); // assign the models to the views - revisionList->setModel(selectorModel); + revisionList->setModel(sortModel); certList->setModel(certsModel); // some tweaks @@ -125,7 +129,7 @@ void SwitchWorkspaceRevision::triggerRev selector.append(selectorValue->text()); - if (!selectorModel->readSelection(selector, true)) + if (!selectorModel->readSelection(selector)) { QMessageBox::warning( this, ============================================================ --- guitone/src/view/dialogs/SwitchWorkspaceRevision.h 9b8c093dc71843dd9af1fcc2eafb073119515d2a +++ guitone/src/view/dialogs/SwitchWorkspaceRevision.h 8e9ba9782eaafa5700552d409af2a6a7db0f9bb4 @@ -24,6 +24,7 @@ #include "Dialog.h" #include "ui_switch_workspace.h" #include "Select.h" +#include "Toposort.h" #include "Certs.h" #include "Branches.h" #include "Tags.h" @@ -40,11 +41,12 @@ private: ~SwitchWorkspaceRevision(); private: - Select * selectorModel; - Certs * certsModel; - Branches * branchesModel; - Tags * tagsModel; - Keys * keysModel; + Select * selectorModel; + Toposort * sortModel; + Certs * certsModel; + Branches * branchesModel; + Tags * tagsModel; + Keys * keysModel; QCompleter * selectorCompleter; private slots: