Isis 3 Programmer Reference
ControlDisplayProperties.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 {
27  DisplayProperties(displayName, parent) {
28 
31 
32  // set all of the defaults to prevent unwanted change signals from
33  // being emitted later.
34  setShowLabel(false);
35  setSelected(false);
36 
37  setValue(Color, QVariant::fromValue(randomColor()));
38  }
39 
40 
42  QObject *parent) : DisplayProperties("", parent) {
45 
46  xmlReader->pushContentHandler(new XmlHandler(this));
47  }
48 
49 
54  }
55 
56 
64  if (!supports(prop)) {
66  emit supportAdded(prop);
67  }
68  }
69 
70 
78  return (m_propertiesUsed & prop) == prop;
79  }
80 
81 
88  return (*m_propertyValues)[prop];
89  }
90 
91 
97  // Gives a random number between 0 and 255
98  int red = 0;
99  int green = 0;
100  int blue = 0;
101 
102  // Generate dark
103  while(red + green + blue < 300) {
104  red = rand() % 256;
105  green = rand() % 256;
106  blue = rand() % 256;
107  }
108 
109  return QColor(red, green, blue, 60);
110  }
111 
112 
113  void ControlDisplayProperties::save(QXmlStreamWriter &stream, const Project *project,
114  FileName newProjectRoot) const {
115  stream.writeStartElement("displayProperties");
116 
117  stream.writeAttribute("displayName", displayName());
118 
119  // Get hex-encoded data
120  QBuffer dataBuffer;
121  dataBuffer.open(QIODevice::ReadWrite);
122  QDataStream propsStream(&dataBuffer);
123  propsStream << *m_propertyValues;
124  dataBuffer.seek(0);
125 
126  stream.writeCharacters(dataBuffer.data().toHex());
127 
128  stream.writeEndElement();
129  }
130 
131 
135  void ControlDisplayProperties::setColor(QColor newColor) {
136  setValue(Color, QVariant::fromValue(newColor));
137  }
138 
139 
144  setValue(Selected, newValue);
145  }
146 
147 
152  setValue(ShowLabel, newValue);
153  }
154 
155 
162  QList<ControlDisplayProperties *> displays = senderToData(sender());
163 
164  bool value = getValue(ShowLabel).toBool();
165  value = !value;
166 
167  ControlDisplayProperties *display;
168  foreach(display, displays) {
169  display->setShowLabel(value);
170  }
171  }
172 
173 
174  ControlDisplayProperties::XmlHandler::XmlHandler(ControlDisplayProperties *displayProperties) {
175  m_displayProperties = displayProperties;
176  }
177 
178 
179  bool ControlDisplayProperties::XmlHandler::startElement(const QString &namespaceURI,
180  const QString &localName, const QString &qName, const QXmlAttributes &atts) {
181  if (XmlStackedHandler::startElement(namespaceURI, localName, qName, atts)) {
182  if (localName == "displayProperties") {
183  QString displayName = atts.value("displayName");
184 
185  if (!displayName.isEmpty()) {
186  m_displayProperties->setDisplayName(displayName);
187  }
188  }
189  }
190 
191  return true;
192  }
193 
194 
195  bool ControlDisplayProperties::XmlHandler::characters(const QString &ch) {
196  m_hexData += ch;
197 
198  return XmlStackedHandler::characters(ch);
199  }
200 
201 
202  bool ControlDisplayProperties::XmlHandler::endElement(const QString &namespaceURI,
203  const QString &localName, const QString &qName) {
204  if (localName == "displayProperties") {
205  QByteArray hexValues(m_hexData.toLatin1());
206  QDataStream valuesStream(QByteArray::fromHex(hexValues));
207  valuesStream >> *m_displayProperties->m_propertyValues;
208  }
209 
210  return XmlStackedHandler::endElement(namespaceURI, localName, qName);
211  }
212 
213 
218  void ControlDisplayProperties::setValue(Property prop, QVariant value) {
219  if ((*m_propertyValues)[prop] != value) {
220  (*m_propertyValues)[prop] = value;
221 
222  if (supports(prop)) {
223  emit propertyChanged(this);
224  }
225  }
226  }
227 
228 
234  QObject *senderObj) {
236 
237  if (senderObj) {
238  QAction *caller = (QAction *)senderObj;
239  QVariant callerData = caller->data();
240 
241  if (callerData.canConvert< QList<ControlDisplayProperties *> >() ) {
242  data = callerData.value< QList<ControlDisplayProperties *> >();
243  }
244  }
245 
246  return data;
247  }
248 
249 
250 }
void setSelected(bool)
Change the selected state associated with this cube.
ControlDisplayProperties(QString displayName, QObject *parent=NULL)
ControlDisplayProperties constructor.
Property
This is a list of properties and actions that are possible.
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
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 ...
void addSupport(Property prop)
Call this with every property you support, otherwise they will not communicate properly between widge...
QString displayName() const
Returns the display name.
static QColor randomColor()
Creates and returns a random color for the intial color of the footprint polygon. ...
True if the control net should show its display name (bool)
bool supports(Property prop)
Support may come later, please make sure you are connected to the supportAdded signal.
This is the GUI communication mechanism for cubes.
void toggleShowLabel()
Change the visibility of the display name.
void setShowLabel(bool)
Change the visibility of the display name associated with this cube.
virtual void pushContentHandler(XmlStackedHandler *newHandler)
Push a contentHandler and maybe continue parsing...
static QList< ControlDisplayProperties * > senderToData(QObject *sender)
This is for the slots that have a list of display properties as associated data.
Null display property for bit-flag purposes.
Property m_propertiesUsed
This indicated whether any widgets with this DisplayProperties is using a particular property...
QVariant getValue(Property prop) const
Get a property&#39;s associated data.
Namespace for ISIS/Bullet specific routines.
Definition: Apollo.h:31
The selection state of this control net (bool)
void setColor(QColor newColor)
Change the color associated with this cube.
Manage a stack of content handlers for reading XML files.
void setValue(Property prop, QVariant value)
This is the generic mutator for properties.