File failed to load: https://isis.astrogeology.usgs.gov/6.0.0/Object/assets/jax/output/NativeMML/config.js
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 
19 namespace Isis {
29  DisplayProperties::DisplayProperties(QString displayName, QObject *parent) :
30  QObject(parent) {
31 
32  m_propertiesUsed = 0;
34 
36  }
37 
38 
40  m_propertiesUsed = 0;
42 
43  xmlReader->pushContentHandler(new XmlHandler(this));
44  }
45 
46 
51  }
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)) {
110  m_propertiesUsed = m_propertiesUsed | 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 }
Isis::PvlObject
Contains Pvl Groups and Pvl Objects.
Definition: PvlObject.h:61
Isis::PvlKeyword
A single keyword-value pair.
Definition: PvlKeyword.h:82
Isis::FileName
File name manipulation and expansion.
Definition: FileName.h:100
Isis::XmlStackedHandlerReader::pushContentHandler
virtual void pushContentHandler(XmlStackedHandler *newHandler)
Push a contentHandler and maybe continue parsing...
Definition: XmlStackedHandlerReader.cpp:55
Isis::DisplayProperties
Definition: DisplayProperties.h:34
Isis::DisplayProperties::addSupport
void addSupport(int property)
Call this with every property you support, otherwise they will not communicate properly between widge...
Definition: DisplayProperties.cpp:108
Isis::DisplayProperties::setValue
void setValue(int prop, QVariant value)
This is the generic mutator for properties.
Definition: DisplayProperties.cpp:131
Isis::DisplayProperties::m_propertiesUsed
int m_propertiesUsed
This indicated whether any widgets with this DisplayProperties is using a particulay property.
Definition: DisplayProperties.h:102
Isis::DisplayProperties::DisplayProperties
DisplayProperties(QString displayName, QObject *parent=NULL)
DisplayProperties constructor.
Definition: DisplayProperties.cpp:29
Isis::XmlStackedHandlerReader
Manage a stack of content handlers for reading XML files.
Definition: XmlStackedHandlerReader.h:30
Isis::Project
The main project for ipce.
Definition: Project.h:289
Isis::DisplayProperties::supports
bool supports(int property)
Support may come later, please make sure you are connected to the supportAdded signal.
Definition: DisplayProperties.cpp:122
Isis::DisplayProperties::displayName
QString displayName() const
Returns the display name.
Definition: DisplayProperties.cpp:88
Isis::DisplayProperties::m_displayName
QString m_displayName
This is the display name.
Definition: DisplayProperties.h:95
Isis::DisplayProperties::toPvl
PvlObject toPvl() const
Convert to Pvl for project files.
Definition: DisplayProperties.cpp:68
QMap< int, QVariant >
Isis::IString
Adds specific functionality to C++ strings.
Definition: IString.h:165
QObject
Isis::DisplayProperties::save
void save(QXmlStreamWriter &stream, const Project *project, FileName newProjectRoot) const
Output format:
Definition: DisplayProperties.cpp:159
Isis::DisplayProperties::getValue
QVariant getValue(int property) const
Get a property's associated data.
Definition: DisplayProperties.cpp:147
Isis::DisplayProperties::m_propertyValues
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...
Definition: DisplayProperties.h:108
Isis::DisplayProperties::setDisplayName
void setDisplayName(QString displayName)
Sets display name.
Definition: DisplayProperties.cpp:97
Isis::DisplayProperties::~DisplayProperties
virtual ~DisplayProperties()
destructor
Definition: DisplayProperties.cpp:50
Isis
This is free and unencumbered software released into the public domain.
Definition: Apollo.h:16

U.S. Department of the Interior | U.S. Geological Survey
ISIS | Privacy & Disclaimers | Astrogeology Research Program
To contact us, please post comments and questions on the USGS Astrogeology Discussion Board
To report a bug, or suggest a feature go to: ISIS Github
File Modified: 07/13/2023 15:16:24