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
24namespace Isis {
34 DisplayProperties(displayName, parent) {
35
37 m_propertyValues = new QMap<int, QVariant>;
38
39 // set all of the defaults to prevent unwanted change signals from
40 // being emitted later.
41 setShowLabel(false);
42 setSelected(false);
43
44 setValue(Color, QVariant::fromValue(randomColor()));
45 }
46
47
53
54
62 if (!supports(prop)) {
64 emit supportAdded(prop);
65 }
66 }
67
68
76 return (m_propertiesUsed & prop) == prop;
77 }
78
79
86 return (*m_propertyValues)[prop];
87 }
88
89
95 // Gives a random number between 0 and 255
96 int red = 0;
97 int green = 0;
98 int blue = 0;
99
100 // Generate dark
101 while(red + green + blue < 300) {
102 red = rand() % 256;
103 green = rand() % 256;
104 blue = rand() % 256;
105 }
106
107 return QColor(red, green, blue, 60);
108 }
109
110
111 void ControlDisplayProperties::save(QXmlStreamWriter &stream, const Project *project,
112 FileName newProjectRoot) const {
113 stream.writeStartElement("displayProperties");
114
115 stream.writeAttribute("displayName", displayName());
116
117 // Get hex-encoded data
118 QBuffer dataBuffer;
119 dataBuffer.open(QIODevice::ReadWrite);
120 QDataStream propsStream(&dataBuffer);
121 propsStream << *m_propertyValues;
122 dataBuffer.seek(0);
123
124 stream.writeCharacters(dataBuffer.data().toHex());
125
126 stream.writeEndElement();
127 }
128
129
134 setValue(Color, QVariant::fromValue(newColor));
135 }
136
137
142 setValue(Selected, newValue);
143 }
144
145
150 setValue(ShowLabel, newValue);
151 }
152
153
160 QList<ControlDisplayProperties *> displays = senderToData(sender());
161
162 bool value = getValue(ShowLabel).toBool();
163 value = !value;
164
166 foreach(display, displays) {
167 display->setShowLabel(value);
168 }
169 }
170
175 void ControlDisplayProperties::setValue(Property prop, QVariant value) {
176 if ((*m_propertyValues)[prop] != value) {
177 (*m_propertyValues)[prop] = value;
178
179 if (supports(prop)) {
180 emit propertyChanged(this);
181 }
182 }
183 }
184
185
190 QList<ControlDisplayProperties *> ControlDisplayProperties::senderToData(
191 QObject *senderObj) {
192 QList<ControlDisplayProperties *> data;
193
194 if (senderObj) {
195 QAction *caller = (QAction *)senderObj;
196 QVariant callerData = caller->data();
197
198 if (callerData.canConvert< QList<ControlDisplayProperties *> >() ) {
199 data = callerData.value< QList<ControlDisplayProperties *> >();
200 }
201 }
202
203 return data;
204 }
205
206
207}
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:287
This is free and unencumbered software released into the public domain.
Definition Apollo.h:16