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 }
Isis::GuiCameraDisplayProperties::ShowLabel
@ ShowLabel
True if the control net should show its display name (bool)
Definition: GuiCameraDisplayProperties.h:90
Isis::Color
This class is designed to serialize QColor in a human-readable form.
Definition: Color.h:26
Isis::GuiCameraDisplayProperties::~GuiCameraDisplayProperties
virtual ~GuiCameraDisplayProperties()
destructor
Definition: GuiCameraDisplayProperties.cpp:57
Isis::GuiCameraDisplayProperties::setShowLabel
void setShowLabel(bool)
Change the visibility of the display name associated with this target.
Definition: GuiCameraDisplayProperties.cpp:196
Isis::GuiCameraDisplayProperties::m_propertiesUsed
Property m_propertiesUsed
This indicates whether any widgets with this DisplayProperties is using a particular property.
Definition: GuiCameraDisplayProperties.h:179
Isis::GuiCameraDisplayProperties::setSelected
void setSelected(bool)
Change the selected state associated with this target.
Definition: GuiCameraDisplayProperties.cpp:187
QList
This is free and unencumbered software released into the public domain.
Definition: BoxcarCachingAlgorithm.h:13
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::GuiCameraDisplayProperties::supports
bool supports(Property prop)
Support may come later, please make sure you are connected to the supportAdded signal.
Definition: GuiCameraDisplayProperties.cpp:112
Isis::GuiCameraDisplayProperties::setValue
void setValue(Property prop, QVariant value)
This is the generic mutator for properties.
Definition: GuiCameraDisplayProperties.cpp:307
Isis::GuiCameraDisplayProperties::save
void save(QXmlStreamWriter &stream, const Project *project, FileName newProjectRoot) const
Write the Gui Camera Display Properties out to an XML file.
Definition: GuiCameraDisplayProperties.cpp:155
Isis::DisplayProperties
Definition: DisplayProperties.h:34
Isis::GuiCameraDisplayProperties::Property
Property
This is a list of properties and actions that are possible.
Definition: GuiCameraDisplayProperties.h:82
Isis::GuiCameraDisplayProperties::randomColor
static QColor randomColor()
Creates and returns a random color for the intial color of the footprint polygon.
Definition: GuiCameraDisplayProperties.cpp:132
Isis::GuiCameraDisplayProperties::senderToData
static QList< GuiCameraDisplayProperties * > senderToData(QObject *sender)
This is for the slots that have a list of display properties as associated data.
Definition: GuiCameraDisplayProperties.cpp:323
Isis::GuiCameraDisplayProperties::toggleShowLabel
void toggleShowLabel()
Change the visibility of the display name.
Definition: GuiCameraDisplayProperties.cpp:206
Isis::GuiCameraDisplayProperties::XmlHandler
Process a GuiCameraDisplayProperties in a stack-oriented way.
Definition: GuiCameraDisplayProperties.h:140
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::GuiCameraDisplayProperties::addSupport
void addSupport(Property prop)
Call this with every property you support, otherwise they will not communicate properly between widge...
Definition: GuiCameraDisplayProperties.cpp:98
Isis::GuiCameraDisplayProperties::Selected
@ Selected
The selection state of this control net (bool)
Definition: GuiCameraDisplayProperties.h:88
Isis::GuiCameraDisplayProperties::getValue
QVariant getValue(Property prop) const
Get a property's associated data.
Definition: GuiCameraDisplayProperties.cpp:122
Isis::GuiCameraDisplayProperties::XmlHandler::startElement
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.
Definition: GuiCameraDisplayProperties.cpp:243
Isis::DisplayProperties::displayName
QString displayName() const
Returns the display name.
Definition: DisplayProperties.cpp:88
Isis::GuiCameraDisplayProperties::None
@ None
Null display property for bit-flag purposes.
Definition: GuiCameraDisplayProperties.h:84
Isis::GuiCameraDisplayProperties::GuiCameraDisplayProperties
GuiCameraDisplayProperties(QString displayName, QObject *parent=NULL)
GuiCameraDisplayProperties constructor.
Definition: GuiCameraDisplayProperties.cpp:24
GuiCameraDisplayProperties.h
Isis::GuiCameraDisplayProperties::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: GuiCameraDisplayProperties.h:185
Isis::GuiCameraDisplayProperties::XmlHandler::characters
virtual bool characters(const QString &ch)
This implementation of a virtual function calls QXmlDefaultHandler::characters(QString &ch) which in ...
Definition: GuiCameraDisplayProperties.cpp:269
Isis::GuiCameraDisplayProperties::XmlHandler::XmlHandler
XmlHandler(GuiCameraDisplayProperties *displayProperties)
Sets the GuiCameraDisplayProperties variable pointer.
Definition: GuiCameraDisplayProperties.cpp:224
QMap< int, QVariant >
Isis::GuiCameraDisplayProperties::setColor
void setColor(QColor newColor)
Change the color associated with this target.
Definition: GuiCameraDisplayProperties.cpp:178
QObject
Isis::GuiCameraDisplayProperties::XmlHandler::endElement
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.
Definition: GuiCameraDisplayProperties.cpp:287
QAction
Isis::GuiCameraDisplayProperties
The GUI communication mechanism for target body objects.
Definition: GuiCameraDisplayProperties.h:76
Isis::GuiCameraDisplayProperties::XmlHandler::m_displayProperties
GuiCameraDisplayProperties * m_displayProperties
An internal pointer to GuiCameraDisplayProperties object.
Definition: GuiCameraDisplayProperties.h:158
Isis
This is free and unencumbered software released into the public domain.
Definition: Apollo.h:16