annotate annotatedialog.cpp @ 331:acfe9390d5c6

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