diff options
Diffstat (limited to 'tests/hawd/formatter.cpp')
-rw-r--r-- | tests/hawd/formatter.cpp | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/tests/hawd/formatter.cpp b/tests/hawd/formatter.cpp new file mode 100644 index 0000000..9328d44 --- /dev/null +++ b/tests/hawd/formatter.cpp | |||
@@ -0,0 +1,52 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2015 Christian Mollekopf <mollekopf@kolabsys.com> | ||
3 | * | ||
4 | * This program is free software; you can redistribute it and/or modify | ||
5 | * it under the terms of the GNU General Public License as published by | ||
6 | * the Free Software Foundation; either version 2 of the License, or | ||
7 | * (at your option) any later version. | ||
8 | * | ||
9 | * This program is distributed in the hope that it will be useful, | ||
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | * GNU General Public License for more details. | ||
13 | * | ||
14 | * You should have received a copy of the GNU General Public License | ||
15 | * along with this program; if not, write to the | ||
16 | * Free Software Foundation, Inc., | ||
17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
18 | */ | ||
19 | |||
20 | #include "formatter.h" | ||
21 | |||
22 | #include <QDir> | ||
23 | #include <QObject> | ||
24 | |||
25 | #include <iostream> | ||
26 | |||
27 | namespace HAWD | ||
28 | { | ||
29 | |||
30 | void Formatter::print(const QString &datasetName, const QStringList &cols, State &state) | ||
31 | { | ||
32 | QDir project(state.projectPath()); | ||
33 | Dataset dataset(datasetName, state); | ||
34 | |||
35 | if (!dataset.isValid()) { | ||
36 | std::cout << QObject::tr("The dataset %1 could not be loaded; try checking it with the check command").arg(datasetName).toStdString() << std::endl; | ||
37 | return; | ||
38 | } | ||
39 | print(dataset); | ||
40 | } | ||
41 | |||
42 | void Formatter::print(Dataset &dataset, const QStringList &cols) | ||
43 | { | ||
44 | QStringList cols; | ||
45 | std::cout << dataset.tableHeaders(cols).toStdString() << std::endl; | ||
46 | dataset.eachRow( | ||
47 | [cols](const Dataset::Row &row) { | ||
48 | std::cout << row.toString(cols).toStdString() << std::endl; | ||
49 | }); | ||
50 | } | ||
51 | |||
52 | } | ||