diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2015-12-01 21:29:42 +0100 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2015-12-01 21:29:42 +0100 |
commit | 93b406d1914a5512aec6ca737ba8326a21191227 (patch) | |
tree | 0f869f201815ae862bc2853de0b2007ff1515bf1 /tests/hawd/dataset.cpp | |
parent | ae7cc26c8350b427870f83687f83184c2c211250 (diff) | |
download | sink-93b406d1914a5512aec6ca737ba8326a21191227.tar.gz sink-93b406d1914a5512aec6ca737ba8326a21191227.zip |
HAWD: Ensure the column order is maintained
By turning the columns into an array instead of an object,
we can print the values in the same order as in the definition file.
Previosly the order was random, and even headers and values were
somtimes mixed up.
Diffstat (limited to 'tests/hawd/dataset.cpp')
-rw-r--r-- | tests/hawd/dataset.cpp | 43 |
1 files changed, 21 insertions, 22 deletions
diff --git a/tests/hawd/dataset.cpp b/tests/hawd/dataset.cpp index 585406b..93eb5cd 100644 --- a/tests/hawd/dataset.cpp +++ b/tests/hawd/dataset.cpp | |||
@@ -49,10 +49,8 @@ Dataset::Row::Row(const Dataset &dataset, qint64 key) | |||
49 | m_dataset(&dataset) | 49 | m_dataset(&dataset) |
50 | { | 50 | { |
51 | // TODO: pre-populate m_data, or do that on buffer creation? | 51 | // TODO: pre-populate m_data, or do that on buffer creation? |
52 | QHashIterator<QString, DataDefinition> it(dataset.definition().columns()); | 52 | for (const auto &colum : dataset.definition().columns()) { |
53 | while (it.hasNext()) { | 53 | m_data.insert(colum.first, QVariant()); |
54 | it.next(); | ||
55 | m_data.insert(it.key(), QVariant()); | ||
56 | } | 54 | } |
57 | } | 55 | } |
58 | 56 | ||
@@ -67,13 +65,16 @@ Dataset::Row &Dataset::Row::operator=(const Row &rhs) | |||
67 | return *this; | 65 | return *this; |
68 | } | 66 | } |
69 | 67 | ||
70 | void Dataset::Row::setValue(const QString &column, const QVariant &value) | 68 | void Dataset::Row::setValue(const QString &col, const QVariant &value) |
71 | { | 69 | { |
72 | if (!m_columns.contains(column) || !value.canConvert(m_columns[column].type())) { | 70 | for (const auto &column : m_columns) { |
73 | return; | 71 | if (column.first == col) { |
72 | if (value.canConvert(column.second.type())) { | ||
73 | m_data[col] = value; | ||
74 | } | ||
75 | return; | ||
76 | } | ||
74 | } | 77 | } |
75 | |||
76 | m_data[column] = value; | ||
77 | } | 78 | } |
78 | 79 | ||
79 | void Dataset::Row::annotate(const QString ¬e) | 80 | void Dataset::Row::annotate(const QString ¬e) |
@@ -158,13 +159,11 @@ QString Dataset::tableHeaders(const QStringList &cols, int standardCols, const Q | |||
158 | strings << QObject::tr("Commit").leftJustified(s_fieldWidth, ' '); | 159 | strings << QObject::tr("Commit").leftJustified(s_fieldWidth, ' '); |
159 | } | 160 | } |
160 | 161 | ||
161 | QHashIterator<QString, DataDefinition> it(m_definition.columns()); | 162 | for (const auto &column : m_definition.columns()) { |
162 | while (it.hasNext()) { | 163 | QString header = column.first; |
163 | it.next(); | ||
164 | QString header = it.key(); | ||
165 | if (cols.isEmpty() || cols.contains(header)) { | 164 | if (cols.isEmpty() || cols.contains(header)) { |
166 | if (!it.value().unit().isEmpty()) { | 165 | if (!column.second.unit().isEmpty()) { |
167 | header.append(" (").append(it.value().unit()).append(")"); | 166 | header.append(" (").append(column.second.unit()).append(")"); |
168 | } | 167 | } |
169 | strings << header.leftJustified(s_fieldWidth, ' '); | 168 | strings << header.leftJustified(s_fieldWidth, ' '); |
170 | } | 169 | } |
@@ -195,14 +194,14 @@ QString Dataset::Row::toString(const QStringList &cols, int standardCols, const | |||
195 | strings << m_commitHash.leftJustified(s_fieldWidth, ' '); | 194 | strings << m_commitHash.leftJustified(s_fieldWidth, ' '); |
196 | } | 195 | } |
197 | 196 | ||
198 | QHashIterator<QString, QVariant> it(m_data); | 197 | for (const auto &column : m_columns) { |
199 | while (it.hasNext()) { | 198 | const auto key = column.first; |
200 | it.next(); | 199 | if (cols.isEmpty() || cols.contains(key)) { |
201 | if (cols.isEmpty() || cols.contains(it.key())) { | 200 | const auto value = m_data.value(key); |
202 | if (it.value().canConvert<double>()) { | 201 | if (value.canConvert<double>()) { |
203 | strings << QString("%1").arg(it.value().toDouble(), s_fieldWidth, 'f', 3); | 202 | strings << QString("%1").arg(value.toDouble(), s_fieldWidth, 'f', 3); |
204 | } else { | 203 | } else { |
205 | strings << it.value().toString().leftJustified(s_fieldWidth, ' '); | 204 | strings << value.toString().leftJustified(s_fieldWidth, ' '); |
206 | } | 205 | } |
207 | } | 206 | } |
208 | } | 207 | } |