summaryrefslogtreecommitdiffstats
path: root/src/preferences
diff options
context:
space:
mode:
authorSwiftb0y <12380386+Swiftb0y@users.noreply.github.com>2021-04-15 22:21:09 +0200
committerSwiftb0y <12380386+Swiftb0y@users.noreply.github.com>2021-04-15 22:21:09 +0200
commitc2f56686b7d9ba392384f36b045384698eab0af1 (patch)
tree97ecf0142d85157b01297abbf3af39f2a5e3c00c /src/preferences
parentf2d9a3938f2bdfde2b47d2cbe8ca0b2b3dba4a44 (diff)
ColorPaletteEditorModel move rangelist to own file
Diffstat (limited to 'src/preferences')
-rw-r--r--src/preferences/colorpaletteeditormodel.cpp86
1 files changed, 3 insertions, 83 deletions
diff --git a/src/preferences/colorpaletteeditormodel.cpp b/src/preferences/colorpaletteeditormodel.cpp
index 0ad70dd3fd..3e0ba2d794 100644
--- a/src/preferences/colorpaletteeditormodel.cpp
+++ b/src/preferences/colorpaletteeditormodel.cpp
@@ -1,11 +1,11 @@
#include "preferences/colorpaletteeditormodel.h"
#include <util/assert.h>
+#include <util/rangelist.h>
#include <QList>
#include <QMap>
#include <QMultiMap>
-#include <QRegularExpression>
#include <algorithm>
#include "engine/controls/cuecontrol.h"
@@ -13,86 +13,6 @@
namespace {
-const QString kGroupSeparator = QStringLiteral(", ");
-const QString kRangeSeparator = QStringLiteral(" - ");
-// when changing groupSeparator or rangeSeparator, rangeListMatchingRegex must
-// be adjusted as well.
-const QRegularExpression kRangeListMatchingRegex(
- QStringLiteral("(?:(\\d+)(?:\\s*-\\s*(\\d+))?)[\\s,]*"));
-
-/// parses a comma-separated list of positive ints and range if ints (eg `n - m`)
-/// and returns a sorted list of all the ints described.
-/// inverse counterpart of `stringifyRangeList`
-QList<int> parseRangeList(const QString& input) {
- QList<int> intList;
- auto matchGroups = kRangeListMatchingRegex.globalMatch(input);
- while (matchGroups.hasNext()) {
- const auto group = matchGroups.next();
- const QString rangeStart = group.captured(1);
- const QString rangeEnd = group.captured(2);
- bool startOk, endOk;
- int startIndex = rangeStart.toInt(&startOk);
- if (!startOk) {
- continue;
- }
- int endIndex = rangeEnd.toInt(&endOk);
- if (!endOk) {
- endIndex = startIndex;
- }
- for (int currentIndex = startIndex; currentIndex <= endIndex; currentIndex++) {
- intList.append(currentIndex);
- }
- }
-
- std::sort(intList.begin(), intList.end());
- const auto end = std::unique(intList.begin(), intList.end());
- intList.erase(end, intList.end());
-
- return intList;
-}
-
-/// take a list of positive integers and stringify them into a neat
-/// user friendly representation (eg {1, 2, 3} => "1 - 3").
-/// inverse counterpart of `parseRangeList`.
-/// rangeList must be sorted!
-QString stringifyRangeList(const QList<int>& rangeList) {
- DEBUG_ASSERT(std::is_sorted(rangeList.cbegin(), rangeList.cend()));
-
- QString stringifiedRangeList;
-
- for (int i = 0; i < rangeList.size();) {
- int rangeStartIndex = i;
- int rangeStartValue = rangeList.at(i);
-
- while (i < rangeList.size() && rangeList.at(i) == rangeStartValue + (i - rangeStartIndex)) {
- i++;
- }
-
- int rangeEndIndex = i - 1;
-
- stringifiedRangeList += QString::number(rangeStartValue);
-
- switch (rangeEndIndex - rangeStartIndex) {
- case 0:
- // not a range
- break;
- case 1:
- // treat ranges of (i..i+1) as separate groups: "i, i+1"
- stringifiedRangeList += kGroupSeparator + QString::number(rangeList.at(rangeEndIndex));
- break;
- default:
- // range where the end is >=2 than the start
- stringifiedRangeList += kRangeSeparator + QString::number(rangeList.at(rangeEndIndex));
- break;
- }
-
- if (i < rangeList.size()) {
- stringifiedRangeList += kGroupSeparator;
- }
- }
- return stringifiedRangeList;
-}
-
QIcon toQIcon(const QColor& color) {
QPixmap pixmap(50, 50);
pixmap.fill(color);
@@ -264,7 +184,7 @@ QVariant HotcueIndexListItem::data(int role) const {
switch (role) {
case Qt::DisplayRole:
case Qt::EditRole: {
- return QVariant(stringifyRangeList(m_hotcueIndexList));
+ return QVariant(mixxx::stringifyRangeList(m_hotcueIndexList));
break;
}
default:
@@ -276,7 +196,7 @@ QVariant HotcueIndexListItem::data(int role) const {
void HotcueIndexListItem::setData(const QVariant& value, int role) {
switch (role) {
case Qt::EditRole: {
- QList<int> newHotcueIndicies = parseRangeList(value.toString());
+ QList<int> newHotcueIndicies = mixxx::parseRangeList(value.toString());
if (m_hotcueIndexList != newHotcueIndicies) {
m_hotcueIndexList = newHotcueIndicies;