dmflagshtmlgenerator.cpp
1 //------------------------------------------------------------------------------
2 // dmflagshtmlgenerator.cpp
3 //------------------------------------------------------------------------------
4 //
5 // This library is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU Lesser General Public
7 // License as published by the Free Software Foundation; either
8 // version 2.1 of the License, or (at your option) any later version.
9 //
10 // This library is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // Lesser General Public License for more details.
14 //
15 // You should have received a copy of the GNU Lesser General Public
16 // License along with this library; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18 // 02110-1301 USA
19 //
20 //------------------------------------------------------------------------------
21 // Copyright (C) 2010 "Zalewa" <zalewapl@gmail.com>
22 //------------------------------------------------------------------------------
23 #include "dmflagshtmlgenerator.h"
24 
25 #include "serverapi/server.h"
27 
28 DClass<DmflagsHtmlGenerator>
29 {
30  public:
31  ServerCPtr server;
32 
33  QString mkSectionContents(const DMFlagsSection &section)
34  {
35  QString result;
36  for (int i = 0; i < section.count(); ++i)
37  {
38  result += "<li>" + section[i].name() + "</li>";
39  }
40  return result;
41  }
42 };
43 
44 DPointered(DmflagsHtmlGenerator)
45 
46 DmflagsHtmlGenerator::DmflagsHtmlGenerator(const ServerCPtr &server)
47 {
48  d->server = server;
49 }
50 
51 DmflagsHtmlGenerator::~DmflagsHtmlGenerator()
52 {
53 }
54 
55 QString DmflagsHtmlGenerator::generate()
56 {
57  QString result;
58  const QList<DMFlagsSection> sections = d->server->dmFlags();
59  foreach(const DMFlagsSection &section, sections)
60  {
61  if (!section.isEmpty())
62  {
63  result += QString("<li><b>%1 (%2):</b></li>").arg(section.name()).arg(section.combineValues());
64  result += "<ul>";
65  result += d->mkSectionContents(section);
66  result += "</ul>";
67  }
68  }
69  if (!result.isEmpty())
70  {
71  result = "<ul>" + result + "</ul>";
72  }
73  return result;
74 }
A group of DMFlag objects that can be safely OR&#39;ed together to form a meaningful value.
int count() const
Number of DMFlag objects inside the collection.
unsigned combineValues() const
Logical OR of all DMFlag::value() results in this collection.
const QString & name() const
User-displayable name of this section, ex. "Compatibility flags".
bool isEmpty() const
Does this section contain any dmflag?