Isis 3.0 Programmer Reference
Back | Home
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 
57 // void ControlDisplayProperties::fromPvl(const PvlObject &pvl) {
58 // m_displayName = ((IString)pvl["DisplayName"][0]).ToQt();
59 
60 // QByteArray hexValues(pvl["Values"][0].c_str());
61 // QDataStream valuesStream(QByteArray::fromHex(hexValues));
62 // valuesStream >> *m_propertyValues;
63 // }
64 
65 
66 // /**
67 // * Convert to Pvl for project files. This stores all of the data associated
68 // * with all of the properties (but not what is supported). This also s tores
69 // * the cube filename.
70 // */
71 // PvlObject ControlDisplayProperties::toPvl() const {
72 // PvlObject output("DisplayProperties");
73 // output += PvlKeyword("DisplayName", m_displayName);
74 
75 // QBuffer dataBuffer;
76 // dataBuffer.open(QIODevice::ReadWrite);
77 
78 // QDataStream propsStream(&dataBuffer);
79 // propsStream << *m_propertyValues;
80 // dataBuffer.seek(0);
81 
82 // output += PvlKeyword("Values", QString(dataBuffer.data().toHex()));
83 
84 // return output;
85 // }
86 
87 
95  if (!supports(prop)) {
97  emit supportAdded(prop);
98  }
99  }
100 
101 
109  return (m_propertiesUsed & prop) == prop;
110  }
111 
112 
119  return (*m_propertyValues)[prop];
120  }
121 
122 
128  // Gives a random number between 0 and 255
129  int red = 0;
130  int green = 0;
131  int blue = 0;
132 
133  // Generate dark
134  while(red + green + blue < 300) {
135  red = rand() % 256;
136  green = rand() % 256;
137  blue = rand() % 256;
138  }
139 
140  return QColor(red, green, blue, 60);
141  }
142 
143 
144  void ControlDisplayProperties::save(QXmlStreamWriter &stream, const Project *project,
145  FileName newProjectRoot) const {
146  stream.writeStartElement("displayProperties");
147 
148  stream.writeAttribute("displayName", displayName());
149 
150  // Get hex-encoded data
151  QBuffer dataBuffer;
152  dataBuffer.open(QIODevice::ReadWrite);
153  QDataStream propsStream(&dataBuffer);
154  propsStream << *m_propertyValues;
155  dataBuffer.seek(0);
156 
157  stream.writeCharacters(dataBuffer.data().toHex());
158 
159  stream.writeEndElement();
160  }
161 
162 
166  void ControlDisplayProperties::setColor(QColor newColor) {
167  setValue(Color, QVariant::fromValue(newColor));
168  }
169 
170 
175  setValue(Selected, newValue);
176  }
177 
178 
183  setValue(ShowLabel, newValue);
184  }
185 
186 
193  QList<ControlDisplayProperties *> displays = senderToData(sender());
194 
195  bool value = getValue(ShowLabel).toBool();
196  value = !value;
197 
198  ControlDisplayProperties *display;
199  foreach(display, displays) {
200  display->setShowLabel(value);
201  }
202  }
203 
204 
205  ControlDisplayProperties::XmlHandler::XmlHandler(ControlDisplayProperties *displayProperties) {
206  m_displayProperties = displayProperties;
207  }
208 
209 
210  bool ControlDisplayProperties::XmlHandler::startElement(const QString &namespaceURI,
211  const QString &localName, const QString &qName, const QXmlAttributes &atts) {
212  if (XmlStackedHandler::startElement(namespaceURI, localName, qName, atts)) {
213  if (localName == "displayProperties") {
214  QString displayName = atts.value("displayName");
215 
216  if (!displayName.isEmpty()) {
217  m_displayProperties->setDisplayName(displayName);
218  }
219  }
220  }
221 
222  return true;
223  }
224 
225 
226  bool ControlDisplayProperties::XmlHandler::characters(const QString &ch) {
227  m_hexData += ch;
228 
229  return XmlStackedHandler::characters(ch);
230  }
231 
232 
233  bool ControlDisplayProperties::XmlHandler::endElement(const QString &namespaceURI,
234  const QString &localName, const QString &qName) {
235  if (localName == "displayProperties") {
236  QByteArray hexValues(m_hexData.toLatin1());
237  QDataStream valuesStream(QByteArray::fromHex(hexValues));
238  valuesStream >> *m_displayProperties->m_propertyValues;
239  }
240 
241  return XmlStackedHandler::endElement(namespaceURI, localName, qName);
242  }
243 
244 
249  void ControlDisplayProperties::setValue(Property prop, QVariant value) {
250  if ((*m_propertyValues)[prop] != value) {
251  (*m_propertyValues)[prop] = value;
252 
253  if (supports(prop)) {
254  emit propertyChanged(this);
255  }
256  }
257  }
258 
259 
265  QObject *senderObj) {
267 
268  if (senderObj) {
269  QAction *caller = (QAction *)senderObj;
270  QVariant callerData = caller->data();
271 
272  if (callerData.canConvert< QList<ControlDisplayProperties *> >() ) {
273  data = callerData.value< QList<ControlDisplayProperties *> >();
274  }
275  }
276 
277  return data;
278  }
279 
280 
281 }
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: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...
void addSupport(Property prop)
Convert to Pvl for project files.
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.
QVariant getValue(Property prop) const
Get a property&#39;s associated data.
This is the GUI communication mechanism for cubes.
void toggleShowLabel()
Change the visibility of the display name.
QString displayName() const
Returns the display name.
void setShowLabel(bool)
Change the visibility of the display name associated with this cube.
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...
The selection state of this control net (bool)
void setColor(QColor newColor)
Change the color associated with this cube.
his enables stack-based XML parsing of XML files.
void setValue(Property prop, QVariant value)
This is the generic mutator for properties.

U.S. Department of the Interior | U.S. Geological Survey
ISIS | Privacy & Disclaimers | Astrogeology Research Program
To contact us, please post comments and questions on the ISIS Support Center
File Modified: 07/12/2023 23:16:16