From 4ba8d7a758f10178fc310fedba3e847f95a75c3f Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Sat, 6 Oct 2018 04:32:32 +0200 Subject: [PATCH] Function QStringList -> HTML table --- src/blackmisc/htmlutils.cpp | 41 +++++++++++++++++++++++++++++++++++++ src/blackmisc/htmlutils.h | 12 +++++++---- 2 files changed, 49 insertions(+), 4 deletions(-) create mode 100644 src/blackmisc/htmlutils.cpp diff --git a/src/blackmisc/htmlutils.cpp b/src/blackmisc/htmlutils.cpp new file mode 100644 index 000000000..5af0c2610 --- /dev/null +++ b/src/blackmisc/htmlutils.cpp @@ -0,0 +1,41 @@ +/* Copyright (C) 2018 + * swift project Community / Contributors + * + * This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level + * directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project, + * including this file, may be copied, modified, propagated, or distributed except according to the terms + * contained in the LICENSE file. + */ + +#include +#include "htmlutils.h" + +namespace BlackMisc +{ + QString toHtmTable(const QStringList &values, int columns) + { + if (values.isEmpty() || columns < 1) { return QStringLiteral(""); } + + QString html; + QString row; + const int size = values.size(); + for (int i = 0; i < size; i++) + { + html += QStringLiteral(""); + for (int c = 0; c < columns; c++) + { + if (i < size) + { + html += QStringLiteral("") % values.at(i) % QStringLiteral(""); + } + else + { + html += QStringLiteral(""); + } + i++; + } + html += QStringLiteral(""); + } + return QStringLiteral("") % html % QStringLiteral("
"); + } +} // ns diff --git a/src/blackmisc/htmlutils.h b/src/blackmisc/htmlutils.h index cac04ecf7..76c6e07eb 100644 --- a/src/blackmisc/htmlutils.h +++ b/src/blackmisc/htmlutils.h @@ -12,10 +12,10 @@ #ifndef BLACKMISC_HTMLUTILS_H #define BLACKMISC_HTMLUTILS_H +#include #include "blackmisc/blackmiscexport.h" #include "blackmisc/propertyindexlist.h" - //! Free functions in BlackMisc namespace BlackMisc { @@ -29,12 +29,16 @@ namespace BlackMisc QString rowHtml; for (const CPropertyIndex &index : indexes) { - rowHtml += "" + obj.propertyByIndex(index).toQString(true) + ""; + rowHtml += QStringLiteral("") % obj.propertyByIndex(index).toQString(true) % QStringLiteral(""); } - html += "" + rowHtml + ""; + html += QStringLiteral("") % rowHtml % QStringLiteral(""); } - return "" + html + "
"; + return QStringLiteral("") % html % QStringLiteral("
"); } + + //! Values as HTML table + BLACKMISC_EXPORT QString toHtmTable(const QStringList &values, int columns); + } // ns #endif // guard