23 #include "DataStructure.h"
25 #include "DocumentManager.h"
29 #include <QGraphicsColorizeEffect>
30 #include <QGraphicsScene>
31 #include <QGraphicsItem>
32 #include <QSvgRenderer>
33 #include <boost/concept_check.hpp>
39 explicit DataItemPrivate(DataPtr n)
42 , _font(
QFont(
"Helvetica [Cronyx]", 12))
45 , _originalWidth(n->width())
47 , _oldDataType(n->dataStructure()->document()->dataType(n->dataType()))
53 qDeleteAll(_propertyValues);
54 _propertyValues.clear();
68 DataTypePtr _oldDataType;
73 , d(new DataItemPrivate(n))
77 connect(d->_oldDataType.get(), SIGNAL(iconChanged(
QString)),
this, SLOT(updateIcon()));
84 connect(n.get(), SIGNAL(colorChanged(
QColor)),
this, SLOT(updateColor()));
85 connect(n.get(), SIGNAL(posChanged(
QPointF)),
this, SLOT(updatePos()));
86 connect(n.get(), SIGNAL(visibilityChanged(
bool)),
this, SLOT(updateVisibility(
bool)));
87 connect(n.get(), SIGNAL(useColorChanged(
bool)),
this, SLOT(updateColor()));
88 connect(n.get(), SIGNAL(widthChanged(
double)),
this, SLOT(updateSize()));
89 connect(n.get(), SIGNAL(dataTypeChanged(
int)),
this, SLOT(setupNode()));
93 setFlag(ItemIsSelectable,
true);
107 void DataItem::setupNode()
109 if (d->_data.get()->dataStructure()->document()->dataType(d->_data.get()->dataType()) != d->_oldDataType) {
110 disconnect(d->_oldDataType.get(), SIGNAL(iconChanged(
QString)),
this, SLOT(updateIcon()));
111 d->_oldDataType = d->_data.get()->dataStructure()->document()->dataType(d->_data.get()->dataType());
112 connect(d->_oldDataType.get(), SIGNAL(iconChanged(
QString)),
this, SLOT(updateIcon()));
117 registerProperty(property);
128 void DataItem::updatePos()
131 setPos(d->_data->x() - fixPos, d->_data->y() - fixPos);
132 updatePropertyList();
135 void DataItem::updateSize()
137 if (d->_data->width() == d->_width) {
141 d->_width = d->_data->width();
145 void DataItem::updateRenderer()
147 QString iconPackage = d->_data->dataStructure()->document()->iconPackage();
151 void DataItem::updateIcon()
153 QString icon = d->_data->dataStructure()->document()->dataType(d->_data->dataType())->iconName();
160 void DataItem::updateVisibility(
bool visible)
162 if (visible ==
true) {
165 while (iter != d->_propertyValues.constEnd()) {
166 (*iter)->setVisible(
true);
172 while (iter != d->_propertyValues.constEnd()) {
173 (*iter)->setVisible(
false);
179 void DataItem::updateColor()
182 delete d->_colorizer;
184 d->_colorizer->setColor(c);
188 void DataItem::updateProperty(
const QString& name)
190 if (!d->_propertyValues.contains(name)) {
191 registerProperty(name);
194 DataTypePtr dataType =
data()->dataStructure()->document()->dataType(
data()->dataType());
196 d->_propertyValues[
name]->setVisible(dataType->isPropertyVisible(name));
197 d->_propertyValues[
name]->update();
198 updatePropertyList();
206 void DataItem::updatePropertyList()
210 if (!d->_propertyValues.contains(property)) {
211 kError() <<
"Cannot update unknown property : " <<
property;
214 if (d->_propertyValues[property]->isVisible() ==
false) {
218 d->_propertyValues[
property]->update();
223 void DataItem::registerProperty(
const QString& name)
225 if (d->_propertyValues.contains(name)) {
228 DataTypePtr dataType =
data()->dataStructure()->document()->dataType(
data()->dataType());
230 d->_propertyValues[
name]->setFlags(ItemIgnoresTransformations);
231 d->_propertyValues[
name]->setFont(d->_font);
232 d->_propertyValues[
name]->setVisible(dataType->isPropertyVisible(name));
233 d->_propertyValues[
name]->setZValue(
zValue() + 1);
234 d->_item->addToGroup(d->_propertyValues[name]);
236 updatePropertyList();
239 void DataItem::removeProperty(
const QString& name)
241 if (d->_propertyValues.contains(name)) {
242 kWarning() <<
"Property not removed: not registered at DataItem.";
245 d->_propertyValues[
name]->setVisible(
false);
246 d->_item->removeFromGroup(d->_propertyValues[name]);
247 delete d->_propertyValues[
name];
248 d->_propertyValues.remove(name);
250 updatePropertyList();
void setScale(qreal factor)
void setGraphicsEffect(QGraphicsEffect *effect)
void setFlag(GraphicsItemFlag flag, bool enabled)
static GraphicsLayout * self()
bool disconnect(const QObject *sender, const char *signal, const QObject *receiver, const char *method)
void update(const QRectF &rect)
const char * name() const
QVariant property(const char *name) const
virtual QRectF boundingRect() const
void setPos(const QPointF &pos)
QByteArray toLatin1() const
void setCacheMode(CacheMode mode, const QSize &logicalCacheSize)
char * toString(const T &value)
QString elementId() const
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
QGraphicsItem * propertyListItem() const
void setSharedRenderer(QSvgRenderer *renderer)