Skip to content

Commit 43c2787

Browse files
committed
Use double in markers to cover the entire range of positions allowable in QML
1 parent f8a36ef commit 43c2787

File tree

3 files changed

+11
-11
lines changed

3 files changed

+11
-11
lines changed

src/marker.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,20 +26,20 @@
2626

2727
struct Marker {
2828
Q_GADGET
29-
Q_PROPERTY(int position MEMBER position)
29+
Q_PROPERTY(double position MEMBER position)
3030
Q_PROPERTY(int length MEMBER length)
3131
Q_PROPERTY(QString url MEMBER url)
3232
public:
3333
Marker() {
3434
position = 0;
3535
};
36-
explicit Marker(int p)
36+
explicit Marker(double p)
3737
{
3838
position = p;
3939
};
4040
// Contents
4141
QString text;
42-
int position = 0;
42+
double position = 0;
4343
int length = 1;
4444
int key = 0;
4545
QString keyLetter;

src/markersmodel.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -138,16 +138,16 @@ int MarkersModel::keySearch(int key, int currentPosition = 0, bool reverse = fal
138138
}
139139

140140
// Custom Recursive Binary Search: Returns most proximate element in a given direction when searched element is not found.
141-
Marker MarkersModel::binarySearch(const int l, const int r, const int goalPosition, const bool reverse = false)
141+
Marker MarkersModel::binarySearch(const double l, const double r, const double goalPosition, const bool reverse = false)
142142
{
143143
// qDebug() << "search in progress";
144144
if (r >= l) {
145145
// qDebug() << "l: " << l << ", r: " << r << ", gp: " << goalPosition;
146146

147147
// Binary search
148-
const int mid = l + (r - l) / 2;
148+
const double mid = l + (r - l) / 2;
149149

150-
const int aimValue = m_data.at(mid).position;
150+
const double aimValue = m_data.at(mid).position;
151151
// Base case
152152
if (aimValue == goalPosition) {
153153
// If last element
@@ -192,7 +192,7 @@ Marker MarkersModel::binarySearch(const int l, const int r, const int goalPositi
192192
return m_data.at(l);
193193
}
194194

195-
Marker MarkersModel::nextMarker(int position)
195+
Marker MarkersModel::nextMarker(double position)
196196
{
197197
// qDebug() << Qt::endl;
198198
const int size = rowCount();
@@ -204,7 +204,7 @@ Marker MarkersModel::nextMarker(int position)
204204
return invalidPositionMarker; // -1
205205
}
206206

207-
Marker MarkersModel::previousMarker(int position)
207+
Marker MarkersModel::previousMarker(double position)
208208
{
209209
// qDebug() << Qt::endl;
210210
const int size = rowCount();

src/markersmodel.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ class MarkersModel : public QAbstractListModel
6060
void clearMarkers();
6161
void appendMarker(const Marker &marker);
6262
void removeMarker(int row);
63-
Marker previousMarker(int position);
64-
Marker nextMarker(int position);
63+
Marker previousMarker(double position);
64+
Marker nextMarker(double position);
6565
int keySearch(int key, int currentPosition, bool reverse, bool wrap);
6666

6767
// void updateMarker(int row);
@@ -75,7 +75,7 @@ private Q_SLOTS:
7575
#else
7676
void resetInternalData();
7777
#endif
78-
Marker binarySearch(const int lo, const int hi, const int x, const bool reverse);
78+
Marker binarySearch(const double l, const double r, const double goalPosition, const bool reverse);
7979
};
8080

8181
#endif // MARKERSMODEL_H

0 commit comments

Comments
 (0)