Isis 3 Programmer Reference
TargetBodyDisplayProperties.cpp
1#include "TargetBodyDisplayProperties.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 {
24 DisplayProperties(displayName, parent) {
25
27 m_propertyValues = new QMap<int, QVariant>;
28
29 // set all of the defaults to prevent unwanted change signals from
30 // being emitted later.
31 setShowLabel(false);
32 setSelected(false);
33
34 setValue(Color, QVariant::fromValue(randomColor()));
35 }
36
37
43
44
45// void TargetBodyDisplayProperties::fromPvl(const PvlObject &pvl) {
46// m_displayName = ((IString)pvl["DisplayName"][0]).ToQt();
47
48// QByteArray hexValues(pvl["Values"][0].c_str());
49// QDataStream valuesStream(QByteArray::fromHex(hexValues));
50// valuesStream >> *m_propertyValues;
51// }
52
53
54// /**
55// * Convert to Pvl for project files. This stores all of the data associated
56// * with all of the properties (but not what is supported). This also s tores
57// * the target filename.
58// */
59// PvlObject TargetBodyDisplayProperties::toPvl() const {
60// PvlObject output("DisplayProperties");
61// output += PvlKeyword("DisplayName", m_displayName);
62
63// QBuffer dataBuffer;
64// dataBuffer.open(QIODevice::ReadWrite);
65
66// QDataStream propsStream(&dataBuffer);
67// propsStream << *m_propertyValues;
68// dataBuffer.seek(0);
69
70// output += PvlKeyword("Values", QString(dataBuffer.data().toHex()));
71
72// return output;
73// }
74
75
82 if (!supports(prop)) {
84 emit supportAdded(prop);
85 }
86 }
87
88
95 return (m_propertiesUsed & prop) == prop;
96 }
97
98
106 return (*m_propertyValues)[prop];
107 }
108
109
116 // Gives a random number between 0 and 255
117 int red = 0;
118 int green = 0;
119 int blue = 0;
120
121 // Generate dark
122 while (red + green + blue < 300) {
123 red = rand() % 256;
124 green = rand() % 256;
125 blue = rand() % 256;
126 }
127
128 return QColor(red, green, blue, 60);
129 }
130
138 void TargetBodyDisplayProperties::save(QXmlStreamWriter &stream, const Project *project,
139 FileName newProjectRoot) const {
140 stream.writeStartElement("displayProperties");
141
142 stream.writeAttribute("displayName", displayName());
143
144 // Get hex-encoded data
145 QBuffer dataBuffer;
146 dataBuffer.open(QIODevice::ReadWrite);
147 QDataStream propsStream(&dataBuffer);
148 propsStream << *m_propertyValues;
149 dataBuffer.seek(0);
150
151 stream.writeCharacters(dataBuffer.data().toHex());
152
153 stream.writeEndElement();
154 }
155
156
163 setValue(Color, QVariant::fromValue(newColor));
164 }
165
166
173 setValue(Selected, newValue);
174 }
175
176
183 setValue(ShowLabel, newValue);
184 }
185
186
195 QList<TargetBodyDisplayProperties *> displays = senderToData(sender());
196
197 bool value = getValue(ShowLabel).toBool();
198 value = !value;
199
201 foreach (display, displays) {
202 display->setShowLabel(value);
203 }
204 }
205
206
207
217 if ((*m_propertyValues)[prop] != value) {
218 (*m_propertyValues)[prop] = value;
219
220 if (supports(prop)) {
221 emit propertyChanged(this);
222 }
223 }
224 }
225
226
236 QList<TargetBodyDisplayProperties *> TargetBodyDisplayProperties::senderToData(
237 QObject *senderObj) {
238 QList<TargetBodyDisplayProperties *> data;
239
240 if (senderObj) {
241 QAction *caller = (QAction *)senderObj;
242 QVariant callerData = caller->data();
243
244 if (callerData.canConvert< QList<TargetBodyDisplayProperties *> >() ) {
245 data = callerData.value< QList<TargetBodyDisplayProperties *> >();
246 }
247 }
248
249 return data;
250 }
251
252
253}
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 target body objects.
Property
This is a list of properties and actions that are possible.
@ Selected
The selection state of this control net (bool)
@ None
Null display property for bit-flag purposes.
@ ShowLabel
True if the control net should show its display name (bool)
Property m_propertiesUsed
This indicated whether any widgets with this DisplayProperties is using a particular property.
void save(QXmlStreamWriter &stream, const Project *project, FileName newProjectRoot) const
Saves this object to an XML file.
TargetBodyDisplayProperties(QString displayName, QObject *parent=NULL)
TargetBodyDisplayProperties constructor.
static QList< TargetBodyDisplayProperties * > senderToData(QObject *sender)
Return display properties associated with a slot.
void toggleShowLabel()
Change the visibility of the display name.
bool supports(Property prop)
Support for this may come later.
QVariant getValue(Property prop) const
Get a property's associated data.
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 setColor(QColor newColor)
Change the color associated with this target.
void setShowLabel(bool)
Change the visibility of the display name associated with this target.
static QColor randomColor()
Creates and returns a random color for the initial color of the footprint polygon.
void setSelected(bool)
Change the selected state associated with this target.
void addSupport(Property prop)
Call this with every property you support, otherwise they will not communicate properly between widge...
void setValue(Property prop, QVariant value)
This is the generic mutator for properties.
This is free and unencumbered software released into the public domain.
Definition Apollo.h:16