Isis 3 Programmer Reference
ShapeDisplayProperties.cpp
1#include "ShapeDisplayProperties.h"
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
16namespace Isis {
25 DisplayProperties(displayName, parent) {
26
28 m_propertyValues = new QMap<int, QVariant>;
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
38
44
45
46
47
48
55 if (!supports(prop)) {
57 emit supportAdded(prop);
58 }
59 }
60
61
68 return (m_propertiesUsed & prop) == prop;
69 }
70
71
79 return (*m_propertyValues)[prop];
80 }
81
82
89 // Gives a random number between 0 and 255
90 int red = 0;
91 int green = 0;
92 int blue = 0;
93
94 // Generate dark
95 while (red + green + blue < 300) {
96 red = rand() % 256;
97 green = rand() % 256;
98 blue = rand() % 256;
99 }
100
101 return QColor(red, green, blue, 60);
102 }
103
110 void ShapeDisplayProperties::save(QXmlStreamWriter &stream, const Project *project,
111 FileName newProjectRoot) const {
112 stream.writeStartElement("displayProperties");
113
114 stream.writeAttribute("displayName", displayName());
115
116 // Get hex-encoded data
117 QBuffer dataBuffer;
118 dataBuffer.open(QIODevice::ReadWrite);
119 QDataStream propsStream(&dataBuffer);
120 propsStream << *m_propertyValues;
121 dataBuffer.seek(0);
122
123 stream.writeCharacters(dataBuffer.data().toHex());
124
125 stream.writeEndElement();
126 }
127
128
133 void ShapeDisplayProperties::setColor(QColor newColor) {
134 setValue(Color, QVariant::fromValue(newColor));
135 }
136
137
143 setValue(Selected, newValue);
144 }
145
146
152 setValue(ShowLabel, newValue);
153 }
154
155
164 QList<ShapeDisplayProperties *> displays = senderToData(sender());
165
166 bool value = getValue(ShowLabel).toBool();
167 value = !value;
168
169 ShapeDisplayProperties *display;
170 foreach (display, displays) {
171 display->setShowLabel(value);
172 }
173 }
174
175
184 void ShapeDisplayProperties::setValue(Property prop, QVariant value) {
185 if ((*m_propertyValues)[prop] != value) {
186 (*m_propertyValues)[prop] = value;
187
188 if (supports(prop)) {
189 emit propertyChanged(this);
190 }
191 }
192 }
193
194
204 QList<ShapeDisplayProperties *> ShapeDisplayProperties::senderToData(
205 QObject *senderObj) {
206 QList<ShapeDisplayProperties *> data;
207
208 if (senderObj) {
209 QAction *caller = (QAction *)senderObj;
210 QVariant callerData = caller->data();
211
212 if (callerData.canConvert< QList<ShapeDisplayProperties *> >() ) {
213 data = callerData.value< QList<ShapeDisplayProperties *> >();
214 }
215 }
216
217 return data;
218 }
219
220
221}
This class is designed to serialize QColor in a human-readable form.
Definition Color.h:26
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 the GUI communication mechanism for shape objects.
bool supports(Property prop)
Support for this may come later.
static QColor randomColor()
Creates and returns a random color for the initial color of the footprint polygon.
virtual ~ShapeDisplayProperties()
The destructor.
void setValue(Property prop, QVariant value)
This is the generic mutator for properties.
Property
This is a list of properties and actions that are possible.
@ None
Null display property for bit-flag purposes.
@ Selected
The selection state of this control net (bool)
@ ShowLabel
True if the control net should show its display name (bool)
void setColor(QColor newColor)
Change the color associated with this shape.
Property m_propertiesUsed
This indicated whether any widgets with this DisplayProperties is using a particular property.
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...
QVariant getValue(Property prop) const
Get a property's associated data.
void setShowLabel(bool)
Change the visibility of the display name associated with this shape.
void save(QXmlStreamWriter &stream, const Project *project, FileName newProjectRoot) const
Saves this object to an XML file.
void addSupport(Property prop)
Call this with every property you support, otherwise they will not communicate properly between widge...
static QList< ShapeDisplayProperties * > senderToData(QObject *sender)
Get the display properties from a slot.
void setSelected(bool)
Change the selected state associated with this shape.
void toggleShowLabel()
Change the visibility of the display name.
ShapeDisplayProperties(QString displayName, QObject *parent=NULL)
ShapeDisplayProperties constructor.
This is free and unencumbered software released into the public domain.
Definition Apollo.h:16