Isis 3 Programmer Reference
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 
307  void GuiCameraDisplayProperties::setValue(Property prop, QVariant value) {
308  if ((*m_propertyValues)[prop] != value) {
309  (*m_propertyValues)[prop] = value;
310 
311  if (supports(prop)) {
312  emit propertyChanged(this);
313  }
314  }
315  }
316 
317 
324  QObject *senderObj) {
326 
327  if (senderObj) {
328  QAction *caller = (QAction *)senderObj;
329  QVariant callerData = caller->data();
330 
331  if (callerData.canConvert< QList<GuiCameraDisplayProperties *> >() ) {
332  data = callerData.value< QList<GuiCameraDisplayProperties *> >();
333  }
334  }
335 
336  return data;
337  }
338 
339 
340 }
This class is designed to serialize QColor in a human-readable form.
Definition: Color.h:20
The main project for ipce.
Definition: Project.h:289
File name manipulation and expansion.
Definition: FileName.h:116
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 save(QXmlStreamWriter &stream, const Project *project, FileName newProjectRoot) const
Write the Gui Camera Display Properties out to an XML file.
QString displayName() const
Returns the display name.
void setColor(QColor newColor)
Change the color associated with this target.
Process a GuiCameraDisplayProperties 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 &ch) which in ...
void addSupport(Property prop)
Convert to Pvl for project files.
void setShowLabel(bool)
Change the visibility of the display name associated with this target.
Null display property for bit-flag purposes.
virtual void pushContentHandler(XmlStackedHandler *newHandler)
Push a contentHandler and maybe continue parsing...
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 ...
Property
This is a list of properties and actions that are possible.
QVariant getValue(Property prop) const
Get a property&#39;s associated data.
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. ...
Namespace for ISIS/Bullet specific routines.
Definition: Apollo.h:31
void setSelected(bool)
Change the selected state associated with this target.
GuiCameraDisplayProperties(QString displayName, QObject *parent=NULL)
GuiCameraDisplayProperties constructor.
Manage a stack of content handlers for reading 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.