Isis 3.0 Programmer Reference
Back | Home
DisplayProperties.cpp
1 #include "DisplayProperties.h"
2 
3 #include <QBuffer>
4 #include <QDataStream>
5 #include <QXmlStreamWriter>
6 
7 #include "FileName.h"
8 #include "Pvl.h"
9 #include "XmlStackedHandlerReader.h"
10 
11 namespace Isis {
21  DisplayProperties::DisplayProperties(QString displayName, QObject *parent) :
22  QObject(parent) {
23 
24  m_propertiesUsed = 0;
26 
28  }
29 
30 
32  m_propertiesUsed = 0;
34 
35  xmlReader->pushContentHandler(new XmlHandler(this));
36  }
37 
38 
43  }
44 
45 
46  void DisplayProperties::fromPvl(const PvlObject &pvl) {
47  setDisplayName(((IString)pvl["DisplayName"][0]).ToQt());
48 
49  QByteArray hexValues(pvl["Values"][0].toLatin1());
50  QDataStream valuesStream(QByteArray::fromHex(hexValues));
51  valuesStream >> *m_propertyValues;
52  }
53 
54 
61  PvlObject output("DisplayProperties");
62  output += PvlKeyword("DisplayName", displayName());
63 
64  QBuffer dataBuffer;
65  dataBuffer.open(QIODevice::ReadWrite);
66 
67  QDataStream propsStream(&dataBuffer);
68  propsStream << *m_propertyValues;
69  dataBuffer.seek(0);
70 
71  output += PvlKeyword("Values", QString(dataBuffer.data().toHex()));
72 
73  return output;
74  }
75 
76 
81  return m_displayName;
82  }
83 
89  void DisplayProperties::setDisplayName(QString displayName) {
91  }
92 
93 
100  void DisplayProperties::addSupport(int property) {
101  if (!supports(property)) {
102  m_propertiesUsed = m_propertiesUsed | property;
103  emit supportAdded(property);
104  }
105  }
106 
107 
114  bool DisplayProperties::supports(int property) {
115  return (m_propertiesUsed & property) == property;
116  }
117 
118 
123  void DisplayProperties::setValue(int property, QVariant value) {
124  if ((*m_propertyValues)[property] != value) {
125  (*m_propertyValues)[property] = value;
126 
127  if (supports(property)) {
128  emit propertyChanged(this);
129  }
130  }
131  }
132 
133 
139  QVariant DisplayProperties::getValue(int property) const {
140  return (*m_propertyValues)[property];
141  }
142 
143 
151  void DisplayProperties::save(QXmlStreamWriter &stream, const Project *project,
152  FileName newProjectRoot) const {
153  stream.writeStartElement("displayProperties");
154 
155  stream.writeAttribute("displayName", displayName());
156 
157  // Get hex-encoded data
158  QBuffer dataBuffer;
159  dataBuffer.open(QIODevice::ReadWrite);
160  QDataStream propsStream(&dataBuffer);
161  propsStream << *m_propertyValues;
162  dataBuffer.seek(0);
163 
164  stream.writeCharacters(dataBuffer.data().toHex());
165 
166  stream.writeEndElement();
167  }
168 
169 
170  DisplayProperties::XmlHandler::XmlHandler(DisplayProperties *displayProperties) {
171  m_displayProperties = displayProperties;
172  }
173 
174 
175  bool DisplayProperties::XmlHandler::startElement(const QString &namespaceURI,
176  const QString &localName, const QString &qName, const QXmlAttributes &atts) {
177  if (XmlStackedHandler::startElement(namespaceURI, localName, qName, atts)) {
178  if (localName == "displayProperties") {
179  QString displayName = atts.value("displayName");
180 
181  if (!displayName.isEmpty()) {
182  m_displayProperties->setDisplayName(displayName);
183  }
184  }
185  }
186 
187  return true;
188  }
189 
190 
191  bool DisplayProperties::XmlHandler::characters(const QString &ch) {
192  m_hexData += ch;
193 
194  return XmlStackedHandler::characters(ch);
195  }
196 
197 
198  bool DisplayProperties::XmlHandler::endElement(const QString &namespaceURI,
199  const QString &localName, const QString &qName) {
200  if (localName == "displayProperties") {
201  QByteArray hexValues(m_hexData.toLatin1());
202  QDataStream valuesStream(QByteArray::fromHex(hexValues));
203  valuesStream >> *m_displayProperties->m_propertyValues;
204  }
205 
206  return XmlStackedHandler::endElement(namespaceURI, localName, qName);
207  }
208 }
209 
QVariant getValue(int property) const
Get a property&#39;s associated data.
bool supports(int property)
Support may come later, please make sure you are connected to the supportAdded signal.
PvlObject toPvl() const
Convert to Pvl for project files.
The main project for cnetsuite.
Definition: Project.h:105
File name manipulation and expansion.
Definition: FileName.h:111
QString m_displayName
This is the display name.
void setDisplayName(QString displayName)
Sets display name.
virtual ~DisplayProperties()
destructor
QString displayName() const
Returns the display name.
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...
A single keyword-value pair.
Definition: PvlKeyword.h:98
void setValue(int prop, QVariant value)
This is the generic mutator for properties.
DisplayProperties(QString displayName, QObject *parent=NULL)
DisplayProperties constructor.
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...
Adds specific functionality to C++ strings.
Definition: IString.h:179
Contains Pvl Groups and Pvl Objects.
Definition: PvlObject.h:74
void save(QXmlStreamWriter &stream, const Project *project, FileName newProjectRoot) const
Output format:
his enables stack-based XML parsing of XML files.

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 ISIS Support Center
File Modified: 07/12/2023 23:17:37