Changeset View
Changeset View
Standalone View
Standalone View
vcs/models/vcseventmodel.cpp
Show All 32 Lines | |||||
33 | #include <vcsjob.h> | 33 | #include <vcsjob.h> | ||
34 | #include <interfaces/ibasicversioncontrol.h> | 34 | #include <interfaces/ibasicversioncontrol.h> | ||
35 | #include <interfaces/icore.h> | 35 | #include <interfaces/icore.h> | ||
36 | #include <interfaces/iruncontroller.h> | 36 | #include <interfaces/iruncontroller.h> | ||
37 | 37 | | |||
38 | namespace KDevelop | 38 | namespace KDevelop | ||
39 | { | 39 | { | ||
40 | 40 | | |||
41 | class VcsEventModelPrivate | 41 | class VcsBasicEventModelPrivate | ||
42 | { | 42 | { | ||
43 | public: | 43 | public: | ||
44 | QList<KDevelop::VcsEvent> m_events; | 44 | QList<KDevelop::VcsEvent> m_events; | ||
45 | KDevelop::IBasicVersionControl* m_iface; | | |||
46 | VcsRevision m_rev; | | |||
47 | QUrl m_url; | | |||
48 | bool done; | | |||
49 | bool fetching; | | |||
50 | }; | 45 | }; | ||
51 | 46 | | |||
52 | VcsEventModel::VcsEventModel( KDevelop::IBasicVersionControl* iface, const VcsRevision& rev, const QUrl& url, QObject* parent ) | 47 | VcsBasicEventModel::VcsBasicEventModel(QObject* parent) | ||
53 | : QAbstractTableModel( parent ), d(new VcsEventModelPrivate) | 48 | : QAbstractTableModel(parent), d(new VcsBasicEventModelPrivate) | ||
54 | { | 49 | { | ||
55 | d->m_iface = iface; | | |||
56 | d->m_rev = rev; | | |||
57 | d->m_url = url; | | |||
58 | d->done = false; | | |||
59 | d->fetching = false; | | |||
60 | } | 50 | } | ||
61 | 51 | | |||
62 | VcsEventModel::~VcsEventModel() | 52 | VcsBasicEventModel::~VcsBasicEventModel() = default; | ||
63 | { | | |||
64 | delete d; | | |||
65 | } | | |||
66 | 53 | | |||
67 | int VcsEventModel::rowCount( const QModelIndex& parent) const | 54 | int VcsBasicEventModel::rowCount(const QModelIndex& parent) const | ||
68 | { | 55 | { | ||
69 | return parent.isValid() ? 0 : d->m_events.count(); | 56 | return parent.isValid() ? 0 : d->m_events.count(); | ||
70 | } | 57 | } | ||
71 | 58 | | |||
72 | int VcsEventModel::columnCount( const QModelIndex& parent) const | 59 | int VcsBasicEventModel::columnCount(const QModelIndex& parent) const | ||
73 | { | 60 | { | ||
74 | return parent.isValid() ? 0 : ColumnCount; | 61 | return parent.isValid() ? 0 : ColumnCount; | ||
75 | } | 62 | } | ||
76 | 63 | | |||
77 | QVariant VcsEventModel::data( const QModelIndex& idx, int role ) const | 64 | QVariant VcsBasicEventModel::data(const QModelIndex& idx, int role) const | ||
78 | { | 65 | { | ||
79 | if( !idx.isValid() || role != Qt::DisplayRole ) | 66 | if( !idx.isValid() || role != Qt::DisplayRole ) | ||
80 | return QVariant(); | 67 | return QVariant(); | ||
81 | 68 | | |||
82 | if( idx.row() < 0 || idx.row() >= rowCount() || idx.column() < 0 || idx.column() >= columnCount() ) | 69 | if( idx.row() < 0 || idx.row() >= rowCount() || idx.column() < 0 || idx.column() >= columnCount() ) | ||
83 | return QVariant(); | 70 | return QVariant(); | ||
84 | 71 | | |||
85 | KDevelop::VcsEvent ev = d->m_events.at( idx.row() ); | 72 | KDevelop::VcsEvent ev = d->m_events.at( idx.row() ); | ||
Show All 9 Lines | 74 | { | |||
95 | case DateColumn: | 82 | case DateColumn: | ||
96 | return QVariant( QLocale().toString( ev.date() ) ); | 83 | return QVariant( QLocale().toString( ev.date() ) ); | ||
97 | default: | 84 | default: | ||
98 | break; | 85 | break; | ||
99 | } | 86 | } | ||
100 | return QVariant(); | 87 | return QVariant(); | ||
101 | } | 88 | } | ||
102 | 89 | | |||
103 | QVariant VcsEventModel::headerData( int section, Qt::Orientation orientation, int role ) const | 90 | QVariant VcsBasicEventModel::headerData(int section, Qt::Orientation orientation, int role) const | ||
104 | { | 91 | { | ||
105 | if( section < 0 || section >= columnCount() || orientation != Qt::Horizontal || role != Qt::DisplayRole ) | 92 | if( section < 0 || section >= columnCount() || orientation != Qt::Horizontal || role != Qt::DisplayRole ) | ||
106 | return QVariant(); | 93 | return QVariant(); | ||
107 | switch( section ) | 94 | switch( section ) | ||
108 | { | 95 | { | ||
109 | case RevisionColumn: | 96 | case RevisionColumn: | ||
110 | return QVariant( i18n("Revision") ); | 97 | return QVariant( i18n("Revision") ); | ||
111 | case SummaryColumn: | 98 | case SummaryColumn: | ||
112 | return QVariant( i18n("Message") ); | 99 | return QVariant( i18n("Message") ); | ||
113 | case AuthorColumn: | 100 | case AuthorColumn: | ||
114 | return QVariant( i18n("Author") ); | 101 | return QVariant( i18n("Author") ); | ||
115 | case DateColumn: | 102 | case DateColumn: | ||
116 | return QVariant( i18n("Date") ); | 103 | return QVariant( i18n("Date") ); | ||
117 | default: | 104 | default: | ||
118 | break; | 105 | break; | ||
119 | } | 106 | } | ||
120 | return QVariant(); | 107 | return QVariant(); | ||
121 | } | 108 | } | ||
122 | 109 | | |||
123 | void VcsEventModel::addEvents( const QList<KDevelop::VcsEvent>& list ) | 110 | void VcsBasicEventModel::addEvents(const QList<KDevelop::VcsEvent>& list) | ||
124 | { | 111 | { | ||
125 | if( list.isEmpty() ) | 112 | if( list.isEmpty() ) | ||
126 | return; | 113 | return; | ||
127 | 114 | | |||
128 | beginInsertRows( QModelIndex(), rowCount(), rowCount()+list.count()-1 ); | 115 | beginInsertRows( QModelIndex(), rowCount(), rowCount()+list.count()-1 ); | ||
129 | d->m_events += list; | 116 | d->m_events += list; | ||
130 | endInsertRows(); | 117 | endInsertRows(); | ||
131 | } | 118 | } | ||
132 | 119 | | |||
133 | KDevelop::VcsEvent VcsEventModel::eventForIndex( const QModelIndex& idx ) const | 120 | KDevelop::VcsEvent VcsBasicEventModel::eventForIndex(const QModelIndex& idx) const | ||
134 | { | 121 | { | ||
135 | if( !idx.isValid() || idx.row() < 0 || idx.row() >= rowCount() ) | 122 | if( !idx.isValid() || idx.row() < 0 || idx.row() >= rowCount() ) | ||
136 | { | 123 | { | ||
137 | return KDevelop::VcsEvent(); | 124 | return KDevelop::VcsEvent(); | ||
138 | } | 125 | } | ||
139 | return d->m_events.at( idx.row() ); | 126 | return d->m_events.at( idx.row() ); | ||
140 | } | 127 | } | ||
141 | 128 | | |||
142 | bool VcsEventModel::canFetchMore(const QModelIndex& parent) const | 129 | class VcsEventLogModelPrivate | ||
130 | { | ||||
131 | public: | ||||
132 | KDevelop::IBasicVersionControl* m_iface; | ||||
133 | VcsRevision m_rev; | ||||
134 | QUrl m_url; | ||||
135 | bool done; | ||||
136 | bool fetching; | ||||
137 | }; | ||||
138 | | ||||
139 | VcsEventLogModel::VcsEventLogModel(KDevelop::IBasicVersionControl* iface, const VcsRevision& rev, const QUrl& url, QObject* parent) | ||||
140 | : KDevelop::VcsBasicEventModel(parent), d(new VcsEventLogModelPrivate) | ||||
141 | { | ||||
142 | d->m_iface = iface; | ||||
143 | d->m_rev = rev; | ||||
144 | d->m_url = url; | ||||
145 | d->done = false; | ||||
146 | d->fetching = false; | ||||
147 | } | ||||
148 | | ||||
149 | VcsEventLogModel::~VcsEventLogModel() = default; | ||||
150 | | ||||
151 | bool VcsEventLogModel::canFetchMore(const QModelIndex& parent) const | ||||
mwolff: QScopedPointer or unique_ptr | |||||
143 | { | 152 | { | ||
144 | return !d->done && !d->fetching && !parent.isValid(); | 153 | return !d->done && !d->fetching && !parent.isValid(); | ||
145 | } | 154 | } | ||
146 | 155 | | |||
147 | void VcsEventModel::fetchMore(const QModelIndex& parent) | 156 | void VcsEventLogModel::fetchMore(const QModelIndex& parent) | ||
148 | { | 157 | { | ||
149 | d->fetching = true; | 158 | d->fetching = true; | ||
150 | Q_ASSERT(!parent.isValid()); | 159 | Q_ASSERT(!parent.isValid()); | ||
151 | Q_UNUSED(parent); | 160 | Q_UNUSED(parent); | ||
152 | VcsJob* job = d->m_iface->log(d->m_url, d->m_rev, qMax(rowCount(), 100)); | 161 | VcsJob* job = d->m_iface->log(d->m_url, d->m_rev, qMax(rowCount(), 100)); | ||
153 | connect(this, &VcsEventModel::destroyed, job, [job] { job->kill(); }); | 162 | connect(this, &VcsEventLogModel::destroyed, job, [job] { job->kill(); }); | ||
154 | connect(job, &VcsJob::finished, this, &VcsEventModel::jobReceivedResults); | 163 | connect(job, &VcsJob::finished, this, &VcsEventLogModel::jobReceivedResults); | ||
155 | ICore::self()->runController()->registerJob( job ); | 164 | ICore::self()->runController()->registerJob( job ); | ||
156 | } | 165 | } | ||
157 | 166 | | |||
158 | void VcsEventModel::jobReceivedResults(KJob* job) | 167 | void VcsEventLogModel::jobReceivedResults(KJob* job) | ||
159 | { | 168 | { | ||
160 | QList<QVariant> l = qobject_cast<KDevelop::VcsJob *>(job)->fetchResults().toList(); | 169 | QList<QVariant> l = qobject_cast<KDevelop::VcsJob *>(job)->fetchResults().toList(); | ||
161 | if(l.isEmpty() || job->error()!=0) { | 170 | if(l.isEmpty() || job->error()!=0) { | ||
162 | d->done = true; | 171 | d->done = true; | ||
163 | return; | 172 | return; | ||
164 | } | 173 | } | ||
165 | QList<KDevelop::VcsEvent> newevents; | 174 | QList<KDevelop::VcsEvent> newevents; | ||
166 | foreach( const QVariant &v, l ) | 175 | foreach( const QVariant &v, l ) | ||
167 | { | 176 | { | ||
168 | if( v.canConvert<KDevelop::VcsEvent>() ) | 177 | if( v.canConvert<KDevelop::VcsEvent>() ) | ||
169 | { | 178 | { | ||
170 | newevents << v.value<KDevelop::VcsEvent>(); | 179 | newevents << v.value<KDevelop::VcsEvent>(); | ||
171 | } | 180 | } | ||
172 | } | 181 | } | ||
173 | d->m_rev = newevents.last().revision(); | 182 | d->m_rev = newevents.last().revision(); | ||
174 | if(!d->m_events.isEmpty()) { | 183 | if (rowCount()) { | ||
175 | newevents.removeFirst(); | 184 | newevents.removeFirst(); | ||
176 | } | 185 | } | ||
177 | d->done = newevents.isEmpty(); | 186 | d->done = newevents.isEmpty(); | ||
178 | addEvents( newevents ); | 187 | addEvents( newevents ); | ||
179 | d->fetching = false; | 188 | d->fetching = false; | ||
180 | } | 189 | } | ||
181 | 190 | | |||
182 | } | 191 | } | ||
183 | |
QScopedPointer or unique_ptr