PageRenderTime 35ms CodeModel.GetById 12ms 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. #include "Ancestors.h"
  19. #include <QFont>
  20. Ancestors::Ancestors(QObject * parent, const MonotoneHandlePtr & handle)
  21. : QAbstractItemModel(parent), AutomateCommand(0), monotoneHandle(handle)
  22. {
  23. selRevisions = new QStringList();
  24. }
  25. Ancestors::~Ancestors()
  26. {
  27. if (selRevisions)
  28. {
  29. selRevisions->clear();
  30. delete selRevisions;
  31. }
  32. }
  33. void Ancestors::readAncestors(const QStringList & parents)
  34. {
  35. // clear current attributes list
  36. selRevisions->clear();
  37. // reset the view
  38. reset();
  39. MonotoneTaskPtr task(new MonotoneTask(QStringList() << "ancestors" << parents));
  40. AutomateCommand::enqueueTask(monotoneHandle, task);
  41. }
  42. void Ancestors::processTaskResult(const MonotoneTaskPtr & task)
  43. {
  44. if (task->getReturnCode() == 2)
  45. {
  46. emit invalidAncestor(task->getDecodedOutput());
  47. }
  48. if (task->getReturnCode() != 0)
  49. {
  50. C(QString("Command returned with a non-zero return code (%1)")
  51. .arg(task->getDecodedOutput()));
  52. return;
  53. }
  54. if (selRevisions > 0)
  55. {
  56. selRevisions->clear();
  57. delete selRevisions;
  58. selRevisions = new QStringList(
  59. task->getDecodedOutput().split('\n', QString::SkipEmptyParts)
  60. );
  61. // reset the view
  62. reset();
  63. }
  64. // signal that we've finished (whoever listens to that)
  65. emit ancestorsRead();
  66. }
  67. int Ancestors::columnCount(const QModelIndex & parent) const
  68. {
  69. Q_UNUSED(parent);
  70. return 1;
  71. }
  72. QVariant Ancestors::data(const QModelIndex & index, int role) const
  73. {
  74. if (!index.isValid())
  75. {
  76. return QVariant();
  77. }
  78. if (role == Qt::FontRole)
  79. {
  80. QFont font;
  81. font.setStyleHint(QFont::Courier);
  82. font.setFamily("Courier");
  83. return QVariant(font);
  84. }
  85. if (role == Qt::DisplayRole)
  86. {
  87. int row = index.row();
  88. if (row >= selRevisions->size()) return QVariant();
  89. return QVariant(selRevisions->at(row));
  90. }
  91. return QVariant();
  92. }
  93. Qt::ItemFlags Ancestors::flags(const QModelIndex & index) const
  94. {
  95. if (index.isValid())
  96. {
  97. return Qt::ItemIsEnabled | Qt::ItemIsSelectable;
  98. }
  99. return 0;
  100. }
  101. QVariant Ancestors::headerData(int section, Qt::Orientation orientation, int role) const
  102. {
  103. Q_UNUSED(section);
  104. if (orientation == Qt::Horizontal && role == Qt::DisplayRole)
  105. {
  106. return QVariant(tr("Revision ID"));
  107. }
  108. return QVariant();
  109. }
  110. int Ancestors::rowCount(const QModelIndex & parent) const
  111. {
  112. Q_UNUSED(parent);
  113. return selRevisions->size();
  114. }
  115. QModelIndex Ancestors::index(int row, int column, const QModelIndex & parent) const
  116. {
  117. if (!hasIndex(row, column, parent))
  118. {
  119. return QModelIndex();
  120. }
  121. return createIndex(row, column, 0);
  122. }
  123. QModelIndex Ancestors::parent(const QModelIndex & index) const
  124. {
  125. Q_UNUSED(index);
  126. return QModelIndex();
  127. }