Skip to content

Commit 2065e25

Browse files
authored
Merge pull request #183 from bobhairgrove/master
2nd try -- …An effort at improvements towards const correctness.
2 parents 01021b2 + 1feaab8 commit 2065e25

File tree

8 files changed

+99
-89
lines changed

8 files changed

+99
-89
lines changed

src/chunks.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ bool Chunks::setIODevice(QIODevice &ioDevice)
6262

6363
// ***************************************** Getting data out of Chunks
6464

65-
QByteArray Chunks::data(qint64 pos, qint64 maxSize, QByteArray *highlighted)
65+
QByteArray Chunks::data(qint64 pos, qint64 maxSize, QByteArray *highlighted) const
6666
{
6767
qint64 ioDelta = 0;
6868
int chunkIdx = 0;
@@ -147,7 +147,7 @@ QByteArray Chunks::data(qint64 pos, qint64 maxSize, QByteArray *highlighted)
147147
return buffer;
148148
}
149149

150-
bool Chunks::write(QIODevice &iODevice, qint64 pos, qint64 count)
150+
bool Chunks::write(QIODevice &iODevice, qint64 pos, qint64 count) const
151151
{
152152
if (count == -1)
153153
count = _size;
@@ -176,7 +176,7 @@ void Chunks::setDataChanged(qint64 pos, bool dataChanged)
176176
_chunks[chunkIdx].dataChanged[(int)posInBa] = char(dataChanged);
177177
}
178178

179-
bool Chunks::dataChanged(qint64 pos)
179+
bool Chunks::dataChanged(qint64 pos) const
180180
{
181181
foreach (Chunk chunk, _chunks)
182182
{
@@ -191,7 +191,7 @@ bool Chunks::dataChanged(qint64 pos)
191191

192192
// ***************************************** Search API
193193

194-
qint64 Chunks::indexOf(const QByteArray &ba, qint64 from)
194+
qint64 Chunks::indexOf(const QByteArray &ba, qint64 from) const
195195
{
196196
qint64 result = -1;
197197
QByteArray buffer;
@@ -206,7 +206,7 @@ qint64 Chunks::indexOf(const QByteArray &ba, qint64 from)
206206
return result;
207207
}
208208

209-
qint64 Chunks::lastIndexOf(const QByteArray &ba, qint64 from)
209+
qint64 Chunks::lastIndexOf(const QByteArray &ba, qint64 from) const
210210
{
211211
qint64 result = -1;
212212
QByteArray buffer;
@@ -276,22 +276,22 @@ bool Chunks::removeAt(qint64 pos)
276276

277277
// ***************************************** Utility functions
278278

279-
char Chunks::operator[](qint64 pos)
279+
char Chunks::operator[](qint64 pos) const
280280
{
281281
return data(pos, 1).at(0);
282282
}
283283

284-
qint64 Chunks::pos()
284+
qint64 Chunks::pos() const
285285
{
286286
return _pos;
287287
}
288288

289-
qint64 Chunks::size()
289+
qint64 Chunks::size() const
290290
{
291291
return _size;
292292
}
293293

294-
int Chunks::getChunkIndex(qint64 absPos)
294+
int Chunks::getChunkIndex(qint64 absPos) const
295295
{
296296
// This routine checks, if there is already a copied chunk available. If os, it
297297
// returns a reference to it. If there is no copied chunk available, original

src/chunks.h

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -54,35 +54,35 @@ Q_OBJECT
5454
bool setIODevice(QIODevice &ioDevice);
5555

5656
// Getting data out of Chunks
57-
QByteArray data(qint64 pos=0, qint64 count=-1, QByteArray *highlighted=0);
58-
bool write(QIODevice &iODevice, qint64 pos=0, qint64 count=-1);
57+
QByteArray data(qint64 pos=0, qint64 count=-1, QByteArray *highlighted=0) const;
58+
bool write(QIODevice &iODevice, qint64 pos=0, qint64 count=-1) const;
5959

6060
// Set and get highlighting infos
6161
void setDataChanged(qint64 pos, bool dataChanged);
62-
bool dataChanged(qint64 pos);
62+
bool dataChanged(qint64 pos) const;
6363

6464
// Search API
65-
qint64 indexOf(const QByteArray &ba, qint64 from);
66-
qint64 lastIndexOf(const QByteArray &ba, qint64 from);
65+
qint64 indexOf(const QByteArray &ba, qint64 from) const;
66+
qint64 lastIndexOf(const QByteArray &ba, qint64 from) const;
6767

6868
// Char manipulations
6969
bool insert(qint64 pos, char b);
7070
bool overwrite(qint64 pos, char b);
7171
bool removeAt(qint64 pos);
7272

7373
// Utility functions
74-
char operator[](qint64 pos);
75-
qint64 pos();
76-
qint64 size();
74+
char operator[](qint64 pos) const;
75+
qint64 pos() const;
76+
qint64 size() const;
7777

7878

7979
private:
80-
int getChunkIndex(qint64 absPos);
80+
int getChunkIndex(qint64 absPos) const;
8181

8282
QIODevice * _ioDevice;
8383
qint64 _pos;
8484
qint64 _size;
85-
QList<Chunk> _chunks;
85+
mutable QList<Chunk> _chunks;
8686

8787
#ifdef MODUL_TEST
8888
public:

src/color_manager.cpp

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,12 @@ ColoredArea::ColoredArea(qint64 posStart, qint64 posEnd, QPen pen, QBrush backgr
4747
_areaStyle = background;
4848
}
4949

50-
QPen ColoredArea::fontPen()
50+
QPen ColoredArea::fontPen() const
5151
{
5252
return _fontColor;
5353
}
5454

55-
QColor ColoredArea::fontColor()
55+
QColor ColoredArea::fontColor() const
5656
{
5757
return _fontColor.color();
5858
}
@@ -62,12 +62,12 @@ void ColoredArea::setFontColor(QColor color)
6262
_fontColor = QPen(color);
6363
}
6464

65-
QColor ColoredArea::areaColor()
65+
QColor ColoredArea::areaColor() const
6666
{
6767
return _areaStyle.color();
6868
}
6969

70-
QBrush ColoredArea::areaStyle()
70+
QBrush ColoredArea::areaStyle() const
7171
{
7272
return _areaStyle;
7373
}
@@ -82,21 +82,21 @@ void ColoredArea::setAreaStyle(QBrush backround)
8282
_areaStyle = backround;
8383
}
8484

85-
qint64 ColoredArea::posStart()
85+
qint64 ColoredArea::posStart() const
8686
{
8787
return _posStart;
88-
};
88+
}
8989

90-
qint64 ColoredArea::posEnd()
90+
qint64 ColoredArea::posEnd() const
9191
{
9292
return _posEnd;
93-
};
93+
}
9494

9595
void ColoredArea::setRange(qint64 posStart, qint64 posEnd)
9696
{
9797
_posStart = posStart;
9898
_posEnd = posEnd;
99-
};
99+
}
100100

101101
void ColoredArea::clear()
102102
{
@@ -111,7 +111,7 @@ ColorManager::ColorManager()
111111
{
112112
QPalette palette = qApp->palette();
113113
setPalette(palette);
114-
};
114+
}
115115

116116
void ColorManager::setPalette(const QPalette &palette)
117117
{
@@ -123,7 +123,7 @@ void ColorManager::setPalette(const QPalette &palette)
123123
}
124124

125125
// read only, copy of relevant ColoredArea is returned: you can't change anything
126-
ColoredArea ColorManager::markedArea(qint64 pos, Area area, Chunks *chunks)
126+
ColoredArea ColorManager::markedArea(qint64 pos, Area area, Chunks *chunks) const
127127
{
128128
// prio 1 selection
129129
if (pos >= _selection.posStart() && pos < _selection.posEnd())
@@ -145,9 +145,9 @@ ColoredArea ColorManager::markedArea(qint64 pos, Area area, Chunks *chunks)
145145
}
146146
// nothing found -> standard colors
147147
return this->notMarked(area);
148-
};
148+
}
149149

150-
ColoredArea& ColorManager::notMarked(Area area)
150+
const ColoredArea &ColorManager::notMarked(Area area) const
151151
{
152152
switch (area) {
153153
case Area::Address:
@@ -163,15 +163,25 @@ ColoredArea& ColorManager::notMarked(Area area)
163163
return _hex; // should never happen
164164
}
165165

166-
ColoredArea& ColorManager::selection()
166+
const ColoredArea &ColorManager::selection() const
167+
{
168+
return _selection;
169+
}
170+
171+
ColoredArea &ColorManager::selection()
167172
{
168173
return _selection;
169-
};
174+
}
175+
176+
const ColoredArea& ColorManager::highlighting() const
177+
{
178+
return _highlighting;
179+
}
170180

171181
ColoredArea& ColorManager::highlighting()
172182
{
173183
return _highlighting;
174-
};
184+
}
175185

176186
void ColorManager::addUserArea(qint64 posStart, qint64 posEnd, QColor fontColor, QBrush areaStyle)
177187
{
@@ -182,4 +192,4 @@ void ColorManager::addUserArea(qint64 posStart, qint64 posEnd, QColor fontColor,
182192
void ColorManager::clearUserAreas()
183193
{
184194
_userAreas.clear();
185-
}
195+
}

src/color_manager.h

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -47,25 +47,25 @@ enum Area {
4747
class ColoredArea
4848
{
4949
public:
50-
// Cunstructors
50+
// Constructors
5151
ColoredArea();
5252
ColoredArea(QPen pen, QBrush background);
5353
ColoredArea(qint64 posStart, qint64 posEnd, QPen pen, QBrush background);
5454

5555
// Property to set/get font color
56-
QColor fontColor();
56+
QColor fontColor() const;
5757
void setFontColor(QColor color);
5858

5959
// Property to set/get area style
60-
QColor areaColor();
61-
QBrush areaStyle();
60+
QColor areaColor() const;
61+
QBrush areaStyle() const;
6262
void setAreaColor(QColor color);
6363
void setAreaStyle(QBrush background);
6464

6565
// other Methods to acces and set internal data
66-
QPen fontPen();
67-
qint64 posStart();
68-
qint64 posEnd();
66+
QPen fontPen() const;
67+
qint64 posStart() const;
68+
qint64 posEnd() const;
6969
void setRange(qint64 posStart, qint64 posEnd);
7070
void clear();
7171

@@ -87,15 +87,17 @@ class ColorManager
8787
void setPalette(const QPalette &palette);
8888

8989
// Method returns color definitions for data at position pos in area area
90-
ColoredArea markedArea(qint64 pos, Area area, Chunks *chunks);
90+
ColoredArea markedArea(qint64 pos, Area area, Chunks *chunks) const;
9191

9292
// Method returns standard collors (without marking)
93-
ColoredArea& notMarked(Area);
93+
const ColoredArea& notMarked(Area) const;
9494

9595
// Get the selection color definitions
96+
const ColoredArea& selection() const;
9697
ColoredArea& selection();
9798

9899
// Get the highlighting color definitions
100+
const ColoredArea& highlighting() const;
99101
ColoredArea& highlighting();
100102

101103
// Add a user defined area
@@ -116,4 +118,4 @@ class ColorManager
116118

117119
/** \endcond docNever */
118120

119-
#endif // COLOR_MANAGER_H
121+
#endif // COLOR_MANAGER_H

src/commands.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,6 @@ UndoStack::UndoStack(Chunks * chunks, QObject * parent)
113113
: QUndoStack(parent)
114114
{
115115
_chunks = chunks;
116-
_parent = parent;
117116
this->setUndoLimit(1000);
118117
}
119118

src/commands.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ class UndoStack : public QUndoStack
5757

5858
private:
5959
Chunks * _chunks;
60-
QObject * _parent;
6160
};
6261

6362
/** \endcond docNever */

0 commit comments

Comments
 (0)