Commit d0108d29 authored by Krzysztof Kurek's avatar Krzysztof Kurek Committed by Dmitry Kazakov

Fix the TestKistSwatchGroup test

KisSwatchGroup now inserts the new KisSwatch into the first position not
containing a valid KisSwatch.

CCBUG: 410387
parent 5f783c40
...@@ -24,20 +24,13 @@ ...@@ -24,20 +24,13 @@
struct KisSwatchGroup::Private { struct KisSwatchGroup::Private {
typedef QMap<int, KisSwatch> Column; typedef QMap<int, KisSwatch> Column;
Private()
: name(QString())
, colorMatrix(DEFAULT_COLUMN_COUNT)
, colorCount(0)
, rowCount(DEFAULT_ROW_COUNT)
{ }
static int DEFAULT_COLUMN_COUNT; static int DEFAULT_COLUMN_COUNT;
static int DEFAULT_ROW_COUNT; static int DEFAULT_ROW_COUNT;
QString name; QString name {QString()};
QVector<Column> colorMatrix; QVector<Column> colorMatrix {DEFAULT_COLUMN_COUNT};
int colorCount; int colorCount {0};
int rowCount; int rowCount {DEFAULT_ROW_COUNT};
}; };
int KisSwatchGroup::Private::DEFAULT_COLUMN_COUNT = 16; int KisSwatchGroup::Private::DEFAULT_COLUMN_COUNT = 16;
...@@ -47,8 +40,7 @@ KisSwatchGroup::KisSwatchGroup() ...@@ -47,8 +40,7 @@ KisSwatchGroup::KisSwatchGroup()
: d(new Private) : d(new Private)
{ } { }
KisSwatchGroup::~KisSwatchGroup() KisSwatchGroup::~KisSwatchGroup() = default;
{ }
KisSwatchGroup::KisSwatchGroup(const KisSwatchGroup &rhs) KisSwatchGroup::KisSwatchGroup(const KisSwatchGroup &rhs)
: d(new Private(*rhs.d)) : d(new Private(*rhs.d))
...@@ -89,7 +81,7 @@ bool KisSwatchGroup::checkEntry(int column, int row) const ...@@ -89,7 +81,7 @@ bool KisSwatchGroup::checkEntry(int column, int row) const
return false; return false;
} }
if (row >= d->colorMatrix[column].size()) { if (!d->colorMatrix[column].contains(row)) {
return false; return false;
} }
...@@ -149,32 +141,17 @@ void KisSwatchGroup::addEntry(const KisSwatch &e) ...@@ -149,32 +141,17 @@ void KisSwatchGroup::addEntry(const KisSwatch &e)
setColumnCount(Private::DEFAULT_COLUMN_COUNT); setColumnCount(Private::DEFAULT_COLUMN_COUNT);
} }
if (d->colorCount == 0) {
setEntry(e, 0, 0);
return;
}
int y = 0; int y = 0;
for (const Private::Column &c : d->colorMatrix) { int x = 0;
if (c.isEmpty()) { continue; } while(checkEntry(x, y))
if (y < c.lastKey()) { {
y = c.lastKey(); if(++x == d->colorMatrix.size())
} {
} x = 0;
for (int x = d->colorMatrix.size() - 1; x >= 0; x--) { ++y;
if (checkEntry(x, y)) {
// if the last entry's at the rightmost column,
// add e to the leftmost column of the next row
// and increase row count
if (++x == d->colorMatrix.size()) {
x = 0;
y++;
}
// else just add it to the right
setEntry(e, x, y);
break;
} }
} }
setEntry(e, x, y);
} }
void KisSwatchGroup::clear() void KisSwatchGroup::clear()
......
...@@ -79,12 +79,12 @@ void TestKisSwatchGroup::testAddEntry() ...@@ -79,12 +79,12 @@ void TestKisSwatchGroup::testAddEntry()
g2.setColumnCount(3); g2.setColumnCount(3);
g2.setRowCount(1); g2.setRowCount(1);
for (int i = 0; i != 3; i++) { for (int i = 0; i != 3; i++) {
g2.addEntry(KisSwatch()); g2.addEntry(KisSwatch(KoColor()));
} }
QCOMPARE(g2.rowCount(), 1); QCOMPARE(g2.rowCount(), 1);
QCOMPARE(g2.columnCount(), 3); QCOMPARE(g2.columnCount(), 3);
QCOMPARE(g2.colorCount(), 3); QCOMPARE(g2.colorCount(), 3);
g2.addEntry(KisSwatch()); g2.addEntry(KisSwatch(KoColor()));
QCOMPARE(g2.rowCount(), 2); QCOMPARE(g2.rowCount(), 2);
QCOMPARE(g2.columnCount(), 3); QCOMPARE(g2.columnCount(), 3);
QCOMPARE(g2.colorCount(), 4); QCOMPARE(g2.colorCount(), 4);
...@@ -93,7 +93,7 @@ void TestKisSwatchGroup::testAddEntry() ...@@ -93,7 +93,7 @@ void TestKisSwatchGroup::testAddEntry()
QCOMPARE(g2.columnCount(), 3); QCOMPARE(g2.columnCount(), 3);
QCOMPARE(g2.colorCount(), 3); QCOMPARE(g2.colorCount(), 3);
for (int i = 0; i != 4; i++) { for (int i = 0; i != 4; i++) {
g2.addEntry(KisSwatch()); g2.addEntry(KisSwatch(KoColor()));
} }
QCOMPARE(g2.rowCount(), 3); QCOMPARE(g2.rowCount(), 3);
QCOMPARE(g2.columnCount(), 3); QCOMPARE(g2.columnCount(), 3);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment