Warning, file /pim/sink/tests/hawd/formatter.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 /* 0002 * Copyright (C) 2015 Christian Mollekopf <mollekopf@kolabsys.com> 0003 * 0004 * This program is free software; you can redistribute it and/or modify 0005 * it under the terms of the GNU General Public License as published by 0006 * the Free Software Foundation; either version 2 of the License, or 0007 * (at your option) any later version. 0008 * 0009 * This program is distributed in the hope that it will be useful, 0010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0012 * GNU General Public License for more details. 0013 * 0014 * You should have received a copy of the GNU General Public License 0015 * along with this program; if not, write to the 0016 * Free Software Foundation, Inc., 0017 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 0018 */ 0019 0020 #include "formatter.h" 0021 0022 #include <QDir> 0023 #include <QObject> 0024 0025 #include <iostream> 0026 0027 namespace HAWD 0028 { 0029 0030 void Formatter::print(const QString &datasetName, const QStringList &cols, State &state) 0031 { 0032 QDir project(state.projectPath()); 0033 Dataset dataset(datasetName, state); 0034 0035 if (!dataset.isValid()) { 0036 std::cout << QObject::tr("The dataset %1 could not be loaded; try checking it with the check command").arg(datasetName).toStdString() << std::endl; 0037 return; 0038 } 0039 print(dataset, cols); 0040 } 0041 0042 void Formatter::print(Dataset &dataset, const QStringList &cols) 0043 { 0044 std::cout << dataset.tableHeaders(cols).toStdString() << std::endl; 0045 //Just reading doesn't sort the rows, let's use a map 0046 QMap<qint64, QString> rows; 0047 dataset.eachRow( 0048 [cols, &rows](const Dataset::Row &row) { 0049 rows.insert(row.key(), row.toString()); 0050 }); 0051 for (const auto &s : rows.values().mid(rows.size() - 3)) { 0052 std::cout << s.toStdString() << std::endl; 0053 } 0054 } 0055 0056 }