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
18namespace Isis {
28 DisplayProperties::DisplayProperties(QString displayName, QObject *parent) :
29 QObject(parent) {
30
32 m_propertyValues = new QMap<int, QVariant>;
33
35 }
36
37
43
44
45 void DisplayProperties::fromPvl(const PvlObject &pvl) {
46 setDisplayName(((IString)pvl["DisplayName"][0]).ToQt());
47
48 QByteArray hexValues(pvl["Values"][0].toLatin1());
49 QDataStream valuesStream(QByteArray::fromHex(hexValues));
50 valuesStream >> *m_propertyValues;
51 }
52
53
60 PvlObject output("DisplayProperties");
61 output += PvlKeyword("DisplayName", displayName());
62
63 QBuffer dataBuffer;
64 dataBuffer.open(QIODevice::ReadWrite);
65
66 QDataStream propsStream(&dataBuffer);
67 propsStream << *m_propertyValues;
68 dataBuffer.seek(0);
69
70 output += PvlKeyword("Values", QString(dataBuffer.data().toHex()));
71
72 return output;
73 }
74
75
80 return m_displayName;
81 }
82
88 void DisplayProperties::setDisplayName(QString displayName) {
90 }
91
92
99 void DisplayProperties::addSupport(int property) {
100 if (!supports(property)) {
102 emit supportAdded(property);
103 }
104 }
105
106
113 bool DisplayProperties::supports(int property) {
114 return (m_propertiesUsed & property) == property;
115 }
116
117
122 void DisplayProperties::setValue(int property, QVariant value) {
123 if ((*m_propertyValues)[property] != value) {
124 (*m_propertyValues)[property] = value;
125
126 if (supports(property)) {
127 emit propertyChanged(this);
128 }
129 }
130 }
131
132
138 QVariant DisplayProperties::getValue(int property) const {
139 return (*m_propertyValues)[property];
140 }
141
142
150 void DisplayProperties::save(QXmlStreamWriter &stream, const Project *project,
151 FileName newProjectRoot) const {
152 stream.writeStartElement("displayProperties");
153
154 stream.writeAttribute("displayName", displayName());
155
156 // Get hex-encoded data
157 QBuffer dataBuffer;
158 dataBuffer.open(QIODevice::ReadWrite);
159 QDataStream propsStream(&dataBuffer);
160 propsStream << *m_propertyValues;
161 dataBuffer.seek(0);
162
163 stream.writeCharacters(dataBuffer.data().toHex());
164
165 stream.writeEndElement();
166 }
167}
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:287
A single keyword-value pair.
Definition PvlKeyword.h:87
Contains Pvl Groups and Pvl Objects.
Definition PvlObject.h:61
This is free and unencumbered software released into the public domain.
Definition Apollo.h:16