# # # add_file "guitone/src/model/Ancestors.cpp" # content [006522686b40da7d61dd6d240646b8562fed2fdd] # # add_file "guitone/src/model/Ancestors.h" # content [9ab08563cff3421ca54a529d985aff8f475f6105] # # patch "guitone/guitone.pro" # from [f92b918bbde8d6084b6de4cd4dcf577a266cf3f7] # to [4d7b37fc37972ff6e8e387cd9d96685b3f5f5793] # # patch "guitone/res/i18n/guitone_de.ts" # from [ece9c70819331cfccb4a350976db0d43cc1ae673] # to [db1af251ea647d64599652b8107a5bf63e5e7f10] # # patch "guitone/src/main.cpp" # from [41f57d259c796164c7939ec5c3b779593016afbd] # to [43f4662e814165beeb2efdf51d1cc61d29e2595c] # # patch "guitone/src/model/Changeset.cpp" # from [da39a3ee5e6b4b0d3255bfef95601890afd80709] # to [0693bfc11b59510a00961beb236da055219dd3eb] # # patch "guitone/src/model/Changeset.h" # from [da39a3ee5e6b4b0d3255bfef95601890afd80709] # to [fbc3054a4c65d837f6a125a68769443211785bd6] # # patch "guitone/src/model/ChangesetModel.cpp" # from [da39a3ee5e6b4b0d3255bfef95601890afd80709] # to [a74917f30ffe8f3bbf50a3380d5a13d05b40a1bf] # # patch "guitone/src/model/ChangesetModel.h" # from [da39a3ee5e6b4b0d3255bfef95601890afd80709] # to [de65803c9618125cd0f9983a3bf1af3b36bb9499] # # patch "guitone/src/view/dialogs/DatabaseView.cpp" # from [06c1298cbbdf800222e15ffa236507f26c3d48f9] # to [3d3f969a6aaedf2b06dbef25c2333e9933c40f12] # # patch "guitone/src/view/dialogs/DatabaseView.h" # from [fda82f6ec5c47ded48a43a4618b4ecdd2c7ee291] # to [1ea140cf0e3f1a8784561918c17481726df9b9c1] # ============================================================ --- guitone/src/model/Ancestors.cpp 006522686b40da7d61dd6d240646b8562fed2fdd +++ guitone/src/model/Ancestors.cpp 006522686b40da7d61dd6d240646b8562fed2fdd @@ -0,0 +1,156 @@ +/*************************************************************************** + * 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 "Ancestors.h" +#include "Toposort.h" +#include "Monotone.h" + +#include + +Ancestors::Ancestors(QObject *parent) + : QAbstractItemModel(parent) +{ + selRevisions = new RevisionList(); + mtnDelegate = new MonotoneDelegate(this); +} + +Ancestors::~Ancestors() +{ + if (selRevisions) + { + selRevisions->clear(); + delete selRevisions; + } + + delete mtnDelegate; +} + +bool Ancestors::readAncestors(const QStringList & parents) +{ + // clear current attributes list + selRevisions->clear(); + // reset the view + reset(); + + QStringList cmd; + cmd.append("ancestors"); + cmd << parents; + + return mtnDelegate->triggerCommand(cmd); +} + +bool Ancestors::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 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) + ); + // reset the view + reset(); + } + + // signal that we've finished (whoever listens to that) + emit AncestorsRead(); +} + +int Ancestors::columnCount(const QModelIndex &parent) const +{ + return 1; +} + +QVariant Ancestors::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 Ancestors::flags(const QModelIndex &index) const +{ + if (index.isValid()) + { + return Qt::ItemIsEnabled | Qt::ItemIsSelectable; + } + return 0; +} + +QVariant Ancestors::headerData(int section, Qt::Orientation orientation, int role) const +{ + if (orientation == Qt::Horizontal && role == Qt::DisplayRole) + { + return QVariant(tr("Revision ID")); + } + return QVariant(); +} + +int Ancestors::rowCount(const QModelIndex& parent) const +{ + return selRevisions->size(); +} + +QModelIndex Ancestors::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, rev); +} + +QModelIndex Ancestors::parent(const QModelIndex& index) const +{ + return QModelIndex(); +} + ============================================================ --- guitone/src/model/Ancestors.h 9ab08563cff3421ca54a529d985aff8f475f6105 +++ guitone/src/model/Ancestors.h 9ab08563cff3421ca54a529d985aff8f475f6105 @@ -0,0 +1,62 @@ +/*************************************************************************** + * 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 ANCESTORS_H +#define ANCESTORS_H + +#include "AutomateCommand.h" +#include "MonotoneDelegate.h" + +#include + +typedef QStringList RevisionList; + +class Ancestors : public QAbstractItemModel, public AutomateCommand +{ + Q_OBJECT +public: + Ancestors(QObject*); + virtual ~Ancestors(); + + // 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 readAncestors(const QStringList &); + +signals: + void AncestorsRead(); + void invalidAncestor(QString); + +private: + void parseOutput(); + bool handleError(int); + RevisionList *selRevisions; + bool sorted; + MonotoneDelegate * mtnDelegate; +}; + +#endif ============================================================ --- guitone/guitone.pro f92b918bbde8d6084b6de4cd4dcf577a266cf3f7 +++ guitone/guitone.pro 4d7b37fc37972ff6e8e387cd9d96685b3f5f5793 @@ -47,6 +47,7 @@ HEADERS += src/view/MainWindow.h \ src/model/ChangesetModel.h \ src/model/Toposort.h \ src/model/Manifest.h \ + src/model/Ancestors.h \ src/util/IconProvider.h \ src/util/StanzaParser.h \ src/util/Settings.h \ @@ -91,6 +92,7 @@ SOURCES += src/view/MainWindow.cpp \ src/model/ChangesetModel.cpp \ src/model/Toposort.cpp \ src/model/Manifest.cpp \ + src/model/Ancestors.cpp \ src/util/IconProvider.cpp \ src/util/StanzaParser.cpp \ src/util/Settings.cpp \ ============================================================ --- guitone/res/i18n/guitone_de.ts ece9c70819331cfccb4a350976db0d43cc1ae673 +++ guitone/res/i18n/guitone_de.ts db1af251ea647d64599652b8107a5bf63e5e7f10 @@ -27,6 +27,14 @@ + Ancestors + + + Revision ID + Revisions-ID + + + Attributes @@ -126,6 +134,14 @@ + ChangesetModel + + + Revision ID + Revisions-ID + + + ContentDiff ============================================================ --- guitone/src/main.cpp 41f57d259c796164c7939ec5c3b779593016afbd +++ guitone/src/main.cpp 43f4662e814165beeb2efdf51d1cc61d29e2595c @@ -75,7 +75,6 @@ int main(int argc, char** argv) mainWnd->show(); app.connect(&app, SIGNAL(lastWindowClosed()), mainWnd, SLOT(quit())); - return app.exec(); } ============================================================ --- guitone/src/model/Changeset.cpp da39a3ee5e6b4b0d3255bfef95601890afd80709 +++ guitone/src/model/Changeset.cpp 0693bfc11b59510a00961beb236da055219dd3eb @@ -0,0 +1,39 @@ +/*************************************************************************** + * 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 "Changeset.h" + +Changeset::Changeset(QString revision, QDate) +{ + this->revision = revision; + this->date = date; +} + +QString Changeset::getRevision() +{ + return revision; +} + +QDate Changeset::getDate() +{ + return date; +} + +Changeset::~Changeset() {} ============================================================ --- guitone/src/model/Changeset.h da39a3ee5e6b4b0d3255bfef95601890afd80709 +++ guitone/src/model/Changeset.h fbc3054a4c65d837f6a125a68769443211785bd6 @@ -0,0 +1,40 @@ +/*************************************************************************** + * 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 CHANGESET_H +#define CHANGESET_H + +#include + +class Changeset +{ +public: + Changeset(QString revsion, QDate date); + ~Changeset(); + + QString getRevision(); + QDate getDate(); + +private: + QString revision; + QDate date; +}; + +#endif //CHANGESET_H ============================================================ --- guitone/src/model/ChangesetModel.cpp da39a3ee5e6b4b0d3255bfef95601890afd80709 +++ guitone/src/model/ChangesetModel.cpp a74917f30ffe8f3bbf50a3380d5a13d05b40a1bf @@ -0,0 +1,169 @@ +/*************************************************************************** + * 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 "ChangesetModel.h" + +ChangesetModel::ChangesetModel(QObject *parent) : QAbstractItemModel(parent) +{ + currentBranch = ""; + selectModel = new Select(this); + revSortModel = new Toposort(this); + ancestorModel = new Ancestors(this); + revSortModel->setSourceModel(ancestorModel); + connect(selectModel, SIGNAL(selectionRead()), + this, SLOT(selectionReady())); + connect(revSortModel, SIGNAL(sortingFinished()), + this, SLOT(revisionsReady())); +} + +ChangesetModel::~ChangesetModel() +{ + delete selectModel; + delete revSortModel; + delete ancestorModel; +} + +void ChangesetModel::receiveRevisions() +{ + +} + +void ChangesetModel::setBranch(QString branch) +{ + currentBranch = branch; + if(branchMap[currentBranch].count == 0) + { + selectModel->readSelection("h:" + currentBranch); + } +} + +void ChangesetModel::selectionReady() +{ + QStringList heads; + int count = selectModel->rowCount(QModelIndex()); + for(int i = 0; i < count; i++) + { + heads << selectModel->data(selectModel->index(i, 0, QModelIndex()), Qt::DisplayRole).toString(); + } + + ancestorModel->readAncestors(heads); +} + +void ChangesetModel::revisionsReady() +{ + QStringList *list = &branchMap[currentBranch]; + int count = revSortModel->rowCount(QModelIndex()); + for(int i = 0; i < count; i++) + { + revSortModel->sort(0, Qt::AscendingOrder); + (*list) << revSortModel->QSortFilterProxyModel::data(revSortModel->index(i, 0, QModelIndex()), Qt::DisplayRole).toString(); + } + reset(); + receiveRevisions(); +} + +int ChangesetModel::columnCount(const QModelIndex &parent) const +{ + return 4; +} + +QVariant ChangesetModel::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 (branchMap[currentBranch].count() > row) + { + int col = index.column(); + switch(col) + { + case(3): + return QVariant(branchMap[currentBranch][row]); + } + } + } + + return QVariant(); +} + +Qt::ItemFlags ChangesetModel::flags(const QModelIndex &index) const +{ + if (index.isValid()) + { + return Qt::ItemIsEnabled | Qt::ItemIsSelectable; + } + return 0; +} + +QVariant ChangesetModel::headerData(int section, Qt::Orientation orientation, int role) const +{ + if (orientation == Qt::Horizontal && role == Qt::DisplayRole) + { + switch(section) + { + case(0): + return QVariant(tr("Date")); + case(1): + return QVariant(tr("Author")); + case(2): + return QVariant(tr("Changelog")); + case(3): + return QVariant(tr("Revision ID")); + } + } + return QVariant(); +} + +int ChangesetModel::rowCount(const QModelIndex& parent) const +{ + if (!parent.isValid()) + return branchMap[currentBranch].count(); + return 0; +} + +QModelIndex ChangesetModel::index(int row, int column, const QModelIndex& parent) const +{ + if (!hasIndex(row, column, parent)) + { + return QModelIndex(); + } + + QString *rev = new QString(branchMap[currentBranch][row]); + return createIndex(row, column, rev); +} + +QModelIndex ChangesetModel::parent(const QModelIndex& index) const +{ + return QModelIndex(); +} + ============================================================ --- guitone/src/model/ChangesetModel.h da39a3ee5e6b4b0d3255bfef95601890afd80709 +++ guitone/src/model/ChangesetModel.h de65803c9618125cd0f9983a3bf1af3b36bb9499 @@ -0,0 +1,69 @@ +/*************************************************************************** + * 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 CHANGESETMODE_H +#define CHANGESETMODE_H + +#include "Changeset.h" +#include "Ancestors.h" +#include "Select.h" +#include "Toposort.h" + +#include + +typedef QMap ChangesetMap; +typedef QMap BranchMap; + +class ChangesetModel : public QAbstractItemModel +{ + Q_OBJECT + +public: + ChangesetMap branchModel; + ChangesetModel(QObject *parent = 0); + ~ChangesetModel(); + + void setBranch(QString branch); + void receiveRevisions(); + + // 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; + +private slots: + void selectionReady(); + void revisionsReady(); + +private: + QString currentBranch; + static const int revPerReceive = 50; + Select * selectModel; + Toposort * revSortModel; + Ancestors * ancestorModel; + BranchMap branchMap; + ChangesetMap changesetMap; +}; + +#endif //CHANGESETMODE_H ============================================================ --- guitone/src/view/dialogs/DatabaseView.cpp 06c1298cbbdf800222e15ffa236507f26c3d48f9 +++ guitone/src/view/dialogs/DatabaseView.cpp 3d3f969a6aaedf2b06dbef25c2333e9933c40f12 @@ -40,6 +40,10 @@ DatabaseView::DatabaseView(QWidget *pare this, SLOT(branchesClicked(QModelIndex))); connect(toolTree, SIGNAL(clicked()), this, SLOT(toggleTree())); + + changesetModel = new ChangesetModel(this); + changesets->setModel(changesetModel); + changesets->setRootIsDecorated(false); } DatabaseView::~DatabaseView() @@ -56,7 +60,7 @@ void DatabaseView::branchesClicked(QMode void DatabaseView::branchesClicked(QModelIndex idx) { QString branch = branchModel->data(idx, Qt::ToolTipRole).toString(); - readChangesets(branch); + changesetModel->setBranch(branch); } void DatabaseView::initTreeWidget() @@ -75,8 +79,3 @@ void DatabaseView::branchesRead() { branches->setExpanded(branchModel->index(0, 0, QModelIndex()), true); } - -void DatabaseView::readChangesets(const QString &branch) -{ - qDebug() << branch; -} ============================================================ --- guitone/src/view/dialogs/DatabaseView.h fda82f6ec5c47ded48a43a4618b4ecdd2c7ee291 +++ guitone/src/view/dialogs/DatabaseView.h 1ea140cf0e3f1a8784561918c17481726df9b9c1 @@ -25,6 +25,7 @@ #include "Monotone.h" #include "Branches.h" #include "Dialog.h" +#include "ChangesetModel.h" #include @@ -34,6 +35,7 @@ public: public: Branches *branchModel; + ChangesetModel *changesetModel; DatabaseView(QWidget *parent = 0); ~DatabaseView(); @@ -45,7 +47,6 @@ private: private: bool tree; void initTreeWidget(); - void readChangesets(const QString &branch); }; #endif //DATABASEVIEW_H