MCPcopy Create free account
hub / github.com/KDE/kdevelop / VcsAnnotationModelPrivate

Class VcsAnnotationModelPrivate

kdevplatform/vcs/models/vcsannotationmodel.cpp:29–73  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

27{
28
29class VcsAnnotationModelPrivate
30{
31public:
32 explicit VcsAnnotationModelPrivate( VcsAnnotationModel* q_ ) : q(q_) {}
33 KDevelop::VcsAnnotation m_annotation;
34 mutable QHash<KDevelop::VcsRevision, QBrush> m_brushes;
35 VcsAnnotationModel* q;
36 VcsJob* job;
37 QColor foreground;
38 QColor background;
39
40 const QBrush& brush(const VcsRevision& revision) const
41 {
42 auto brushIt = m_brushes.find(revision);
43 if (brushIt == m_brushes.end()) {
44 const int background_y = background.red()*0.299 + 0.587*background.green()
45 + 0.114*background.blue();
46 // get random, but reproducible 8-bit values from last two bytes of the revision hash
47 const auto revisionHash = qHash(revision);
48 const int u = static_cast<int>((0xFF & revisionHash));
49 const int v = static_cast<int>((0xFF00 & revisionHash) >> 8);
50 const int r = qRound(qMin(255.0, qMax(0.0, background_y + 1.402*(v-128))));
51 const int g = qRound(qMin(255.0, qMax(0.0, background_y - 0.344*(u-128) - 0.714*(v-128))));
52 const int b = qRound(qMin(255.0, qMax(0.0, background_y + 1.772*(u-128))));
53 brushIt = m_brushes.insert(revision, QBrush(QColor(r, g, b)));
54 }
55 return brushIt.value();
56 }
57
58 void addLines( KDevelop::VcsJob* job )
59 {
60 if( job == this->job )
61 {
62 const auto results = job->fetchResults().toList();
63 for (const QVariant& v : results) {
64 if( v.canConvert<KDevelop::VcsAnnotationLine>() )
65 {
66 VcsAnnotationLine l = v.value<KDevelop::VcsAnnotationLine>();
67 m_annotation.insertLine( l.lineNumber(), l );
68 emit q->lineChanged( l.lineNumber() );
69 }
70 }
71 }
72 }
73};
74
75VcsAnnotationModel::VcsAnnotationModel(VcsJob *job, const QUrl& url, QObject* parent,
76 const QColor &foreground, const QColor &background)

Callers

nothing calls this directly

Calls 6

QColorClass · 0.85
qHashFunction · 0.50
findMethod · 0.45
endMethod · 0.45
insertMethod · 0.45
valueMethod · 0.45

Tested by

no test coverage detected