Isis 3 Programmer Reference
ControlDisplayProperties.cpp
1 
7 /* SPDX-License-Identifier: CC0-1.0 */
8 
9 #include "ControlDisplayProperties.h"
10 
11 #include <QAction>
12 #include <QBitArray>
13 #include <QBuffer>
14 #include <QColorDialog>
15 #include <QDebug>
16 #include <QInputDialog>
17 #include <QMap>
18 #include <QVariant>
19 #include <QXmlStreamWriter>
20 
21 #include "FileName.h"
22 #include "Pvl.h"
23 #include "XmlStackedHandlerReader.h"
24 
25 namespace Isis {
35  DisplayProperties(displayName, parent) {
36 
39 
40  // set all of the defaults to prevent unwanted change signals from
41  // being emitted later.
42  setShowLabel(false);
43  setSelected(false);
44 
45  setValue(Color, QVariant::fromValue(randomColor()));
46  }
47 
48 
50  QObject *parent) : DisplayProperties("", parent) {
53 
54  xmlReader->pushContentHandler(new XmlHandler(this));
55  }
56 
57 
62  }
63 
64 
72  if (!supports(prop)) {
74  emit supportAdded(prop);
75  }
76  }
77 
78 
86  return (m_propertiesUsed & prop) == prop;
87  }
88 
89 
96  return (*m_propertyValues)[prop];
97  }
98 
99 
105  // Gives a random number between 0 and 255
106  int red = 0;
107  int green = 0;
108  int blue = 0;
109 
110  // Generate dark
111  while(red + green + blue < 300) {
112  red = rand() % 256;
113  green = rand() % 256;
114  blue = rand() % 256;
115  }
116 
117  return QColor(red, green, blue, 60);
118  }
119 
120 
121  void ControlDisplayProperties::save(QXmlStreamWriter &stream, const Project *project,
122  FileName newProjectRoot) const {
123  stream.writeStartElement("displayProperties");
124 
125  stream.writeAttribute("displayName", displayName());
126 
127  // Get hex-encoded data
128  QBuffer dataBuffer;
129  dataBuffer.open(QIODevice::ReadWrite);
130  QDataStream propsStream(&dataBuffer);
131  propsStream << *m_propertyValues;
132  dataBuffer.seek(0);
133 
134  stream.writeCharacters(dataBuffer.data().toHex());
135 
136  stream.writeEndElement();
137  }
138 
139 
143  void ControlDisplayProperties::setColor(QColor newColor) {
144  setValue(Color, QVariant::fromValue(newColor));
145  }
146 
147 
152  setValue(Selected, newValue);
153  }
154 
155 
160  setValue(ShowLabel, newValue);
161  }
162 
163 
170  QList<ControlDisplayProperties *> displays = senderToData(sender());
171 
172  bool value = getValue(ShowLabel).toBool();
173  value = !value;
174 
175  ControlDisplayProperties *display;
176  foreach(display, displays) {
177  display->setShowLabel(value);
178  }
179  }
180 
181 
182  ControlDisplayProperties::XmlHandler::XmlHandler(ControlDisplayProperties *displayProperties) {
183  m_displayProperties = displayProperties;
184  }
185 
186 
187  bool ControlDisplayProperties::XmlHandler::startElement(const QString &namespaceURI,
188  const QString &localName, const QString &qName, const QXmlAttributes &atts) {
189  if (XmlStackedHandler::startElement(namespaceURI, localName, qName, atts)) {
190  if (localName == "displayProperties") {
191  QString displayName = atts.value("displayName");
192 
193  if (!displayName.isEmpty()) {
194  m_displayProperties->setDisplayName(displayName);
195  }
196  }
197  }
198 
199  return true;
200  }
201 
202 
203  bool ControlDisplayProperties::XmlHandler::characters(const QString &ch) {
204  m_hexData += ch;
205 
206  return XmlStackedHandler::characters(ch);
207  }
208 
209 
210  bool ControlDisplayProperties::XmlHandler::endElement(const QString &namespaceURI,
211  const QString &localName, const QString &qName) {
212  if (localName == "displayProperties") {
213  QByteArray hexValues(m_hexData.toLatin1());
214  QDataStream valuesStream(QByteArray::fromHex(hexValues));
215  valuesStream >> *m_displayProperties->m_propertyValues;
216  }
217 
218  return XmlStackedHandler::endElement(namespaceURI, localName, qName);
219  }
220 
221 
226  void ControlDisplayProperties::setValue(Property prop, QVariant value) {
227  if ((*m_propertyValues)[prop] != value) {
228  (*m_propertyValues)[prop] = value;
229 
230  if (supports(prop)) {
231  emit propertyChanged(this);
232  }
233  }
234  }
235 
236 
242  QObject *senderObj) {
244 
245  if (senderObj) {
246  QAction *caller = (QAction *)senderObj;
247  QVariant callerData = caller->data();
248 
249  if (callerData.canConvert< QList<ControlDisplayProperties *> >() ) {
250  data = callerData.value< QList<ControlDisplayProperties *> >();
251  }
252  }
253 
254  return data;
255  }
256 
257 
258 }
Isis::Color
This class is designed to serialize QColor in a human-readable form.
Definition: Color.h:26
Isis::ControlDisplayProperties::senderToData
static QList< ControlDisplayProperties * > senderToData(QObject *sender)
This is for the slots that have a list of display properties as associated data.
Definition: ControlDisplayProperties.cpp:241
Isis::ControlDisplayProperties::None
@ None
Null display property for bit-flag purposes.
Definition: ControlDisplayProperties.h:67
QList
This is free and unencumbered software released into the public domain.
Definition: BoxcarCachingAlgorithm.h:13
Isis::ControlDisplayProperties::m_propertiesUsed
Property m_propertiesUsed
This indicated whether any widgets with this DisplayProperties is using a particular property.
Definition: ControlDisplayProperties.h:142
Isis::ControlDisplayProperties::randomColor
static QColor randomColor()
Creates and returns a random color for the intial color of the footprint polygon.
Definition: ControlDisplayProperties.cpp:104
Isis::FileName
File name manipulation and expansion.
Definition: FileName.h:100
Isis::XmlStackedHandlerReader::pushContentHandler
virtual void pushContentHandler(XmlStackedHandler *newHandler)
Push a contentHandler and maybe continue parsing...
Definition: XmlStackedHandlerReader.cpp:55
Isis::DisplayProperties
Definition: DisplayProperties.h:34
Isis::ControlDisplayProperties::ShowLabel
@ ShowLabel
True if the control net should show its display name (bool)
Definition: ControlDisplayProperties.h:73
Isis::ControlDisplayProperties
This is the GUI communication mechanism for cubes.
Definition: ControlDisplayProperties.h:59
Isis::ControlDisplayProperties::toggleShowLabel
void toggleShowLabel()
Change the visibility of the display name.
Definition: ControlDisplayProperties.cpp:169
Isis::ControlDisplayProperties::Selected
@ Selected
The selection state of this control net (bool)
Definition: ControlDisplayProperties.h:71
Isis::ControlDisplayProperties::~ControlDisplayProperties
virtual ~ControlDisplayProperties()
destructor
Definition: ControlDisplayProperties.cpp:61
Isis::XmlStackedHandlerReader
Manage a stack of content handlers for reading XML files.
Definition: XmlStackedHandlerReader.h:30
Isis::Project
The main project for ipce.
Definition: Project.h:289
Isis::ControlDisplayProperties::setSelected
void setSelected(bool)
Change the selected state associated with this cube.
Definition: ControlDisplayProperties.cpp:151
Isis::ControlDisplayProperties::ControlDisplayProperties
ControlDisplayProperties(QString displayName, QObject *parent=NULL)
ControlDisplayProperties constructor.
Definition: ControlDisplayProperties.cpp:34
Isis::ControlDisplayProperties::supports
bool supports(Property prop)
Support may come later, please make sure you are connected to the supportAdded signal.
Definition: ControlDisplayProperties.cpp:85
Isis::DisplayProperties::displayName
QString displayName() const
Returns the display name.
Definition: DisplayProperties.cpp:88
Isis::ControlDisplayProperties::m_propertyValues
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...
Definition: ControlDisplayProperties.h:148
Isis::ControlDisplayProperties::setShowLabel
void setShowLabel(bool)
Change the visibility of the display name associated with this cube.
Definition: ControlDisplayProperties.cpp:159
Isis::ControlDisplayProperties::setColor
void setColor(QColor newColor)
Change the color associated with this cube.
Definition: ControlDisplayProperties.cpp:143
Isis::ControlDisplayProperties::addSupport
void addSupport(Property prop)
Call this with every property you support, otherwise they will not communicate properly between widge...
Definition: ControlDisplayProperties.cpp:71
Isis::ControlDisplayProperties::setValue
void setValue(Property prop, QVariant value)
This is the generic mutator for properties.
Definition: ControlDisplayProperties.cpp:226
QMap< int, QVariant >
Isis::ControlDisplayProperties::Property
Property
This is a list of properties and actions that are possible.
Definition: ControlDisplayProperties.h:65
QObject
QAction
Isis::ControlDisplayProperties::getValue
QVariant getValue(Property prop) const
Get a property's associated data.
Definition: ControlDisplayProperties.cpp:95
Isis
This is free and unencumbered software released into the public domain.
Definition: Apollo.h:16