~ubuntu-branches/ubuntu/saucy/merkaartor/saucy

« back to all changes in this revision

Viewing changes to src/Preferences/WmsServersList.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Bernd Zeimetz
  • Date: 2009-09-13 00:52:12 UTC
  • mto: (1.2.7 upstream) (0.1.3 upstream) (3.1.7 sid)
  • mto: This revision was merged to the branch mainline in revision 10.
  • Revision ID: james.westby@ubuntu.com-20090913005212-pjecal8zxm07x0fj
ImportĀ upstreamĀ versionĀ 0.14+svnfixes~20090912

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//
 
2
// C++ Implementation: WMSServersList
 
3
//
 
4
// Description:
 
5
//
 
6
//
 
7
// Author: cbro <cbro@semperpax.com>, (C) 2009
 
8
//
 
9
// Copyright: See COPYING file that comes with this distribution
 
10
//
 
11
//
 
12
 
 
13
#include <QApplication>
 
14
 
 
15
#include "WmsServersList.h"
 
16
#include "Preferences/MerkaartorPreferences.h"
 
17
 
 
18
WmsServer::WmsServer()
 
19
{
 
20
        WmsServer(QApplication::translate("MerkaartorPreferences","New Server"), "", "", "", "", "", "");
 
21
}
 
22
 
 
23
WmsServer::WmsServer(const WmsServer& other)
 
24
        : WmsName(other.WmsName), WmsAdress(other.WmsAdress), WmsPath(other.WmsPath), WmsLayers(other.WmsLayers), 
 
25
                WmsProjections(other.WmsProjections), WmsStyles(other.WmsStyles), WmsImgFormat(other.WmsImgFormat), deleted(other.deleted)
 
26
{
 
27
}
 
28
 
 
29
WmsServer::WmsServer(QString Name, QString Adress, QString Path, QString Layers, QString Projections, QString Styles, QString ImgFormat, bool Deleted)
 
30
        : WmsName(Name), WmsAdress(Adress), WmsPath(Path), WmsLayers(Layers), WmsProjections(Projections), WmsStyles(Styles), WmsImgFormat(ImgFormat), deleted(Deleted)
 
31
{
 
32
        if (Name == "") {
 
33
                WmsName = QApplication::translate("MerkaartorPreferences","New Server");
 
34
        }
 
35
}
 
36
 
 
37
void WmsServer::toXml(QDomElement parent)
 
38
{
 
39
        QDomElement p = parent.ownerDocument().createElement("WmsServer");
 
40
        parent.appendChild(p);
 
41
        p.setAttribute("name", WmsName);
 
42
        p.setAttribute("address", WmsAdress);
 
43
        p.setAttribute("path", WmsPath);
 
44
        p.setAttribute("layers", WmsLayers);
 
45
        p.setAttribute("projections", WmsProjections);
 
46
        p.setAttribute("styles", WmsStyles);
 
47
        p.setAttribute("format", WmsImgFormat);
 
48
        if (deleted)
 
49
                p.setAttribute("deleted", "true");
 
50
}
 
51
 
 
52
WmsServer WmsServer::fromXml(QDomElement parent)
 
53
{
 
54
        WmsServer theServer;
 
55
 
 
56
        if (parent.tagName() == "WmsServer") {
 
57
                theServer.WmsName = parent.attribute("name");
 
58
                theServer.WmsAdress = parent.attribute("address");
 
59
                theServer.WmsPath = parent.attribute("path");
 
60
                theServer.WmsLayers = parent.attribute("layers");
 
61
                theServer.WmsProjections = parent.attribute("projections");
 
62
                theServer.WmsStyles = parent.attribute("styles");
 
63
                theServer.WmsImgFormat = parent.attribute("format");
 
64
                theServer.deleted = (parent.attribute("deleted") == "true" ? true : false);
 
65
        }
 
66
 
 
67
        return theServer;
 
68
}
 
69
 
 
70
/** **/
 
71
 
 
72
void WmsServersList::add(WmsServersList aWmsServersList)
 
73
{
 
74
        QMapIterator <QString, WmsServer> it(*(aWmsServersList.getServers()));
 
75
        while (it.hasNext()) {
 
76
                it.next();
 
77
 
 
78
                WmsServer anItem = it.value();
 
79
                theServers.insert(anItem.WmsName, anItem);
 
80
        }
 
81
}
 
82
 
 
83
WmsServerList* WmsServersList::getServers()
 
84
{
 
85
        return &theServers;
 
86
}
 
87
 
 
88
void WmsServersList::addServer(WmsServer aServer)
 
89
{
 
90
        theServers.insert(aServer.WmsName, aServer);
 
91
}
 
92
 
 
93
bool WmsServersList::contains(QString name) const
 
94
{
 
95
        if (theServers.contains(name))
 
96
                return true;
 
97
        else {
 
98
                WmsServerListIterator it(theServers);
 
99
                while (it.hasNext()) {
 
100
                        it.next();
 
101
 
 
102
                        if (it.key().contains(name, Qt::CaseInsensitive))
 
103
                                return true;
 
104
                }
 
105
        }
 
106
        return false;
 
107
}
 
108
 
 
109
WmsServer WmsServersList::getServer(QString name) const
 
110
{
 
111
        if (theServers.contains(name))
 
112
                return theServers.value(name);
 
113
        else {
 
114
                WmsServerListIterator it(theServers);
 
115
                while (it.hasNext()) {
 
116
                        it.next();
 
117
 
 
118
                        if (it.key().contains(name, Qt::CaseInsensitive))
 
119
                                return it.value();
 
120
                }
 
121
        }
 
122
        return WmsServer();
 
123
}
 
124
 
 
125
void WmsServersList::toXml(QDomElement parent)
 
126
{
 
127
        QDomElement rt = parent.ownerDocument().createElement("WmsServers");
 
128
        parent.appendChild(rt);
 
129
        rt.setAttribute("creator", QString("Merkaartor v%1%2").arg(STRINGIFY(VERSION)).arg(STRINGIFY(REVISION)));
 
130
 
 
131
        WmsServerListIterator it(theServers);
 
132
        while (it.hasNext()) {
 
133
                it.next();
 
134
 
 
135
                WmsServer i = it.value();
 
136
                i.toXml(rt);
 
137
        }
 
138
}
 
139
 
 
140
WmsServersList WmsServersList::fromXml(QDomElement parent)
 
141
{
 
142
        WmsServersList theServersList;
 
143
 
 
144
        if (parent.nodeName() == "WmsServers") {
 
145
                QDomElement c = parent.firstChildElement();
 
146
                while(!c.isNull()) {
 
147
                        if (c.tagName() == "WmsServer") {
 
148
                                theServersList.addServer(WmsServer::fromXml(c));
 
149
                        } 
 
150
 
 
151
                        c = c.nextSiblingElement();
 
152
                }
 
153
        }
 
154
 
 
155
        return theServersList;
 
156
}