Isis 3.0 Programmer Reference
Home
TargetBodyDisplayProperties.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 
44  QObject *parent) : DisplayProperties("", parent) {
47 
48  xmlReader->pushContentHandler(new XmlHandler(this));
49  }
50 
51 
56  }
57 
58 
59 // void TargetBodyDisplayProperties::fromPvl(const PvlObject &pvl) {
60 // m_displayName = ((IString)pvl["DisplayName"][0]).ToQt();
61 
62 // QByteArray hexValues(pvl["Values"][0].c_str());
63 // QDataStream valuesStream(QByteArray::fromHex(hexValues));
64 // valuesStream >> *m_propertyValues;
65 // }
66 
67 
68 // /**
69 // * Convert to Pvl for project files. This stores all of the data associated
70 // * with all of the properties (but not what is supported). This also s tores
71 // * the target filename.
72 // */
73 // PvlObject TargetBodyDisplayProperties::toPvl() const {
74 // PvlObject output("DisplayProperties");
75 // output += PvlKeyword("DisplayName", m_displayName);
76 
77 // QBuffer dataBuffer;
78 // dataBuffer.open(QIODevice::ReadWrite);
79 
80 // QDataStream propsStream(&dataBuffer);
81 // propsStream << *m_propertyValues;
82 // dataBuffer.seek(0);
83 
84 // output += PvlKeyword("Values", QString(dataBuffer.data().toHex()));
85 
86 // return output;
87 // }
88 
89 
96  if (!supports(prop)) {
98  emit supportAdded(prop);
99  }
100  }
101 
102 
109  return (m_propertiesUsed & prop) == prop;
110  }
111 
112 
120  return (*m_propertyValues)[prop];
121  }
122 
123 
130  // Gives a random number between 0 and 255
131  int red = 0;
132  int green = 0;
133  int blue = 0;
134 
135  // Generate dark
136  while (red + green + blue < 300) {
137  red = rand() % 256;
138  green = rand() % 256;
139  blue = rand() % 256;
140  }
141 
142  return QColor(red, green, blue, 60);
143  }
144 
151  void TargetBodyDisplayProperties::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 
175  setValue(Color, QVariant::fromValue(newColor));
176  }
177 
178 
184  setValue(Selected, newValue);
185  }
186 
187 
193  setValue(ShowLabel, newValue);
194  }
195 
196 
204 
205  bool value = getValue(ShowLabel).toBool();
206  value = !value;
207 
209  foreach (display, displays) {
210  display->setShowLabel(value);
211  }
212  }
213 
214 
221  m_displayProperties = displayProperties;
222  }
223 
224 
236  const QString &localName, const QString &qName, const QXmlAttributes &atts) {
237  if (XmlStackedHandler::startElement(namespaceURI, localName, qName, atts)) {
238  if (localName == "displayProperties") {
239  QString displayName = atts.value("displayName");
240 
241  if (!displayName.isEmpty()) {
242  m_displayProperties->setDisplayName(displayName);
243  }
244  }
245  }
246 
247  return true;
248  }
249 
250 
262  m_hexData += ch;
263 
264  return XmlStackedHandler::characters(ch);
265  }
266 
267 
268 
280  bool TargetBodyDisplayProperties::XmlHandler::endElement(const QString &namespaceURI,
281  const QString &localName, const QString &qName) {
282  if (localName == "displayProperties") {
283  QByteArray hexValues(m_hexData.toLatin1());
284  QDataStream valuesStream(QByteArray::fromHex(hexValues));
285  valuesStream >> *m_displayProperties->m_propertyValues;
286  }
287 
288  return XmlStackedHandler::endElement(namespaceURI, localName, qName);
289  }
290 
291 
292 
299  void TargetBodyDisplayProperties::setValue(Property prop, QVariant value) {
300  if ((*m_propertyValues)[prop] != value) {
301  (*m_propertyValues)[prop] = value;
302 
303  if (supports(prop)) {
304  emit propertyChanged(this);
305  }
306  }
307  }
308 
309 
318  QObject *senderObj) {
320 
321  if (senderObj) {
322  QAction *caller = (QAction *)senderObj;
323  QVariant callerData = caller->data();
324 
325  if (callerData.canConvert< QList<TargetBodyDisplayProperties *> >() ) {
326  data = callerData.value< QList<TargetBodyDisplayProperties *> >();
327  }
328  }
329 
330  return data;
331  }
332 
333 
334 }
True if the control net should show its display name (bool)
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
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...
static QColor randomColor()
Creates and returns a random color for the initial color of the footprint polygon.
Property
This is a list of properties and actions that are possible.
This is the GUI communication mechanism for target body objects.
void setValue(Property prop, QVariant value)
This is the generic mutator for properties.
void save(QXmlStreamWriter &stream, const Project *project, FileName newProjectRoot) const
Saves this object to an XML file.
bool supports(Property prop)
Support for this may come later.
void setShowLabel(bool)
Change the visibility of the display name associated with this target.
Property m_propertiesUsed
This indicated whether any widgets with this DisplayProperties is using a particular property...
void addSupport(Property prop)
Convert to Pvl for project files.
QVariant getValue(Property prop) const
Get a property&#39;s associated data.
QString displayName() const
Returns the display name.
Null display property for bit-flag purposes.
The selection state of this control net (bool)
virtual bool startElement(const QString &namespaceURI, const QString &localName, const QString &qName, const QXmlAttributes &atts)
This overrides the parent startElement function in XmlStackedHandler so the parser can handle an XML ...
virtual ~TargetBodyDisplayProperties()
The destructor.
void setColor(QColor newColor)
Change the color associated with this target.
TargetBodyDisplayProperties(QString displayName, QObject *parent=NULL)
TargetBodyDisplayProperties constructor.
XmlHandler(TargetBodyDisplayProperties *displayProperties)
Constructor for the XmlHandler class.
void setSelected(bool)
Change the selected state associated with this target.
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.
This class is used for processing an XML file containing information about a WorkOrder.
his enables stack-based XML parsing of XML files.
virtual bool characters(const QString &ch)
This implementation of a virtual function calls QXmlDefaultHandler::characters(QString &amp;ch) which in ...
static QList< TargetBodyDisplayProperties * > senderToData(QObject *sender)
This is for the slots that have a list of display properties as associated data.