Engauge Digitizer 2
Loading...
Searching...
No Matches
PointIdentifiers.cpp
Go to the documentation of this file.
1/******************************************************************************************************
2 * (C) 2014 markummitchell@github.com. This file is part of Engauge Digitizer, which is released *
3 * under GNU General Public License version 2 (GPLv2) or (at your option) any later version. See file *
4 * LICENSE or go to gnu.org/licenses for details. Distribution requires prior written permission. *
5 ******************************************************************************************************/
6
7#include "DocumentSerialize.h"
8#include "EngaugeAssert.h"
9#include "Logger.h"
10#include "PointIdentifiers.h"
11#include <QObject>
12#include <QXmlStreamReader>
13#include <QXmlStreamWriter>
14#include "Xml.h"
15
19
21{
22 LOG4CPP_DEBUG_S ((*mainCat)) << "PointIdentifiers::contains"
23 << " pointCount=" << m_pointIdentifiers.count();
24
25 return m_pointIdentifiers.contains (pointIdentifier);
26}
27
29{
30 return m_pointIdentifiers.count();
31}
32
34{
35 ENGAUGE_ASSERT (i < m_pointIdentifiers.count());
36
37 QList<QString> keys = m_pointIdentifiers.keys();
38
39 return keys.at(i);
40}
41
43{
44 ENGAUGE_ASSERT (m_pointIdentifiers.contains (pointIdentifier));
45
46 return m_pointIdentifiers [pointIdentifier];
47}
48
50{
51 bool success = true;
52
53 // Read through each DOCUMENT_SERIALIZE_POINT_IDENTIFIER until end of DOCUMENT_SERIALIZE_POINT_IDENTIFIERS is encountered
54 while (loadNextFromReader (reader)) {
55
56 if (reader.atEnd() || reader.hasError ()) {
57 success = false;
58 break;
59 }
60
61 if ((reader.tokenType() == QXmlStreamReader::EndElement) &&
63 break;
64 }
65
66 // Not done yet
67 if ((reader.tokenType() == QXmlStreamReader::StartElement) &&
69
70 // This is an entry that we need to add
72
75
77
78 QString identifier = attributes.value (DOCUMENT_SERIALIZE_POINT_IDENTIFIER_NAME).toString();
80
81 m_pointIdentifiers [identifier] = value;
82 }
83 }
84 }
85
86 if (!success) {
87 reader.raiseError (QObject::tr ("Cannot read point identifiers"));
88 }
89}
90
92{
94 PointIdentifiersInternal::const_iterator itr;
95 for (itr = m_pointIdentifiers.begin(); itr != m_pointIdentifiers.end (); itr++) {
96 QString identifier = itr.key();
97 bool value = itr.value();
99 writer.writeAttribute(DOCUMENT_SERIALIZE_POINT_IDENTIFIER_NAME, identifier);
102 writer.writeEndElement();
103 }
104 writer.writeEndElement();
105}
106
108 bool value)
109{
110 m_pointIdentifiers [pointIdentifier] = value;
111}
const int INNER_RADIUS_MIN
const QString DOCUMENT_SERIALIZE_POINT_IDENTIFIERS
const QString DOCUMENT_SERIALIZE_POINT_IDENTIFIER
const QString DOCUMENT_SERIALIZE_POINT_IDENTIFIER_VALUE
const QString DOCUMENT_SERIALIZE_POINT_IDENTIFIER_NAME
const QString DOCUMENT_SERIALIZE_BOOL_TRUE
const QString DOCUMENT_SERIALIZE_BOOL_FALSE
#define ENGAUGE_ASSERT(cond)
Drop in replacement for Q_ASSERT if defined(QT_NO_DEBUG) && !defined(QT_FORCE_ASSERTS) define ENGAUGE...
log4cpp::Category * mainCat
Definition Logger.cpp:14
QXmlStreamReader::TokenType loadNextFromReader(QXmlStreamReader &reader)
Load next token from xml reader.
Definition Xml.cpp:14
bool contains(const QString &pointIdentifier) const
True if specified entry exists in the table.
PointIdentifiers()
Single constructor.
QString getKey(int i) const
Get key for index.
void loadXml(QXmlStreamReader &reader)
Load from serialized xml.
int count() const
Number of entries.
bool getValue(const QString &pointIdentifier) const
Get value for key.
void setKeyValue(const QString &pointIdentifier, bool value)
Set key/value pair.
void saveXml(QXmlStreamWriter &writer) const
Serialize table to xml.
#define LOG4CPP_DEBUG_S(logger)
Definition convenience.h:20