Isis 3.0 Programmer Reference
Back | Home
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 {
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 ShapeDisplayProperties::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 shape filename.
72 // */
73 // PvlObject ShapeDisplayProperties::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 ShapeDisplayProperties::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 
174  void ShapeDisplayProperties::setColor(QColor newColor) {
175  setValue(Color, QVariant::fromValue(newColor));
176  }
177 
178 
184  setValue(Selected, newValue);
185  }
186 
187 
193  setValue(ShowLabel, newValue);
194  }
195 
196 
203  QList<ShapeDisplayProperties *> displays = senderToData(sender());
204 
205  bool value = getValue(ShowLabel).toBool();
206  value = !value;
207 
208  ShapeDisplayProperties *display;
209  foreach (display, displays) {
210  display->setShowLabel(value);
211  }
212  }
213 
214 
221  m_displayProperties = displayProperties;
222  }
223 
224 
235  bool ShapeDisplayProperties::XmlHandler::startElement(const QString &namespaceURI,
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 ShapeDisplayProperties::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 ShapeDisplayProperties::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<ShapeDisplayProperties *> >() ) {
326  data = callerData.value< QList<ShapeDisplayProperties *> >();
327  }
328  }
329 
330  return data;
331  }
332 
333 
334 }
QVariant getValue(Property prop) const
Get a property&#39;s associated data.
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
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.
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.
True if the control net should show its display name (bool)
void setSelected(bool)
Change the selected state associated with this shape.
QString displayName() const
Returns the display name.
virtual bool characters(const QString &ch)
This implementation of a virtual function calls QXmlDefaultHandler::characters(QString &amp;ch) which in ...
void setColor(QColor newColor)
Change the color associated with this shape.
void addSupport(Property prop)
Convert to Pvl for project files.
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.
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.
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 Q...
his enables stack-based XML parsing of XML files.
static QList< ShapeDisplayProperties * > senderToData(QObject *sender)
This is for the slots that have a list of display properties as associated data.
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.

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:29:05