Isis 3.0 Programmer Reference
Back | Home
GuiCameraDisplayProperties.cpp
2 
3 #include <QAction>
4 #include <QBitArray>
5 #include <QBuffer>
6 #include <QColorDialog>
7 #include <QDebug>
8 #include <QInputDialog>
9 #include <QMap>
10 #include <QVariant>
11 #include <QXmlStreamWriter>
12 
13 #include "FileName.h"
14 #include "Pvl.h"
15 #include "XmlStackedHandlerReader.h"
16 
17 namespace Isis {
25  DisplayProperties(displayName, parent) {
26 
29 
30  // set all of the defaults to prevent unwanted change signals from
31  // being emitted later.
32  setShowLabel(false);
33  setSelected(false);
34 
35  setValue(Color, QVariant::fromValue(randomColor()));
36  }
37 
38 
46  QObject *parent) : DisplayProperties("", parent) {
49 
50  xmlReader->pushContentHandler(new XmlHandler(this));
51  }
52 
53 
58  }
59 
60 
61 // void GuiCameraDisplayProperties::fromPvl(const PvlObject &pvl) {
62 // m_displayName = ((IString)pvl["DisplayName"][0]).ToQt();
63 
64 // QByteArray hexValues(pvl["Values"][0].c_str());
65 // QDataStream valuesStream(QByteArray::fromHex(hexValues));
66 // valuesStream >> *m_propertyValues;
67 // }
68 
69 
70 // /**
71 // * Convert to Pvl for project files. This stores all of the data associated
72 // * with all of the properties (but not what is supported). This also s tores
73 // * the target filename.
74 // */
75 // PvlObject GuiCameraDisplayProperties::toPvl() const {
76 // PvlObject output("DisplayProperties");
77 // output += PvlKeyword("DisplayName", m_displayName);
78 
79 // QBuffer dataBuffer;
80 // dataBuffer.open(QIODevice::ReadWrite);
81 
82 // QDataStream propsStream(&dataBuffer);
83 // propsStream << *m_propertyValues;
84 // dataBuffer.seek(0);
85 
86 // output += PvlKeyword("Values", QString(dataBuffer.data().toHex()));
87 
88 // return output;
89 // }
90 
91 
99  if (!supports(prop)) {
101  emit supportAdded(prop);
102  }
103  }
104 
105 
113  return (m_propertiesUsed & prop) == prop;
114  }
115 
116 
123  return (*m_propertyValues)[prop];
124  }
125 
126 
133  // Gives a random number between 0 and 255
134  int red = 0;
135  int green = 0;
136  int blue = 0;
137 
138  // Generate dark
139  while(red + green + blue < 300) {
140  red = rand() % 256;
141  green = rand() % 256;
142  blue = rand() % 256;
143  }
144 
145  return QColor(red, green, blue, 60);
146  }
147 
148 
155  void GuiCameraDisplayProperties::save(QXmlStreamWriter &stream, const Project *project,
156  FileName newProjectRoot) const {
157  stream.writeStartElement("displayProperties");
158 
159  stream.writeAttribute("displayName", displayName());
160 
161  // Get hex-encoded data
162  QBuffer dataBuffer;
163  dataBuffer.open(QIODevice::ReadWrite);
164  QDataStream propsStream(&dataBuffer);
165  propsStream << *m_propertyValues;
166  dataBuffer.seek(0);
167 
168  stream.writeCharacters(dataBuffer.data().toHex());
169 
170  stream.writeEndElement();
171  }
172 
173 
178  void GuiCameraDisplayProperties::setColor(QColor newColor) {
179  setValue(Color, QVariant::fromValue(newColor));
180  }
181 
182 
188  setValue(Selected, newValue);
189  }
190 
191 
197  setValue(ShowLabel, newValue);
198  }
199 
200 
208 
209  bool value = getValue(ShowLabel).toBool();
210  value = !value;
211 
213  foreach(display, displays) {
214  display->setShowLabel(value);
215  }
216  }
217 
218 
225  m_displayProperties = displayProperties;
226  }
227 
228 
244  const QString &localName, const QString &qName, const QXmlAttributes &atts) {
245  if (XmlStackedHandler::startElement(namespaceURI, localName, qName, atts)) {
246  if (localName == "displayProperties") {
247  QString displayName = atts.value("displayName");
248 
249  if (!displayName.isEmpty()) {
250  m_displayProperties->setDisplayName(displayName);
251  }
252  }
253  }
254 
255  return true;
256  }
257 
258 
270  m_hexData += ch;
271 
272  return XmlStackedHandler::characters(ch);
273  }
274 
275 
287  bool GuiCameraDisplayProperties::XmlHandler::endElement(const QString &namespaceURI,
288  const QString &localName, const QString &qName) {
289  if (localName == "displayProperties") {
290  QByteArray hexValues(m_hexData.toLatin1());
291  QDataStream valuesStream(QByteArray::fromHex(hexValues));
292  valuesStream >> *m_displayProperties->m_propertyValues;
293  }
294 
295  return XmlStackedHandler::endElement(namespaceURI, localName, qName);
296  }
297 
298 
305  void GuiCameraDisplayProperties::setValue(Property prop, QVariant value) {
306  if ((*m_propertyValues)[prop] != value) {
307  (*m_propertyValues)[prop] = value;
308 
309  if (supports(prop)) {
310  emit propertyChanged(this);
311  }
312  }
313  }
314 
315 
322  QObject *senderObj) {
324 
325  if (senderObj) {
326  QAction *caller = (QAction *)senderObj;
327  QVariant callerData = caller->data();
328 
329  if (callerData.canConvert< QList<GuiCameraDisplayProperties *> >() ) {
330  data = callerData.value< QList<GuiCameraDisplayProperties *> >();
331  }
332  }
333 
334  return data;
335  }
336 
337 
338 }
This class is designed to serialize QColor in a human-readable form.
Definition: Color.h:19
The main project for cnetsuite.
Definition: Project.h:105
File name manipulation and expansion.
Definition: FileName.h:111
void toggleShowLabel()
Change the visibility of the display name.
bool supports(Property prop)
Support may come later, please make sure you are connected to the supportAdded signal.
The selection state of this control net (bool)
void setColor(QColor newColor)
Change the color associated with this target.
Child class for XmlStackedHandler which is used to process XML in a stack-oriented way...
Property m_propertiesUsed
This indicates whether any widgets with this DisplayProperties is using a particular property...
True if the control net should show its display name (bool)
static QList< GuiCameraDisplayProperties * > senderToData(QObject *sender)
This is for the slots that have a list of display properties as associated data.
virtual bool endElement(const QString &namespaceURI, const QString &localName, const QString &qName)
The XML reader invokes this method at the end of every element in the XML document.
void setValue(Property prop, QVariant value)
This is the generic mutator for properties.
XmlHandler(GuiCameraDisplayProperties *displayProperties)
Sets the GuiCameraDisplayProperties variable pointer.
virtual bool characters(const QString &ch)
This implementation of a virtual function calls QXmlDefaultHandler::characters(QString &amp;ch) which in ...
void addSupport(Property prop)
Convert to Pvl for project files.
QString displayName() const
Returns the display name.
void setShowLabel(bool)
Change the visibility of the display name associated with this target.
Null display property for bit-flag purposes.
QVariant getValue(Property prop) const
Get a property&#39;s associated data.
void save(QXmlStreamWriter &stream, const Project *project, FileName newProjectRoot) const
Write the Gui Camera Display Properties out to an XML file.
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...
Property
This is a list of properties and actions that are possible.
This is the GUI communication mechanism for target body objects.
static QColor randomColor()
Creates and returns a random color for the intial color of the footprint polygon. ...
void setSelected(bool)
Change the selected state associated with this target.
GuiCameraDisplayProperties(QString displayName, QObject *parent=NULL)
GuiCameraDisplayProperties constructor.
his enables stack-based XML parsing of XML files.
virtual bool startElement(const QString &namespaceURI, const QString &localName, const QString &qName, const QXmlAttributes &atts)
The XML reader invokes this method at the start of every element in the XML document.
GuiCameraDisplayProperties * m_displayProperties
An internal pointer to GuiCameraDisplayProperties object.

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:19:00