PageRenderTime 37ms CodeModel.GetById 25ms app.highlight 10ms RepoModel.GetById 0ms app.codeStats 0ms

/guitone-1.0rc5/src/model/Ancestors.cpp

#
C++ | 149 lines | 106 code | 22 blank | 21 comment | 18 complexity | 63869406c2c99364d41f62026a3e5100 MD5 | raw file
Possible License(s): GPL-3.0
  1/***************************************************************************
  2 *   Copyright (C) 2006 by Jean-Louis Fuchs                                *
  3 *   ganwell@fangorn.ch                                                    *
  4 *                                                                         *
  5 *   This program is free software; you can redistribute it and/or modify  *
  6 *   it under the terms of the GNU General Public License as published by  *
  7 *   the Free Software Foundation, either version 3 of the License, or     *
  8 *   (at your option) any later version.                                   *
  9 *                                                                         *
 10 *   This program is distributed in the hope that it will be useful,       *
 11 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 12 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 13 *   GNU General Public License for more details.                          *
 14 *                                                                         *
 15 *   You should have received a copy of the GNU General Public License     *
 16 *   along with this program.  If not, see <http://www.gnu.org/licenses/>. *
 17 ***************************************************************************/
 18
 19#include "Ancestors.h"
 20
 21#include <QFont>
 22
 23Ancestors::Ancestors(QObject * parent, const MonotoneHandlePtr & handle)
 24    : QAbstractItemModel(parent), AutomateCommand(0), monotoneHandle(handle)
 25{
 26    selRevisions = new QStringList();
 27}
 28
 29Ancestors::~Ancestors()
 30{
 31    if (selRevisions)
 32    {
 33        selRevisions->clear();
 34        delete selRevisions;
 35    }
 36}
 37
 38void Ancestors::readAncestors(const QStringList & parents)
 39{
 40    // clear current attributes list
 41    selRevisions->clear();
 42    // reset the view
 43    reset();
 44
 45    MonotoneTaskPtr task(new MonotoneTask(QStringList() << "ancestors" << parents));
 46    AutomateCommand::enqueueTask(monotoneHandle, task);
 47}
 48
 49void Ancestors::processTaskResult(const MonotoneTaskPtr & task)
 50{
 51    if (task->getReturnCode() == 2)
 52    {
 53        emit invalidAncestor(task->getDecodedOutput());
 54    }
 55
 56    if (task->getReturnCode() != 0)
 57    {
 58        C(QString("Command returned with a non-zero return code (%1)")
 59            .arg(task->getDecodedOutput()));
 60        return;
 61    }
 62
 63    if (selRevisions > 0)
 64    {
 65        selRevisions->clear();
 66        delete selRevisions;
 67        selRevisions = new QStringList(
 68            task->getDecodedOutput().split('\n', QString::SkipEmptyParts)
 69        );
 70        // reset the view
 71        reset();
 72    }
 73
 74    // signal that we've finished (whoever listens to that)
 75    emit ancestorsRead();
 76}
 77
 78int Ancestors::columnCount(const QModelIndex & parent) const
 79{
 80    Q_UNUSED(parent);
 81    return 1;
 82}
 83
 84QVariant Ancestors::data(const QModelIndex & index, int role) const
 85{
 86    if (!index.isValid())
 87    {
 88        return QVariant();
 89    }
 90
 91    if (role == Qt::FontRole)
 92    {
 93        QFont font;
 94        font.setStyleHint(QFont::Courier);
 95        font.setFamily("Courier");
 96        return QVariant(font);
 97    }
 98
 99    if (role == Qt::DisplayRole)
100    {
101        int row = index.row();
102        if (row >= selRevisions->size()) return QVariant();
103        return QVariant(selRevisions->at(row));
104    }
105
106    return QVariant();
107}
108
109Qt::ItemFlags Ancestors::flags(const QModelIndex & index) const
110{
111    if (index.isValid())
112    {
113        return Qt::ItemIsEnabled | Qt::ItemIsSelectable;
114    }
115    return 0;
116}
117
118QVariant Ancestors::headerData(int section, Qt::Orientation orientation, int role) const
119{
120    Q_UNUSED(section);
121    if (orientation == Qt::Horizontal && role == Qt::DisplayRole)
122    {
123        return QVariant(tr("Revision ID"));
124    }
125    return QVariant();
126}
127
128int Ancestors::rowCount(const QModelIndex & parent) const
129{
130    Q_UNUSED(parent);
131    return selRevisions->size();
132}
133
134QModelIndex Ancestors::index(int row, int column, const QModelIndex & parent) const
135{
136    if (!hasIndex(row, column, parent))
137    {
138        return QModelIndex();
139    }
140
141    return createIndex(row, column, 0);
142}
143
144QModelIndex Ancestors::parent(const QModelIndex & index) const
145{
146    Q_UNUSED(index);
147    return QModelIndex();
148}
149