31 #include <QStringList> 32 #include <QStyleOptionViewItem> 42 const QColor& default_value,
43 const QString& description,
45 const char* changed_slot,
47 :
Property(name, QVariant(), description, parent, changed_slot, receiver), color_(default_value)
69 if (new_value.type() == QVariant::Color)
71 return setColor(new_value.value<QColor>());
74 QColor new_color =
parseColor(new_value.toString());
75 if (new_color.isValid())
93 color = QColor(200, 200, 200);
94 painter->setPen(QColor(Qt::lightGray));
96 QString text =
value_.toString();
97 QRect rect = option.rect;
99 rect.adjust(rect.height() + 4, 1, 0, 0);
100 painter->drawText(rect, text);
110 editor->setFrame(
false);
bool setValue(const QVariant &new_value) override
Set the new value for this property. Returns true if the new value is different from the old value...
void changed()
Emitted by setValue() just after the value has changed.
PropertyTreeModel * model_
Pointer to the PropertyTreeModel managing this property tree.
A single element of a property tree, with a name, value, description, and possibly children...
QVariant value_
This is the central property value. If you set it directly in a subclass, do so with care because man...
ColorProperty(const QString &name=QString(), const QColor &default_value=Qt::black, const QString &description=QString(), Property *parent=nullptr, const char *changed_slot=nullptr, QObject *receiver=nullptr)
static void paintColorBox(QPainter *painter, const QRect &rect, const QColor &color)
QWidget * createEditor(QWidget *parent, const QStyleOptionViewItem &option) override
Create an editor widget to edit the value of this property.
virtual Qt::ItemFlags getViewFlags(int column) const
Return item flags appropriate for the given column (0 or 1) for this Property.
virtual bool setColor(const QColor &color)
QColor parseColor(const QString &color_string)
QString printColor(const QColor &color)
void aboutToChange()
Emitted by setValue() just before the value has changed.
void emitDataChanged(Property *property)
bool paint(QPainter *painter, const QStyleOptionViewItem &option) const override
Hook to provide custom painting of the value data (right-hand column) in a subclass.