# # # add_file "src/view/widgets/CertListBrowser.cpp" # content [7b10a41d97f7692e656450d562fce456040c0dbc] # # add_file "src/view/widgets/CertListBrowser.h" # content [db0ffa6a52db23b4a74b5f6069c8243ea229a3ed] # # patch "guitone.pro" # from [44021940bbffed9caffd3b96cdcddfe8238aa209] # to [4c98b74da3eb5f33933d210a4ff916eb661e280b] # # patch "res/forms/dialogs/annotate.ui" # from [839c5a5809de9e5e4068a70480edcf919da79991] # to [afb7bdb74c80f6dd7d1645215548059e1a584706] # # patch "src/model/Annotate.cpp" # from [7a4d854c9c3abf7a9adfd6b6115a6be691e7b4b0] # to [d7fe79ade508a60624a3aa51bf23f5ce8076c4a9] # # patch "src/model/Annotate.h" # from [0468d04bd508d7aba5ac13c083784d2e12dc2a5b] # to [3b36b4f860145308b3f77295e4ed484c3402c328] # # patch "src/view/dialogs/AnnotateFile.cpp" # from [1edd1c4cfe1705865f6fe06566c61c8cc9d45548] # to [7781a16f5c64f4b921e04caeb7a1e9a15ff95d56] # ============================================================ --- src/view/widgets/CertListBrowser.cpp 7b10a41d97f7692e656450d562fce456040c0dbc +++ src/view/widgets/CertListBrowser.cpp 7b10a41d97f7692e656450d562fce456040c0dbc @@ -0,0 +1,69 @@ +/*************************************************************************** + * Copyright (C) 2010 by Thomas Keller * + * 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 3 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, see . * + ***************************************************************************/ + +#include "CertListBrowser.h" +#include "MonotoneUtil.h" + +CertListBrowser::CertListBrowser(QWidget * parent) + : QTextBrowser(parent) {} + +CertListBrowser::~CertListBrowser() {} + +void CertListBrowser::setCertList(const CertList & list) +{ + QString html = + "" + ; + + foreach (const Cert & cert, list.certs) + { + QString name, value; + if (cert.name == "date") + { + name = tr("Date"); + value = cert.dateTimeValue().toString( + Qt::DefaultLocaleShortDate + ); + } + else if (cert.name == "changelog") + { + name = tr("Changelog"); + value = cert.htmlValue(); + } + else + { + // localize common certs + if (cert.name == "author") + name = tr("Author"); + else if (cert.name == "branch") + name = tr("Branch"); + else if (cert.name == "tag") + name = tr("Tag"); + else + name = cert.name; + + value = cert.value; + } + + html += QString("
%1
%2
").arg(name).arg(value); + } + setHtml(QString("
%1
").arg(html)); +} + ============================================================ --- src/view/widgets/CertListBrowser.h db0ffa6a52db23b4a74b5f6069c8243ea229a3ed +++ src/view/widgets/CertListBrowser.h db0ffa6a52db23b4a74b5f6069c8243ea229a3ed @@ -0,0 +1,36 @@ +/*************************************************************************** + * Copyright (C) 2010 by Thomas Keller * + * 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 3 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, see . * + ***************************************************************************/ + +#ifndef CERT_LIST_BROWSER_H +#define CERT_LIST_BROWSER_H + +#include "vocab.h" +#include + +class CertListBrowser : public QTextBrowser +{ + Q_OBJECT +public: + CertListBrowser(QWidget *); + ~CertListBrowser(); + +public slots: + void setCertList(const CertList &); +}; + +#endif ============================================================ --- guitone.pro 44021940bbffed9caffd3b96cdcddfe8238aa209 +++ guitone.pro 4c98b74da3eb5f33933d210a4ff916eb661e280b @@ -38,6 +38,7 @@ HEADERS = src/view/widgets/TreeView.h \ src/view/widgets/ToolBox.h \ src/view/widgets/SearchInput.h \ src/view/widgets/SizeableLabel.h \ + src/view/widgets/CertListBrowser.h \ src/view/mainwindows/MainWindow.h \ src/view/mainwindows/WorkspaceWindow.h \ src/view/mainwindows/DatabaseWindow.h \ @@ -132,6 +133,7 @@ SOURCES += src/view/widgets/TreeView.cpp src/view/widgets/ToolBox.cpp \ src/view/widgets/SearchInput.cpp \ src/view/widgets/SizeableLabel.cpp \ + src/view/widgets/CertListBrowser.cpp \ src/view/mainwindows/MainWindow.cpp \ src/view/mainwindows/WorkspaceWindow.cpp \ src/view/mainwindows/DatabaseWindow.cpp \ ============================================================ --- res/forms/dialogs/annotate.ui 839c5a5809de9e5e4068a70480edcf919da79991 +++ res/forms/dialogs/annotate.ui afb7bdb74c80f6dd7d1645215548059e1a584706 @@ -101,7 +101,7 @@ - + @@ -174,6 +174,11 @@ QTreeView
TreeView.h
+ + CertListBrowser + QTextBrowser +
CertListBrowser.h
+
============================================================ --- src/model/Annotate.cpp 7a4d854c9c3abf7a9adfd6b6115a6be691e7b4b0 +++ src/model/Annotate.cpp d7fe79ade508a60624a3aa51bf23f5ce8076c4a9 @@ -22,8 +22,70 @@ #include +Annotation::Annotation(Annotate * ann, QString rev, QString c, bool s) + : model(ann), revision(rev), code(c), show_info(s) +{ + annotationFont.setPointSize(10); + + codeFont.setStyleHint(QFont::Courier); + codeFont.setFamily("Courier"); +} + +QVariant Annotation::data(int col, int role) const +{ + if (role == Qt::DisplayRole) + { + if (col == 0) + { + if (!show_info) + return QVariant(); + + CertList certs = model->getCachedCertList(revision); + if (certs.revision.isEmpty()) + return QVariant(revision); + + QList authorCerts = certs.find("author"); + QList dateCerts = certs.find("date"); + + if (authorCerts.size() == 0 || dateCerts.size() == 0) + return QVariant(revision); + + QString author = authorCerts.at(0).value; + if (author.size() > 8) + author = author.left(6) + ".."; + + QString date = dateCerts.at(0).dateTimeValue().date().toString( + Qt::DefaultLocaleShortDate + ); + + return QVariant(QString("%1 by %2 on %3") + .arg(revision.left(8)).arg(author).arg(date) + ); + } + + if (col == 1) + return QVariant(code); + } + + if (role == Qt::FontRole) + { + if (col == 0) + return QVariant(annotationFont); + + if (col == 1) + return QVariant(codeFont); + } + + if (role == Qt::UserRole) + { + return QVariant(revision); + } + + return QVariant(); +} + Annotate::Annotate(QObject * parent) - : QAbstractItemModel(parent), proc(0) + : QAbstractItemModel(parent), proc(0), certsModel(0) { proc = new MonotoneProcess(); connect( @@ -35,6 +97,7 @@ Annotate::~Annotate() Annotate::~Annotate() { if (proc) delete proc; + if (certsModel) delete certsModel; } void Annotate::readAnnotation(const DatabaseFile & db, @@ -46,6 +109,15 @@ void Annotate::readAnnotation(const Data annotationLines.clear(); reset(); + if (certsModel) + delete certsModel; + + certsModel = new Certs(this, db); + connect( + certsModel, SIGNAL(certsRead(const CertList &)), + this, SLOT(certsRead(const CertList &)) + ); + databaseFile = db; proc->start( QStringList() << "annotate" << "-d" << db @@ -83,7 +155,7 @@ void Annotate::processFinished(int exitC lastRevision = revision; annotationLines.append( - Annotation(revision, code, showAnnotation) + Annotation(this, revision, code, showAnnotation) ); revisions.insert(revision); } @@ -105,6 +177,11 @@ void Annotate::processFinished(int exitC inverseBrushMap.insert(rev, QBrush(QColor::fromRgbF(1.0 - r, 1.0 - g, 1.0 - b))); r += rStep; g += gStep; b += bStep; + + if (!certMap.contains(rev)) + { + certsToRead.push(rev); + } } highlightBrush = QBrush(QColor( @@ -113,8 +190,45 @@ void Annotate::processFinished(int exitC reset(); emit annotationRead(); + + readNextCerts(); } +void Annotate::readNextCerts() +{ + if (certsToRead.size() == 0) + return; + certsModel->readCerts(certsToRead.pop()); +} + +void Annotate::certsRead(const CertList & certs) +{ + certMap[certs.revision] = certs; + for (int i=0; i #include #include +#include + #include "MonotoneProcess.h" +#include "Certs.h" #include "vocab.h" -struct Annotation +class Annotate; + +class Annotation { +public: + Annotation(Annotate *, QString, QString, bool); + QVariant data(int, int) const; + +private: + Annotate * model; QString revision; QString code; bool show_info; @@ -35,45 +46,7 @@ struct Annotation QFont annotationFont; QFont codeFont; - Annotation(QString rev, QString c, bool s) - : revision(rev), code(c), show_info(s) - { - annotationFont.setPointSize(10); - - codeFont.setStyleHint(QFont::Courier); - codeFont.setFamily("Courier"); - } - - QVariant data(int col, int role) const - { - if (role == Qt::DisplayRole) - { - if (col == 0) - { - if (!show_info) return QVariant(); - return QVariant(revision); - } - - if (col == 1) - return QVariant(code); - } - - if (role == Qt::FontRole) - { - if (col == 0) - return QVariant(annotationFont); - - if (col == 1) - return QVariant(codeFont); - } - - if (role == Qt::UserRole) - { - return QVariant(revision); - } - - return QVariant(); - } + friend class Annotate; }; class Annotate : public QAbstractItemModel @@ -82,6 +55,7 @@ public: public: Annotate(QObject *); virtual ~Annotate(); + CertList getCachedCertList(const QString &) const; // needed Qt Model methods QVariant data(const QModelIndex &, int) const; @@ -98,17 +72,26 @@ signals: signals: void annotationRead(); + void currentCertList(const CertList &); private: DatabaseFile databaseFile; QList annotationLines; MonotoneProcess * proc; + Certs * certsModel; + QStack certsToRead; + QMap certMap; QMap brushMap, inverseBrushMap; QBrush highlightBrush; QString selectedRevision; + void readNextCerts(); + private slots: void processFinished(int exitCode, QProcess::ExitStatus exitStatus); + void certsRead(const CertList &); + + friend class Annotation; }; #endif ============================================================ --- src/view/dialogs/AnnotateFile.cpp 1edd1c4cfe1705865f6fe06566c61c8cc9d45548 +++ src/view/dialogs/AnnotateFile.cpp 7781a16f5c64f4b921e04caeb7a1e9a15ff95d56 @@ -35,6 +35,11 @@ AnnotateFile::AnnotateFile(QWidget * par ); connect( + annotateModel, SIGNAL(currentCertList(const CertList &)), + changelog, SLOT(setCertList(const CertList &)) + ); + + connect( annotationView, SIGNAL(selectedRows(const QModelIndexList &)), this, SLOT(rowsSelected(const QModelIndexList &)) ); @@ -109,8 +114,5 @@ void AnnotateFile::rowsSelected(const QM // if the guard above which checks for no selected indexes is // removed, then this leads to infinite recursion! annotationView->selectionModel()->clearSelection(); - - // FIXME: temporary - changelog->setText(rev); }