comparison annotatedialog.cpp @ 331:acfe9390d5c6

Basic implementation of annotate
author Chris Cannam
date Sun, 13 Mar 2011 10:31:32 +0000
parents
children 70ad221e1619
comparison
equal deleted inserted replaced
330:bf4bbb53e217 331:acfe9390d5c6
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
2
3 /*
4 EasyMercurial
5
6 Based on hgExplorer by Jari Korhonen
7 Copyright (c) 2010 Jari Korhonen
8 Copyright (c) 2011 Chris Cannam
9 Copyright (c) 2011 Queen Mary, University of London
10
11 This program is free software; you can redistribute it and/or
12 modify it under the terms of the GNU General Public License as
13 published by the Free Software Foundation; either version 2 of the
14 License, or (at your option) any later version. See the file
15 COPYING included with this distribution for more information.
16 */
17
18 #include "annotatedialog.h"
19 #include "common.h"
20 #include "debug.h"
21
22 #include <QDialogButtonBox>
23 #include <QLabel>
24 #include <QTableWidget>
25 #include <QHeaderView>
26 #include <QGridLayout>
27
28 AnnotateDialog::AnnotateDialog(QWidget *w, QString text) :
29 QDialog(w)
30 {
31 setMinimumWidth(600);
32 setMinimumHeight(700);
33
34 text.replace("\r\n", "\n");
35 QStringList lines = text.split("\n");
36
37 QGridLayout *layout = new QGridLayout;
38 QTableWidget *table = new QTableWidget;
39
40 QRegExp annotateLineRE = QRegExp("^([^:]+) ([a-z0-9]{12}) ([0-9-]+): (.*)$");
41
42 table->setRowCount(lines.size());
43 table->setColumnCount(4);
44 table->horizontalHeader()->setStretchLastSection(true);
45
46 QStringList labels;
47 labels << tr("User") << tr("Revision") << tr("Date") << tr("Content");
48 table->setHorizontalHeaderLabels(labels);
49
50 int row = 0;
51
52 foreach (QString line, lines) {
53 if (annotateLineRE.indexIn(line) == 0) {
54 QStringList items = annotateLineRE.capturedTexts();
55 // note items[0] is the whole match, so we want 1-4
56 for (int col = 0; col+1 < items.size(); ++col) {
57 std::cerr << "row " << row << " col " << col << " text "
58 << items[col+1] << std::endl;
59 table->setItem(row, col, new QTableWidgetItem(items[col+1]));
60 }
61 } else {
62 DEBUG << "AnnotateDialog: Failed to match RE in line: " << line << " at row " << row << endl;
63 }
64 ++row;
65 }
66
67 QDialogButtonBox *bb = new QDialogButtonBox(QDialogButtonBox::Ok);
68 connect(bb, SIGNAL(accepted()), this, SLOT(accept()));
69
70 layout->addWidget(table, 0, 0);
71 layout->addWidget(bb, 1, 0);
72
73 setLayout(layout);
74 }
75