/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
- /***************************************************************************
- * Copyright (C) 2006 by Jean-Louis Fuchs *
- * ganwell@fangorn.ch *
- * *
- * 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 <http://www.gnu.org/licenses/>. *
- ***************************************************************************/
- #include "Ancestors.h"
- #include <QFont>
- Ancestors::Ancestors(QObject * parent, const MonotoneHandlePtr & handle)
- : QAbstractItemModel(parent), AutomateCommand(0), monotoneHandle(handle)
- {
- selRevisions = new QStringList();
- }
- Ancestors::~Ancestors()
- {
- if (selRevisions)
- {
- selRevisions->clear();
- delete selRevisions;
- }
- }
- void Ancestors::readAncestors(const QStringList & parents)
- {
- // clear current attributes list
- selRevisions->clear();
- // reset the view
- reset();
- MonotoneTaskPtr task(new MonotoneTask(QStringList() << "ancestors" << parents));
- AutomateCommand::enqueueTask(monotoneHandle, task);
- }
- void Ancestors::processTaskResult(const MonotoneTaskPtr & task)
- {
- if (task->getReturnCode() == 2)
- {
- emit invalidAncestor(task->getDecodedOutput());
- }
- if (task->getReturnCode() != 0)
- {
- C(QString("Command returned with a non-zero return code (%1)")
- .arg(task->getDecodedOutput()));
- return;
- }
- if (selRevisions > 0)
- {
- selRevisions->clear();
- delete selRevisions;
- selRevisions = new QStringList(
- task->getDecodedOutput().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
- {
- Q_UNUSED(parent);
- 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
- {
- Q_UNUSED(section);
- if (orientation == Qt::Horizontal && role == Qt::DisplayRole)
- {
- return QVariant(tr("Revision ID"));
- }
- return QVariant();
- }
- int Ancestors::rowCount(const QModelIndex & parent) const
- {
- Q_UNUSED(parent);
- return selRevisions->size();
- }
- QModelIndex Ancestors::index(int row, int column, const QModelIndex & parent) const
- {
- if (!hasIndex(row, column, parent))
- {
- return QModelIndex();
- }
- return createIndex(row, column, 0);
- }
- QModelIndex Ancestors::parent(const QModelIndex & index) const
- {
- Q_UNUSED(index);
- return QModelIndex();
- }