| 158 | } |
| 159 | |
| 160 | void BatchEditValueLabelsDialog::save() const { |
| 161 | // remove all already available labels first |
| 162 | for (auto* column : m_columns) |
| 163 | column->valueLabelsRemoveAll(); |
| 164 | |
| 165 | // add new labels |
| 166 | const auto numberLocale = QLocale(); |
| 167 | QString label; |
| 168 | QString valueStr; |
| 169 | bool ok; |
| 170 | const auto mode = m_column->columnMode(); |
| 171 | const QString& text = teValueLabels->toPlainText(); |
| 172 | const auto& lines = text.split(QLatin1Char('\n')); |
| 173 | |
| 174 | for (const auto& line : lines) { |
| 175 | auto pair = line.split(QLatin1Char('=')); |
| 176 | if (pair.size() != 2) |
| 177 | continue; |
| 178 | |
| 179 | valueStr = pair.at(0).simplified(); |
| 180 | label = pair.at(1).simplified(); |
| 181 | if (valueStr.isEmpty() || label.isEmpty()) |
| 182 | continue; |
| 183 | |
| 184 | switch (mode) { |
| 185 | case AbstractColumn::ColumnMode::Double: { |
| 186 | double value = numberLocale.toDouble(valueStr, &ok); |
| 187 | if (!ok) |
| 188 | continue; |
| 189 | for (auto* col : m_columns) |
| 190 | col->addValueLabel(value, label); |
| 191 | break; |
| 192 | } |
| 193 | case AbstractColumn::ColumnMode::Integer: { |
| 194 | int value = numberLocale.toInt(valueStr, &ok); |
| 195 | if (!ok) |
| 196 | continue; |
| 197 | for (auto* col : m_columns) |
| 198 | col->addValueLabel(value, label); |
| 199 | break; |
| 200 | } |
| 201 | case AbstractColumn::ColumnMode::BigInt: { |
| 202 | qint64 value = numberLocale.toLongLong(valueStr, &ok); |
| 203 | if (!ok) |
| 204 | continue; |
| 205 | for (auto* col : m_columns) |
| 206 | col->addValueLabel(value, label); |
| 207 | break; |
| 208 | } |
| 209 | case AbstractColumn::ColumnMode::Text: { |
| 210 | for (auto* col : m_columns) |
| 211 | col->addValueLabel(valueStr, label); |
| 212 | break; |
| 213 | } |
| 214 | case AbstractColumn::ColumnMode::Month: |
| 215 | case AbstractColumn::ColumnMode::Day: |
| 216 | case AbstractColumn::ColumnMode::DateTime: { |
| 217 | const auto* filter = static_cast<DateTime2StringFilter*>(m_column->outputFilter()); |
no test coverage detected