• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdevelop API Reference
  • KDE Home
  • Contact Us
 

kdevelop/kdevplatform/vcs

  • extragear
  • kdevelop
  • kdevelop
  • kdevplatform
  • vcs
  • models
vcseventmodel.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  * This file is part of KDevelop *
3  * Copyright 2007 Andreas Pakulat <[email protected]> *
4  * *
5  * This program is free software; you can redistribute it and/or modify *
6  * it under the terms of the GNU Library General Public License as *
7  * published by the Free Software Foundation; either version 2 of the *
8  * License, or (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 Library General Public *
16  * License along with this program; if not, write to the *
17  * Free Software Foundation, Inc., *
18  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
19  ***************************************************************************/
20 
21 #include "vcseventmodel.h"
22 
23 #include <QModelIndex>
24 #include <QVariant>
25 #include <QDateTime>
26 #include <QList>
27 #include <QLocale>
28 
29 #include <KLocalizedString>
30 
31 #include "../vcsevent.h"
32 #include "../vcsrevision.h"
33 #include <vcsjob.h>
34 #include <interfaces/ibasicversioncontrol.h>
35 #include <interfaces/icore.h>
36 #include <interfaces/iruncontroller.h>
37 
38 namespace KDevelop
39 {
40 
41 class VcsBasicEventModelPrivate
42 {
43 public:
44  QList<KDevelop::VcsEvent> m_events;
45 };
46 
47 VcsBasicEventModel::VcsBasicEventModel(QObject* parent)
48  : QAbstractTableModel(parent)
49  , d_ptr(new VcsBasicEventModelPrivate)
50 {
51 }
52 
53 VcsBasicEventModel::~VcsBasicEventModel() = default;
54 
55 int VcsBasicEventModel::rowCount(const QModelIndex& parent) const
56 {
57  Q_D(const VcsBasicEventModel);
58 
59  return parent.isValid() ? 0 : d->m_events.count();
60 }
61 
62 int VcsBasicEventModel::columnCount(const QModelIndex& parent) const
63 {
64  return parent.isValid() ? 0 : ColumnCount;
65 }
66 
67 QVariant VcsBasicEventModel::data(const QModelIndex& idx, int role) const
68 {
69  Q_D(const VcsBasicEventModel);
70 
71  if( !idx.isValid() || role != Qt::DisplayRole )
72  return QVariant();
73 
74  if( idx.row() < 0 || idx.row() >= rowCount() || idx.column() < 0 || idx.column() >= columnCount() )
75  return QVariant();
76 
77  KDevelop::VcsEvent ev = d->m_events.at( idx.row() );
78  switch( idx.column() )
79  {
80  case RevisionColumn:
81  return QVariant( ev.revision().revisionValue() );
82  case SummaryColumn:
83  // show the first line only
84  return QVariant( ev.message().section(QLatin1Char('\n'), 0, 0) );
85  case AuthorColumn:
86  return QVariant( ev.author() );
87  case DateColumn:
88  return QVariant( QLocale().toString( ev.date() ) );
89  default:
90  break;
91  }
92  return QVariant();
93 }
94 
95 QVariant VcsBasicEventModel::headerData(int section, Qt::Orientation orientation, int role) const
96 {
97  if( section < 0 || section >= columnCount() || orientation != Qt::Horizontal || role != Qt::DisplayRole )
98  return QVariant();
99  switch( section )
100  {
101  case RevisionColumn:
102  return QVariant( i18n("Revision") );
103  case SummaryColumn:
104  return QVariant( i18n("Message") );
105  case AuthorColumn:
106  return QVariant( i18n("Author") );
107  case DateColumn:
108  return QVariant( i18n("Date") );
109  default:
110  break;
111  }
112  return QVariant();
113 }
114 
115 void VcsBasicEventModel::addEvents(const QList<KDevelop::VcsEvent>& list)
116 {
117  Q_D(VcsBasicEventModel);
118 
119  if( list.isEmpty() )
120  return;
121 
122  beginInsertRows( QModelIndex(), rowCount(), rowCount()+list.count()-1 );
123  d->m_events += list;
124  endInsertRows();
125 }
126 
127 KDevelop::VcsEvent VcsBasicEventModel::eventForIndex(const QModelIndex& idx) const
128 {
129  Q_D(const VcsBasicEventModel);
130 
131  if( !idx.isValid() || idx.row() < 0 || idx.row() >= rowCount() )
132  {
133  return KDevelop::VcsEvent();
134  }
135  return d->m_events.at( idx.row() );
136 }
137 
138 class VcsEventLogModelPrivate
139 {
140 public:
141  KDevelop::IBasicVersionControl* m_iface;
142  VcsRevision m_rev;
143  QUrl m_url;
144  bool done;
145  bool fetching;
146 };
147 
148 VcsEventLogModel::VcsEventLogModel(KDevelop::IBasicVersionControl* iface, const VcsRevision& rev, const QUrl& url, QObject* parent)
149  : KDevelop::VcsBasicEventModel(parent)
150  , d_ptr(new VcsEventLogModelPrivate)
151 {
152  Q_D(VcsEventLogModel);
153 
154  d->m_iface = iface;
155  d->m_rev = rev;
156  d->m_url = url;
157  d->done = false;
158  d->fetching = false;
159 }
160 
161 VcsEventLogModel::~VcsEventLogModel() = default;
162 
163 bool VcsEventLogModel::canFetchMore(const QModelIndex& parent) const
164 {
165  Q_D(const VcsEventLogModel);
166 
167  return !d->done && !d->fetching && !parent.isValid();
168 }
169 
170 void VcsEventLogModel::fetchMore(const QModelIndex& parent)
171 {
172  Q_D(VcsEventLogModel);
173 
174  d->fetching = true;
175  Q_ASSERT(!parent.isValid());
176  Q_UNUSED(parent);
177  VcsJob* job = d->m_iface->log(d->m_url, d->m_rev, qMax(rowCount(), 100));
178  connect(this, &VcsEventLogModel::destroyed, job, [job] { job->kill(); });
179  connect(job, &VcsJob::finished, this, &VcsEventLogModel::jobReceivedResults);
180  ICore::self()->runController()->registerJob( job );
181 }
182 
183 void VcsEventLogModel::jobReceivedResults(KJob* job)
184 {
185  Q_D(VcsEventLogModel);
186 
187  const QList<QVariant> l = qobject_cast<KDevelop::VcsJob *>(job)->fetchResults().toList();
188  if(l.isEmpty() || job->error()!=0) {
189  d->done = true;
190  return;
191  }
192  QList<KDevelop::VcsEvent> newevents;
193  for (const QVariant& v : l) {
194  if( v.canConvert<KDevelop::VcsEvent>() )
195  {
196  newevents << v.value<KDevelop::VcsEvent>();
197  }
198  }
199  d->m_rev = newevents.last().revision();
200  if (rowCount()) {
201  newevents.removeFirst();
202  }
203  d->done = newevents.isEmpty();
204  addEvents( newevents );
205  d->fetching = false;
206 }
207 
208 }
KDevelop::VcsBasicEventModel::rowCount
int rowCount(const QModelIndex &=QModelIndex()) const override
Definition: vcseventmodel.cpp:55
QModelIndex
KDevelop::VcsBasicEventModel::~VcsBasicEventModel
~VcsBasicEventModel() override
KDevelop::VcsEvent::date
QDateTime date() const
Definition: vcsevent.cpp:131
vcsjob.h
KDevelop::VcsEventLogModel::canFetchMore
bool canFetchMore(const QModelIndex &parent) const override
Definition: vcseventmodel.cpp:163
KDevelop::VcsEventLogModel::~VcsEventLogModel
~VcsEventLogModel() override
KDevelop::VcsBasicEventModel::VcsBasicEventModel
VcsBasicEventModel(QObject *parent)
Definition: vcseventmodel.cpp:47
QAbstractTableModel
KDevelop::VcsBasicEventModel::ColumnCount
Definition: vcseventmodel.h:54
QList::removeFirst
void removeFirst()
KDevelop::VcsEvent::author
QString author() const
Definition: vcsevent.cpp:126
KDevelop::VcsEventLogModel::VcsEventLogModel
VcsEventLogModel(KDevelop::IBasicVersionControl *iface, const KDevelop::VcsRevision &rev, const QUrl &url, QObject *parent)
Definition: vcseventmodel.cpp:148
KDevelop::VcsBasicEventModel::RevisionColumn
Definition: vcseventmodel.h:50
KDevelop::VcsBasicEventModel::AuthorColumn
Definition: vcseventmodel.h:52
QList::value
T value(int i) const
KDevelop::VcsBasicEventModel::eventForIndex
KDevelop::VcsEvent eventForIndex(const QModelIndex &) const
Definition: vcseventmodel.cpp:127
QModelIndex::isValid
bool isValid() const
ibasicversioncontrol.h
QList::count
int count(const T &value) const
KDevelop::VcsBasicEventModel::data
QVariant data(const QModelIndex &, int role=Qt::DisplayRole) const override
Definition: vcseventmodel.cpp:67
QAbstractItemModel::endInsertRows
void endInsertRows()
KDevelop::VcsBasicEventModel::DateColumn
Definition: vcseventmodel.h:53
QObject
QList::isEmpty
bool isEmpty() const
KDevelop::VcsRevision::revisionValue
QVariant revisionValue() const
Return the value of this revision.
Definition: vcsrevision.cpp:83
QModelIndex::row
int row() const
KDevelop::VcsBasicEventModel::addEvents
void addEvents(const QList< KDevelop::VcsEvent > &)
Definition: vcseventmodel.cpp:115
KDevelop::VcsEvent::message
QString message() const
Definition: vcsevent.cpp:136
KDevelop::VcsEventLogModel
This model stores a list of VcsEvents corresponding to the log obtained via IBasicVersionControl::log...
Definition: vcseventmodel.h:78
QList
Definition: vcsannotationmodel.h:32
QLocale
QUrl
QLatin1Char
KDevelop::VcsBasicEventModel::headerData
QVariant headerData(int, Qt::Orientation, int role=Qt::DisplayRole) const override
Definition: vcseventmodel.cpp:95
QAbstractItemModel::beginInsertRows
void beginInsertRows(const QModelIndex &parent, int first, int last)
vcseventmodel.h
KDevelop::VcsBasicEventModel
This is a generic model to store a list of VcsEvents.
Definition: vcseventmodel.h:45
KDevelop::VcsEventLogModel::fetchMore
void fetchMore(const QModelIndex &parent) override
Adds events to the model via.
Definition: vcseventmodel.cpp:170
KDevelop::VcsJob
This class provides an extension of KJob to get various VCS-specific information about the job...
Definition: vcsjob.h:43
KDevelop::VcsRevision
Encapsulates a vcs revision number, date or range of revisions.
Definition: vcsrevision.h:66
KDevelop::VcsEvent::revision
VcsRevision revision() const
Definition: vcsevent.cpp:121
QList::last
T & last()
KDevelop::IBasicVersionControl
This is the basic interface that all Version Control or Source Code Management plugins need to implem...
Definition: ibasicversioncontrol.h:52
QModelIndex::column
int column() const
QString::section
QString section(QChar sep, int start, int end, QFlags< QString::SectionFlag > flags) const
KDevelop::VcsEvent
Small container class that contains information about a single revision.
Definition: vcsevent.h:92
QObject::connect
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
KDevelop::VcsBasicEventModel::columnCount
int columnCount(const QModelIndex &parent=QModelIndex()) const override
Definition: vcseventmodel.cpp:62
KJob
QObject::destroyed
void destroyed(QObject *obj)
KDevelop::VcsBasicEventModel::SummaryColumn
Definition: vcseventmodel.h:51
QVariant
This file is part of the KDE documentation.
Documentation copyright © 1996-2019 The KDE developers.
Generated on Fri Dec 6 2019 04:52:21 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kdevelop/kdevplatform/vcs

Skip menu "kdevelop/kdevplatform/vcs"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdevelop API Reference

Skip menu "kdevelop API Reference"
  •   kdevplatform
  •     debugger
  •     documentation
  •     interfaces
  •     language
  •       assistant
  •       backgroundparser
  •       checks
  •       classmodel
  •       codecompletion
  •       codegen
  •       duchain
  •       editor
  •       highlighting
  •       interfaces
  •       util
  •     outputview
  •     project
  •     serialization
  •     shell
  •     sublime
  •     tests
  •     util
  •     vcs

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal