Isis 3 Programmer Reference
GuiCameraDisplayProperties.cpp
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 GuiCameraDisplayProperties::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 GuiCameraDisplayProperties::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
83 if (!supports(prop)) {
85 emit supportAdded(prop);
86 }
87 }
88
89
97 return (m_propertiesUsed & prop) == prop;
98 }
99
100
107 return (*m_propertyValues)[prop];
108 }
109
110
117 // Gives a random number between 0 and 255
118 int red = 0;
119 int green = 0;
120 int blue = 0;
121
122 // Generate dark
123 while(red + green + blue < 300) {
124 red = rand() % 256;
125 green = rand() % 256;
126 blue = rand() % 256;
127 }
128
129 return QColor(red, green, blue, 60);
130 }
131
132
139 void GuiCameraDisplayProperties::save(QXmlStreamWriter &stream, const Project *project,
140 FileName newProjectRoot) const {
141 stream.writeStartElement("displayProperties");
142
143 stream.writeAttribute("displayName", displayName());
144
145 // Get hex-encoded data
146 QBuffer dataBuffer;
147 dataBuffer.open(QIODevice::ReadWrite);
148 QDataStream propsStream(&dataBuffer);
149 propsStream << *m_propertyValues;
150 dataBuffer.seek(0);
151
152 stream.writeCharacters(dataBuffer.data().toHex());
153
154 stream.writeEndElement();
155 }
156
157
163 setValue(Color, QVariant::fromValue(newColor));
164 }
165
166
172 setValue(Selected, newValue);
173 }
174
175
181 setValue(ShowLabel, newValue);
182 }
183
184
191 QList<GuiCameraDisplayProperties *> displays = senderToData(sender());
192
193 bool value = getValue(ShowLabel).toBool();
194 value = !value;
195
197 foreach(display, displays) {
198 display->setShowLabel(value);
199 }
200 }
201
202
212 if ((*m_propertyValues)[prop] != value) {
213 (*m_propertyValues)[prop] = value;
214
215 if (supports(prop)) {
216 emit propertyChanged(this);
217 }
218 }
219 }
220
221
227 QList<GuiCameraDisplayProperties *> GuiCameraDisplayProperties::senderToData(
228 QObject *senderObj) {
229 QList<GuiCameraDisplayProperties *> data;
230
231 if (senderObj) {
232 QAction *caller = (QAction *)senderObj;
233 QVariant callerData = caller->data();
234
235 if (callerData.canConvert< QList<GuiCameraDisplayProperties *> >() ) {
236 data = callerData.value< QList<GuiCameraDisplayProperties *> >();
237 }
238 }
239
240 return data;
241 }
242
243
244}
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 GUI communication mechanism for target body objects.
static QColor randomColor()
Creates and returns a random color for the intial color of the footprint polygon.
void setColor(QColor newColor)
Change the color associated with this target.
void setValue(Property prop, QVariant value)
This is the generic mutator for properties.
void toggleShowLabel()
Change the visibility of the display name.
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)
void setSelected(bool)
Change the selected state associated with this target.
bool supports(Property prop)
Support may come later, please make sure you are connected to the supportAdded signal.
static QList< GuiCameraDisplayProperties * > senderToData(QObject *sender)
This is for the slots that have a list of display properties as associated data.
Property m_propertiesUsed
This indicates whether any widgets with this DisplayProperties is using a particular property.
void addSupport(Property prop)
Call this with every property you support, otherwise they will not communicate properly between widge...
void setShowLabel(bool)
Change the visibility of the display name associated with this target.
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 save(QXmlStreamWriter &stream, const Project *project, FileName newProjectRoot) const
Write the Gui Camera Display Properties out to an XML file.
GuiCameraDisplayProperties(QString displayName, QObject *parent=NULL)
GuiCameraDisplayProperties constructor.
QVariant getValue(Property prop) const
Get a property's associated data.
The main project for ipce.
Definition Project.h:287
This is free and unencumbered software released into the public domain.
Definition Apollo.h:16