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
25namespace Isis {
35 DisplayProperties(displayName, parent) {
36
38 m_propertyValues = new QMap<int, QVariant>;
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) {
52 m_propertyValues = new QMap<int, QVariant>;
53
54 xmlReader->pushContentHandler(new XmlHandler(this));
55 }
56
57
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
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
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
241 QList<ControlDisplayProperties *> ControlDisplayProperties::senderToData(
242 QObject *senderObj) {
243 QList<ControlDisplayProperties *> data;
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}
This class is designed to serialize QColor in a human-readable form.
Definition Color.h:26
This is the GUI communication mechanism for cubes.
Property m_propertiesUsed
This indicated whether any widgets with this DisplayProperties is using a particular property.
void setColor(QColor newColor)
Change the color associated with this cube.
static QColor randomColor()
Creates and returns a random color for the intial color of the footprint polygon.
ControlDisplayProperties(QString displayName, QObject *parent=NULL)
ControlDisplayProperties constructor.
void setValue(Property prop, QVariant value)
This is the generic mutator for properties.
QVariant getValue(Property prop) const
Get a property's associated data.
bool supports(Property prop)
Support may come later, please make sure you are connected to the supportAdded signal.
void toggleShowLabel()
Change the visibility of the display name.
void addSupport(Property prop)
Call this with every property you support, otherwise they will not communicate properly between widge...
static QList< ControlDisplayProperties * > senderToData(QObject *sender)
This is for the slots that have a list of display properties as associated data.
Property
This is a list of properties and actions that are possible.
@ None
Null display property for bit-flag purposes.
@ ShowLabel
True if the control net should show its display name (bool)
@ Selected
The selection state of this control net (bool)
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 setShowLabel(bool)
Change the visibility of the display name associated with this cube.
void setSelected(bool)
Change the selected state associated with this cube.
QString displayName() const
Returns the display name.
File name manipulation and expansion.
Definition FileName.h:100
The main project for ipce.
Definition Project.h:289
Manage a stack of content handlers for reading XML files.
This is free and unencumbered software released into the public domain.
Definition Apollo.h:16