diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2015-08-07 18:43:03 +0200 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2015-08-07 18:43:03 +0200 |
commit | b6e7be78f3e13275a8f217a4e01b304d97538641 (patch) | |
tree | ace45830fa61a930aecb4d73051fcbdc1a99559c | |
parent | a6959d8414da1efbe90e7dbc364bffb6658bba74 (diff) | |
download | sink-b6e7be78f3e13275a8f217a4e01b304d97538641.tar.gz sink-b6e7be78f3e13275a8f217a4e01b304d97538641.zip |
HAWD::Formatter to print dataset
-rw-r--r-- | tests/hawd/CMakeLists.txt | 1 | ||||
-rw-r--r-- | tests/hawd/formatter.cpp | 52 | ||||
-rw-r--r-- | tests/hawd/formatter.h | 37 |
3 files changed, 90 insertions, 0 deletions
diff --git a/tests/hawd/CMakeLists.txt b/tests/hawd/CMakeLists.txt index 84c41ab..071f2ba 100644 --- a/tests/hawd/CMakeLists.txt +++ b/tests/hawd/CMakeLists.txt | |||
@@ -12,6 +12,7 @@ set(lib_SRCS | |||
12 | dataset.cpp | 12 | dataset.cpp |
13 | datasetdefinition.cpp | 13 | datasetdefinition.cpp |
14 | state.cpp | 14 | state.cpp |
15 | formatter.cpp | ||
15 | ) | 16 | ) |
16 | 17 | ||
17 | set(SRCS | 18 | set(SRCS |
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 | } | ||
diff --git a/tests/hawd/formatter.h b/tests/hawd/formatter.h new file mode 100644 index 0000000..6a53bb2 --- /dev/null +++ b/tests/hawd/formatter.h | |||
@@ -0,0 +1,37 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2015 Christian Mollekopf <mollekopf@kolabsys.com> | ||
3 | * | ||
4 | * This library is free software; you can redistribute it and/or | ||
5 | * modify it under the terms of the GNU Lesser General Public | ||
6 | * License as published by the Free Software Foundation; either | ||
7 | * version 2.1 of the License, or (at your option) version 3, or any | ||
8 | * later version accepted by the membership of KDE e.V. (or its | ||
9 | * successor approved by the membership of KDE e.V.), which shall | ||
10 | * act as a proxy defined in Section 6 of version 3 of the license. | ||
11 | * | ||
12 | * This library is distributed in the hope that it will be useful, | ||
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
15 | * Lesser General Public License for more details. | ||
16 | * | ||
17 | * You should have received a copy of the GNU Lesser General Public | ||
18 | * License along with this library. If not, see <http://www.gnu.org/licenses/>. | ||
19 | */ | ||
20 | |||
21 | #pragma once | ||
22 | |||
23 | #include "hawd_export.h" | ||
24 | #include "state.h" | ||
25 | #include "dataset.h" | ||
26 | |||
27 | namespace HAWD | ||
28 | { | ||
29 | |||
30 | class HAWD_EXPORT Formatter | ||
31 | { | ||
32 | public: | ||
33 | static void print(const QString &datasetName, const QStringList &cols, State &state); | ||
34 | static void print(Dataset &dataset, const QStringList &cols = QStringList()); | ||
35 | }; | ||
36 | |||
37 | } | ||