# # # patch "guitone/src/model/AutomateCommand.cpp" # from [ee1894776615f7ee996b752c6165acd77d673e5f] # to [afbdacade31039dcddc144c5e5b03e95f21b01cf] # # patch "guitone/src/model/AutomateCommand.h" # from [f7ded2d43c8532e573a48f191945c3adff08bcee] # to [30795a07b6521be4cdb7ac999535aad35893bd85] # # patch "guitone/src/model/Select.cpp" # from [d9a7d10977ce65d4590e7a062074e175c80a79a0] # to [6e372eb6918a2b996167b67dc11a32903b573e65] # # patch "guitone/src/model/Select.h" # from [6332af0b8e4017c7eb844747786a194ea4af312a] # to [b1bff47d082be6b1b7efd7cfed910748394661fb] # # patch "guitone/src/model/Toposort.cpp" # from [da39a3ee5e6b4b0d3255bfef95601890afd80709] # to [752a8d6e51b39ca0318307f8a99c872fcf9ab21a] # # patch "guitone/src/model/Toposort.h" # from [da39a3ee5e6b4b0d3255bfef95601890afd80709] # to [28b9bf52762df0765db10a744e4ba77ede531caf] # # patch "guitone/src/util/TreeBuilder.cpp" # from [1aca5e633d77f2b720c5ffd05acab21fcf29917a] # to [78ffc09b0c2f09a9f6235f5ce9d8cfe5f6af53f0] # # patch "guitone/src/util/TreeBuilder.h" # from [e060d7fe445bc817c3e3f80b30c2d25b9504640d] # to [2a8dc775fd704078f4ab756e99cd3ea1a2ddf850] # # patch "guitone/src/view/dialogs/SwitchWorkspaceRevision.cpp" # from [d702f2d4fdec0bc1e7b1178006d1a52dfc984c87] # to [4d173137804a19d26d741f6da0fa5a4d53f74341] # ============================================================ --- guitone/src/model/AutomateCommand.cpp ee1894776615f7ee996b752c6165acd77d673e5f +++ guitone/src/model/AutomateCommand.cpp afbdacade31039dcddc144c5e5b03e95f21b01cf @@ -30,6 +30,11 @@ AutomateCommand::~AutomateCommand() { } +const QString AutomateCommand::getAutomateData() const +{ + return AutomateCommand::data; +} + bool AutomateCommand::triggerCommand(const QStringList & cmd) { return triggerCommand(cmd, QStringList()); ============================================================ --- guitone/src/model/AutomateCommand.h f7ded2d43c8532e573a48f191945c3adff08bcee +++ guitone/src/model/AutomateCommand.h 30795a07b6521be4cdb7ac999535aad35893bd85 @@ -36,6 +36,7 @@ public: public: virtual void clearData(); + const QString getAutomateData() const; protected: // its not allowed to create objects of this type directly @@ -44,8 +45,8 @@ protected: bool triggerCommand(const QStringList &); bool triggerCommand(const QStringList &, const QStringList &); virtual bool handleError(int); + QString data; - QString data; protected slots: void commandFinished(int); ============================================================ --- guitone/src/model/Select.cpp d9a7d10977ce65d4590e7a062074e175c80a79a0 +++ guitone/src/model/Select.cpp 6e372eb6918a2b996167b67dc11a32903b573e65 @@ -19,6 +19,7 @@ ***************************************************************************/ #include "Select.h" +#include "Toposort.h" #include "../monotone/Monotone.h" #include @@ -27,17 +28,25 @@ Select::Select(QObject *parent) : AutomateCommand(parent) { selRevisions = new RevisionList(); + sorted = false; + toposort = 0; } Select::~Select() { - selRevisions->clear(); - delete selRevisions; + + if(selRevisions) + { + selRevisions->clear(); + delete selRevisions; + } + if(toposort) delete toposort; } -bool Select::readSelection(const QString & selector) +bool Select::readSelection(const QString & selector, bool sorted) { - // clear current attributes list + Select::sorted = sorted; + // clear current attributes list selRevisions->clear(); // reset the view reset(); @@ -61,21 +70,41 @@ 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 = new RevisionList(AutomateCommand::data.split("\n")); - - // reset the view - reset(); - - // signal that we've finished (whoever listens to that) - emit selectionRead(); + 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(); + } } int Select::columnCount(const QModelIndex &parent) const ============================================================ --- guitone/src/model/Select.h 6332af0b8e4017c7eb844747786a194ea4af312a +++ guitone/src/model/Select.h b1bff47d082be6b1b7efd7cfed910748394661fb @@ -24,6 +24,7 @@ typedef QStringList RevisionList; #include "AutomateCommand.h" typedef QStringList RevisionList; +class Toposort; class Select : public AutomateCommand { @@ -42,7 +43,7 @@ public slots: int columnCount(const QModelIndex&) const; public slots: - bool readSelection(const QString &); + bool readSelection(const QString &, bool sorted = false); signals: void selectionRead(); @@ -52,6 +53,11 @@ private: void parseOutput(); bool handleError(int); RevisionList *selRevisions; + bool sorted; + Toposort * toposort; + +private slots: + void dataReady(); }; #endif ============================================================ --- guitone/src/model/Toposort.cpp da39a3ee5e6b4b0d3255bfef95601890afd80709 +++ guitone/src/model/Toposort.cpp 752a8d6e51b39ca0318307f8a99c872fcf9ab21a @@ -0,0 +1,152 @@ +/*************************************************************************** + * 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 * + * 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. * + ***************************************************************************/ + +#include "Toposort.h" +#include "../monotone/Monotone.h" + +#include + +Toposort::Toposort(QObject *parent) + : AutomateCommand(parent) +{ + selRevisions = new RevisionList(); +} + +Toposort::~Toposort() +{ + if(selRevisions) + { + selRevisions->clear(); + delete selRevisions; + } +} + +bool Toposort::sortSelection(const QStringList &selection) +{ + // clear current attributes list + selRevisions->clear(); + // reset the view + reset(); + + QStringList cmd; + cmd.append("toposort"); + //QStringList args; + cmd << selection; + + return AutomateCommand::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) + { + selRevisions->clear(); + delete selRevisions; + } + + selRevisions = new RevisionList(AutomateCommand::data.split("\n")); + + // reset the view + reset(); + + // signal that we've finished (whoever listens to that) + emit sortedSelectionReady(); +} + +int Toposort::columnCount(const QModelIndex &parent) const +{ + return 1; +} + +QVariant Toposort::data(const QModelIndex &index, int role) const +{ + if (!index.isValid()) + { + return QVariant(); + } + + if (role == Qt::FontRole) + { + QFont font; + font.setStyleHint(QFont::Courier); + font.setFamily("Courier"); + return QVariant(font); + } + + if (role == Qt::DisplayRole) + { + int row = index.row(); + if (row >= selRevisions->size()) return QVariant(); + return QVariant(selRevisions->at(row)); + } + + return QVariant(); +} + +Qt::ItemFlags Toposort::flags(const QModelIndex &index) const +{ + if (index.isValid()) + { + return Qt::ItemIsEnabled | Qt::ItemIsSelectable; + } + 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)) + { + return QModelIndex(); + } + //QString *rev = new QString(selRevisions->at(row)); + return createIndex(row, column, 0); +} + +QModelIndex Toposort::parent(const QModelIndex& index) const +{ + return QModelIndex(); +} + ============================================================ --- guitone/src/model/Toposort.h da39a3ee5e6b4b0d3255bfef95601890afd80709 +++ guitone/src/model/Toposort.h 28b9bf52762df0765db10a744e4ba77ede531caf @@ -0,0 +1,58 @@ +/*************************************************************************** + * 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 * + * 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 TOPOSOT_H +#define TOPOSOT_H + +#include "AutomateCommand.h" +#include + +typedef QStringList RevisionList; + +class Toposort : 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); + +private: + void parseOutput(); + bool handleError(int); + RevisionList *selRevisions; +}; + +#endif //TOPOSOT_H ============================================================ --- guitone/src/util/TreeBuilder.cpp 1aca5e633d77f2b720c5ffd05acab21fcf29917a +++ guitone/src/util/TreeBuilder.cpp 78ffc09b0c2f09a9f6235f5ce9d8cfe5f6af53f0 @@ -26,7 +26,7 @@ TreeBuilder::TreeBuilder(QStandardItem * TreeBuilder::TreeBuilder(QStandardItem *root, QObject *parent) : QObject(parent) { TreeBuilder::root = root; - dot = '.'; + sep = '.'; } QStandardItem* TreeBuilder::add(const QString &branch) @@ -42,7 +42,7 @@ void TreeBuilder::addData(QStandardItem QString branch; QStandardItem* item = child; QString text = child->data().toString(); - if(text.right(1) == ".") + if(text.right(1) == QString(sep)) text = text.left(text.length() - 1) + "*"; child->setText(text); @@ -52,7 +52,7 @@ void TreeBuilder::addData(QStandardItem item = item->parent(); } - if(branch.right(1) == ".") + if(branch.right(1) == QString(sep)) branch = branch.left(branch.length() - 1) + "*"; child->setData(branch, Qt::ToolTipRole); } @@ -125,9 +125,9 @@ int TreeBuilder::overlap(const QString & int max = qMax(a.length(), b.length()); while(len < max && ac[len] == bc[len]) len++; - // Important: It only is a splitting point if both a and b have a dot at + // Important: It only is a splitting point if both a and b have a sep at // this point! - while(len >= 0 && (ac[len] != dot || bc[len] != dot)) + while(len >= 0 && (ac[len] != sep || bc[len] != sep)) len--; return len; } @@ -136,14 +136,14 @@ void TreeBuilder::addList(const QString { QStringList branchList = branches.split("\n"); - //Code for testing the algorithmn + //Code for testing the algorithm srand( (unsigned)time( NULL ) ); while(int c = branchList.count()) add(branchList.takeAt(rand() % c)); - // FIXME: Replace the code above with the code below once it is clear that the algorithmn - // is working. Don't for get to remove the #includes. + // FIXME: Replace the code above with the code below once it is clear that the algorithm + // is working. Don't forget to remove the #includes. /*QStringListIterator iterator(branchList); while(iterator.hasNext()) ============================================================ --- guitone/src/util/TreeBuilder.h e060d7fe445bc817c3e3f80b30c2d25b9504640d +++ guitone/src/util/TreeBuilder.h 2a8dc775fd704078f4ab756e99cd3ea1a2ddf850 @@ -37,7 +37,7 @@ private: void addData(QStandardItem *item); int overlap(const QString &a, const QString &b); QStandardItem *root; - QChar dot; + QChar sep; }; #endif //TREEBUILDER_H ============================================================ --- guitone/src/view/dialogs/SwitchWorkspaceRevision.cpp d702f2d4fdec0bc1e7b1178006d1a52dfc984c87 +++ guitone/src/view/dialogs/SwitchWorkspaceRevision.cpp 4d173137804a19d26d741f6da0fa5a4d53f74341 @@ -129,7 +129,7 @@ void SwitchWorkspaceRevision::triggerRev selector.append(selectorValue->text()); - if (!selectorModel->readSelection(selector)) + if (!selectorModel->readSelection(selector, true)) { QMessageBox::warning( this,