32 #include <QCoreApplication>
38 #include <QStaticStringData>
39 #include <QStringData>
40 #include <QStringDataPtr>
43 #include "../ifc/ifcdef.h"
44 #include "../vproperty_p.h"
59 if (m_lineWeights.empty())
66 if (tmpIndex < 0 || tmpIndex >= m_indexList.count())
71 if (column == DPC_Data && Qt::DisplayRole == role)
73 return m_indexList.at(tmpIndex);
75 else if (column == DPC_Data && Qt::EditRole == role)
86 const QAbstractItemDelegate *delegate)
90 QComboBox* lineWeightEditor =
new QComboBox(parent);
94 lineWeightEditor->setIconSize(QSize(m_iconWidth-= 2 ,m_iconHeight-= 2));
97 lineWeightEditor->setIconSize(QSize(m_iconWidth, m_iconHeight));
99 lineWeightEditor->clear();
100 lineWeightEditor->setMinimumWidth(140);
101 lineWeightEditor->setLocale(parent->locale());
104 while (i != m_lineWeights.constEnd())
106 const qreal lineweight = QVariant(i.key()).toDouble();
107 lineWeightEditor->addItem(createIcon(lineweight), i.value(), QVariant(i.key()));
111 connect(lineWeightEditor,
static_cast<void (QComboBox::*)(
int)
>(&QComboBox::currentIndexChanged),
120 const QComboBox* lineWeightEditor = qobject_cast<const QComboBox*>(editor);
121 if (lineWeightEditor)
123 return lineWeightEditor->currentIndex();
131 this->m_lineWeights = lineWeights;
134 while (i != lineWeights.constEnd())
136 m_indexList.append(i.key());
144 return m_lineWeights;
149 int tmpIndex = value.toInt();
151 if (tmpIndex < 0 || tmpIndex >= m_indexList.count())
167 return QStringLiteral(
"lineWeight");
179 while (i != lineWeights.constEnd())
181 m_indexList.append(i.key());
184 return m_indexList.indexOf(weight);
196 QPixmap pixmap(m_iconWidth, m_iconHeight);
197 pixmap.fill(Qt::black);
199 QPen pen(Qt::black,
ToPixel(width,
Unit::Mm), Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin);
201 QPainter painter(&pixmap);
202 painter.fillRect(QRect(1, 1, m_iconWidth-2, m_iconHeight-2), QColor(Qt::white));
204 painter.drawLine(0, m_iconHeight/2, m_iconWidth, m_iconHeight/2);
206 return QIcon(pixmap);
LineWeightProperty(const QString &name)
Constructor.
virtual void setValue(const QVariant &value) Q_DECL_OVERRIDE
Sets the value of the property.
virtual QVariant getEditorData(const QWidget *editor) const Q_DECL_OVERRIDE
Gets the data from the widget.
virtual Q_REQUIRED_RESULT VProperty * clone(bool include_children=true, VProperty *container=nullptr) const Q_DECL_OVERRIDE
Clones this property.
virtual void setLineWeights(const QMap< QString, QString > &weights)
Sets the line styles.
void currentIndexChanged(int index)
virtual QVariant data(int column=DPC_Name, int role=Qt::DisplayRole) const Q_DECL_OVERRIDE
Get the data how it should be displayed.
static int indexOfLineWeight(const QMap< QString, QString > &lineWeights, const QString &weight)
QIcon createIcon(const qreal &width)
virtual QWidget * createEditor(QWidget *parent, const QStyleOptionViewItem &options, const QAbstractItemDelegate *delegate) Q_DECL_OVERRIDE
Returns an editor widget, or NULL if it doesn't supply one.
virtual QString type() const Q_DECL_OVERRIDE
Returns a string containing the type of the property.
virtual QMap< QString, QString > getLineWeights() const
Get the settings. This function has to be implemented in a subclass in order to have an effect.
QVariant VariantValue
The property's value. This does not have to be used by subclasses, but it makes sense in cases where ...
virtual Q_REQUIRED_RESULT VProperty * clone(bool include_children=true, VProperty *container=nullptr) const
Clones this property.
VPropertyPrivate * d_ptr
The protected structure holding the member variables (to assure binary compatibility)
virtual QVariant data(int column=DPC_Name, int role=Qt::DisplayRole) const
Get the data how it should be displayed.
double ToPixel(double val, const Unit &unit)