mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-27 11:05:44 +08:00
Function QStringList -> HTML table
This commit is contained in:
41
src/blackmisc/htmlutils.cpp
Normal file
41
src/blackmisc/htmlutils.cpp
Normal file
@@ -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 <QStringBuilder>
|
||||||
|
#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("<tr>");
|
||||||
|
for (int c = 0; c < columns; c++)
|
||||||
|
{
|
||||||
|
if (i < size)
|
||||||
|
{
|
||||||
|
html += QStringLiteral("<td>") % values.at(i) % QStringLiteral("</td>");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
html += QStringLiteral("<td></td>");
|
||||||
|
}
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
html += QStringLiteral("</tr>");
|
||||||
|
}
|
||||||
|
return QStringLiteral("<table>") % html % QStringLiteral("</table>");
|
||||||
|
}
|
||||||
|
} // ns
|
||||||
@@ -12,10 +12,10 @@
|
|||||||
#ifndef BLACKMISC_HTMLUTILS_H
|
#ifndef BLACKMISC_HTMLUTILS_H
|
||||||
#define BLACKMISC_HTMLUTILS_H
|
#define BLACKMISC_HTMLUTILS_H
|
||||||
|
|
||||||
|
#include <QStringBuilder>
|
||||||
#include "blackmisc/blackmiscexport.h"
|
#include "blackmisc/blackmiscexport.h"
|
||||||
#include "blackmisc/propertyindexlist.h"
|
#include "blackmisc/propertyindexlist.h"
|
||||||
|
|
||||||
|
|
||||||
//! Free functions in BlackMisc
|
//! Free functions in BlackMisc
|
||||||
namespace BlackMisc
|
namespace BlackMisc
|
||||||
{
|
{
|
||||||
@@ -29,12 +29,16 @@ namespace BlackMisc
|
|||||||
QString rowHtml;
|
QString rowHtml;
|
||||||
for (const CPropertyIndex &index : indexes)
|
for (const CPropertyIndex &index : indexes)
|
||||||
{
|
{
|
||||||
rowHtml += "<td>" + obj.propertyByIndex(index).toQString(true) + "</td>";
|
rowHtml += QStringLiteral("<td>") % obj.propertyByIndex(index).toQString(true) % QStringLiteral("</td>");
|
||||||
}
|
}
|
||||||
html += "<tr>" + rowHtml + "</tr>";
|
html += QStringLiteral("<tr>") % rowHtml % QStringLiteral("</tr>");
|
||||||
}
|
}
|
||||||
return "<table>" + html + "</table>";
|
return QStringLiteral("<table>") % html % QStringLiteral("</table>");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//! Values as HTML table
|
||||||
|
BLACKMISC_EXPORT QString toHtmTable(const QStringList &values, int columns);
|
||||||
|
|
||||||
} // ns
|
} // ns
|
||||||
|
|
||||||
#endif // guard
|
#endif // guard
|
||||||
|
|||||||
Reference in New Issue
Block a user