Isis 3 Programmer Reference
DisplayProperties.cpp
1
7/* SPDX-License-Identifier: CC0-1.0 */
8
9#include "DisplayProperties.h"
10
11#include <QBuffer>
12#include <QDataStream>
13#include <QXmlStreamWriter>
14
15#include "FileName.h"
16#include "Pvl.h"
17#include "XmlStackedHandlerReader.h"
18
19namespace Isis {
29 DisplayProperties::DisplayProperties(QString displayName, QObject *parent) :
30 QObject(parent) {
31
33 m_propertyValues = new QMap<int, QVariant>;
34
36 }
37
38
41 m_propertyValues = new QMap<int, QVariant>;
42
43 xmlReader->pushContentHandler(new XmlHandler(this));
44 }
45
46
52
53
54 void DisplayProperties::fromPvl(const PvlObject &pvl) {
55 setDisplayName(((IString)pvl["DisplayName"][0]).ToQt());
56
57 QByteArray hexValues(pvl["Values"][0].toLatin1());
58 QDataStream valuesStream(QByteArray::fromHex(hexValues));
59 valuesStream >> *m_propertyValues;
60 }
61
62
69 PvlObject output("DisplayProperties");
70 output += PvlKeyword("DisplayName", displayName());
71
72 QBuffer dataBuffer;
73 dataBuffer.open(QIODevice::ReadWrite);
74
75 QDataStream propsStream(&dataBuffer);
76 propsStream << *m_propertyValues;
77 dataBuffer.seek(0);
78
79 output += PvlKeyword("Values", QString(dataBuffer.data().toHex()));
80
81 return output;
82 }
83
84
89 return m_displayName;
90 }
91
97 void DisplayProperties::setDisplayName(QString displayName) {
99 }
100
101
108 void DisplayProperties::addSupport(int property) {
109 if (!supports(property)) {
111 emit supportAdded(property);
112 }
113 }
114
115
122 bool DisplayProperties::supports(int property) {
123 return (m_propertiesUsed & property) == property;
124 }
125
126
131 void DisplayProperties::setValue(int property, QVariant value) {
132 if ((*m_propertyValues)[property] != value) {
133 (*m_propertyValues)[property] = value;
134
135 if (supports(property)) {
136 emit propertyChanged(this);
137 }
138 }
139 }
140
141
147 QVariant DisplayProperties::getValue(int property) const {
148 return (*m_propertyValues)[property];
149 }
150
151
159 void DisplayProperties::save(QXmlStreamWriter &stream, const Project *project,
160 FileName newProjectRoot) const {
161 stream.writeStartElement("displayProperties");
162
163 stream.writeAttribute("displayName", displayName());
164
165 // Get hex-encoded data
166 QBuffer dataBuffer;
167 dataBuffer.open(QIODevice::ReadWrite);
168 QDataStream propsStream(&dataBuffer);
169 propsStream << *m_propertyValues;
170 dataBuffer.seek(0);
171
172 stream.writeCharacters(dataBuffer.data().toHex());
173
174 stream.writeEndElement();
175 }
176
177
178 DisplayProperties::XmlHandler::XmlHandler(DisplayProperties *displayProperties) {
179 m_displayProperties = displayProperties;
180 }
181
182
183 bool DisplayProperties::XmlHandler::startElement(const QString &namespaceURI,
184 const QString &localName, const QString &qName, const QXmlAttributes &atts) {
185 if (XmlStackedHandler::startElement(namespaceURI, localName, qName, atts)) {
186 if (localName == "displayProperties") {
187 QString displayName = atts.value("displayName");
188
189 if (!displayName.isEmpty()) {
190 m_displayProperties->setDisplayName(displayName);
191 }
192 }
193 }
194
195 return true;
196 }
197
198
199 bool DisplayProperties::XmlHandler::characters(const QString &ch) {
200 m_hexData += ch;
201
202 return XmlStackedHandler::characters(ch);
203 }
204
205
206 bool DisplayProperties::XmlHandler::endElement(const QString &namespaceURI,
207 const QString &localName, const QString &qName) {
208 if (localName == "displayProperties") {
209 QByteArray hexValues(m_hexData.toLatin1());
210 QDataStream valuesStream(QByteArray::fromHex(hexValues));
211 valuesStream >> *m_displayProperties->m_propertyValues;
212 }
213
214 return XmlStackedHandler::endElement(namespaceURI, localName, qName);
215 }
216}
QMap< int, QVariant > * m_propertyValues
This is a map from Property to value – the reason I use an int is so Qt knows how to serialize this Q...
QVariant getValue(int property) const
Get a property's associated data.
QString displayName() const
Returns the display name.
void save(QXmlStreamWriter &stream, const Project *project, FileName newProjectRoot) const
Output format:
void setDisplayName(QString displayName)
Sets display name.
void setValue(int prop, QVariant value)
This is the generic mutator for properties.
virtual ~DisplayProperties()
destructor
PvlObject toPvl() const
Convert to Pvl for project files.
QString m_displayName
This is the display name.
DisplayProperties(QString displayName, QObject *parent=NULL)
DisplayProperties constructor.
bool supports(int property)
Support may come later, please make sure you are connected to the supportAdded signal.
void addSupport(int property)
Call this with every property you support, otherwise they will not communicate properly between widge...
int m_propertiesUsed
This indicated whether any widgets with this DisplayProperties is using a particulay property.
File name manipulation and expansion.
Definition FileName.h:100
Adds specific functionality to C++ strings.
Definition IString.h:165
The main project for ipce.
Definition Project.h:289
A single keyword-value pair.
Definition PvlKeyword.h:87
Contains Pvl Groups and Pvl Objects.
Definition PvlObject.h:61
Manage a stack of content handlers for reading XML files.
This is free and unencumbered software released into the public domain.
Definition Apollo.h:16