Isis 3 Programmer Reference
ShapeDisplayProperties.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 {
26  DisplayProperties(displayName, parent) {
27 
30 
31  // set all of the defaults to prevent unwanted change signals from
32  // being emitted later.
33  setShowLabel(false);
34  setSelected(false);
35 
36  setValue(Color, QVariant::fromValue(randomColor()));
37  }
38 
45  QObject *parent) : DisplayProperties("", parent) {
48 
49  xmlReader->pushContentHandler(new XmlHandler(this));
50  }
51 
52 
57  }
58 
59 
60 
61 
62 
69  if (!supports(prop)) {
71  emit supportAdded(prop);
72  }
73  }
74 
75 
82  return (m_propertiesUsed & prop) == prop;
83  }
84 
85 
93  return (*m_propertyValues)[prop];
94  }
95 
96 
103  // Gives a random number between 0 and 255
104  int red = 0;
105  int green = 0;
106  int blue = 0;
107 
108  // Generate dark
109  while (red + green + blue < 300) {
110  red = rand() % 256;
111  green = rand() % 256;
112  blue = rand() % 256;
113  }
114 
115  return QColor(red, green, blue, 60);
116  }
117 
124  void ShapeDisplayProperties::save(QXmlStreamWriter &stream, const Project *project,
125  FileName newProjectRoot) const {
126  stream.writeStartElement("displayProperties");
127 
128  stream.writeAttribute("displayName", displayName());
129 
130  // Get hex-encoded data
131  QBuffer dataBuffer;
132  dataBuffer.open(QIODevice::ReadWrite);
133  QDataStream propsStream(&dataBuffer);
134  propsStream << *m_propertyValues;
135  dataBuffer.seek(0);
136 
137  stream.writeCharacters(dataBuffer.data().toHex());
138 
139  stream.writeEndElement();
140  }
141 
142 
147  void ShapeDisplayProperties::setColor(QColor newColor) {
148  setValue(Color, QVariant::fromValue(newColor));
149  }
150 
151 
157  setValue(Selected, newValue);
158  }
159 
160 
166  setValue(ShowLabel, newValue);
167  }
168 
169 
178  QList<ShapeDisplayProperties *> displays = senderToData(sender());
179 
180  bool value = getValue(ShowLabel).toBool();
181  value = !value;
182 
183  ShapeDisplayProperties *display;
184  foreach (display, displays) {
185  display->setShowLabel(value);
186  }
187  }
188 
189 
198  m_displayProperties = displayProperties;
199  }
200 
201 
212  bool ShapeDisplayProperties::XmlHandler::startElement(const QString &namespaceURI,
213  const QString &localName, const QString &qName, const QXmlAttributes &atts) {
214  if (XmlStackedHandler::startElement(namespaceURI, localName, qName, atts)) {
215  if (localName == "displayProperties") {
216  QString displayName = atts.value("displayName");
217 
218  if (!displayName.isEmpty()) {
219  m_displayProperties->setDisplayName(displayName);
220  }
221  }
222  }
223 
224  return true;
225  }
226 
227 
241  m_hexData += ch;
242 
243  return XmlStackedHandler::characters(ch);
244  }
245 
246 
247 
259  bool ShapeDisplayProperties::XmlHandler::endElement(const QString &namespaceURI,
260  const QString &localName, const QString &qName) {
261  if (localName == "displayProperties") {
262  QByteArray hexValues(m_hexData.toLatin1());
263  QDataStream valuesStream(QByteArray::fromHex(hexValues));
264  valuesStream >> *m_displayProperties->m_propertyValues;
265  }
266 
267  return XmlStackedHandler::endElement(namespaceURI, localName, qName);
268  }
269 
270 
271 
280  void ShapeDisplayProperties::setValue(Property prop, QVariant value) {
281  if ((*m_propertyValues)[prop] != value) {
282  (*m_propertyValues)[prop] = value;
283 
284  if (supports(prop)) {
285  emit propertyChanged(this);
286  }
287  }
288  }
289 
290 
301  QObject *senderObj) {
303 
304  if (senderObj) {
305  QAction *caller = (QAction *)senderObj;
306  QVariant callerData = caller->data();
307 
308  if (callerData.canConvert< QList<ShapeDisplayProperties *> >() ) {
309  data = callerData.value< QList<ShapeDisplayProperties *> >();
310  }
311  }
312 
313  return data;
314  }
315 
316 
317 }
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
QVariant getValue(Property prop) const
Get a property&#39;s associated data.
bool supports(Property prop)
Support for this may come later.
Property m_propertiesUsed
This indicated whether any widgets with this DisplayProperties is using a particular property...
virtual ~ShapeDisplayProperties()
The destructor.
This class is used for processing an XML file containing information about a WorkOrder.
QString displayName() const
Returns the display name.
This is the GUI communication mechanism for shape objects.
static QColor randomColor()
Creates and returns a random color for the initial color of the footprint polygon.
void setShowLabel(bool)
Change the visibility of the display name associated with this shape.
void toggleShowLabel()
Change the visibility of the display name.
True if the control net should show its display name (bool)
void setSelected(bool)
Change the selected state associated with this shape.
virtual void pushContentHandler(XmlStackedHandler *newHandler)
Push a contentHandler and maybe continue parsing...
virtual bool characters(const QString &ch)
This is called when the XML processor has parsed a chunk of character data.
void setColor(QColor newColor)
Change the color associated with this shape.
void save(QXmlStreamWriter &stream, const Project *project, FileName newProjectRoot) const
Saves this object to an XML file.
void addSupport(Property prop)
Call this with every property you support, otherwise they will not communicate properly between widge...
void setValue(Property prop, QVariant value)
This is the generic mutator for properties.
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 ...
Null display property for bit-flag purposes.
Namespace for ISIS/Bullet specific routines.
Definition: Apollo.h:31
ShapeDisplayProperties(QString displayName, QObject *parent=NULL)
ShapeDisplayProperties constructor.
The selection state of this control net (bool)
Property
This is a list of properties and actions that are possible.
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 ...
Manage a stack of content handlers for reading XML files.
static QList< ShapeDisplayProperties * > senderToData(QObject *sender)
Get the display properties from a slot.
XmlHandler(ShapeDisplayProperties *displayProperties)
Constructor for the XmlHandler class.
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.