20#include <QDialogButtonBox>
31 for (
int i = 0; i < ( vectorPattern.size() - 1 ); ++i )
33 const double dash = vectorPattern.at( i );
35 const double space = vectorPattern.at( i );
36 total += dash + space;
37 QTreeWidgetItem *entry =
new QTreeWidgetItem();
38 entry->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsEnabled );
39 entry->setText( 0, QLocale().toString( dash ) );
40 entry->setText( 1, QLocale().toString( space ) );
41 mDashSpaceTreeWidget->addTopLevelItem( entry );
44 mPatternLengthLabel->setText( QLocale().toString( total,
'f', 6 ) );
46 connect( mAddButton, &QPushButton::clicked,
this, &QgsDashSpaceWidget::mAddButton_clicked );
47 connect( mRemoveButton, &QPushButton::clicked,
this, &QgsDashSpaceWidget::mRemoveButton_clicked );
48 connect( mDashSpaceTreeWidget, &QTreeWidget::itemChanged,
this, [
this ] { emit
widgetChanged(); } );
54 for ( qreal part : pattern )
58 mPatternLengthLabel->setText( QLocale().toString( total,
'f', 6 ) );
62void QgsDashSpaceWidget::mAddButton_clicked()
65 QTreeWidgetItem *entry =
new QTreeWidgetItem();
66 entry->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsEnabled );
67 entry->setText( 0, QStringLiteral(
"5" ) );
68 entry->setText( 1, QStringLiteral(
"2" ) );
69 mDashSpaceTreeWidget->addTopLevelItem( entry );
73void QgsDashSpaceWidget::mRemoveButton_clicked()
76 QTreeWidgetItem *currentItem = mDashSpaceTreeWidget->currentItem();
79 mDashSpaceTreeWidget->takeTopLevelItem( mDashSpaceTreeWidget->indexOfTopLevelItem( currentItem ) );
86 QVector<qreal> dashVector;
87 const int nTopLevelItems = mDashSpaceTreeWidget->topLevelItemCount();
88 dashVector.reserve( nTopLevelItems * 2 );
89 for (
int i = 0; i < nTopLevelItems; ++i )
91 QTreeWidgetItem *currentItem = mDashSpaceTreeWidget->topLevelItem( i );
102 QTreeWidgetItem *headerItem = mDashSpaceTreeWidget->headerItem();
109 QVBoxLayout *vLayout =
new QVBoxLayout();
111 vLayout->addWidget( mWidget );
112 QDialogButtonBox *bbox =
new QDialogButtonBox( QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal );
113 connect( bbox, &QDialogButtonBox::accepted,
this, &QgsDashSpaceDialog::accept );
114 connect( bbox, &QDialogButtonBox::rejected,
this, &QgsDashSpaceDialog::reject );
115 vLayout->addWidget( bbox );
116 setLayout( vLayout );
117 setWindowTitle( tr(
"Custom Dash Pattern" ) );
static QIcon getThemeIcon(const QString &name, const QColor &fillColor=QColor(), const QColor &strokeColor=QColor())
Helper to get a theme icon.
QgsDashSpaceDialog(const QVector< qreal > &v, QWidget *parent=nullptr, Qt::WindowFlags f=Qt::WindowFlags())
Constructor for QgsDashSpaceDialog.
QVector< qreal > dashDotVector() const
Returns the dash pattern as a list of numbers.
void setUnit(QgsUnitTypes::RenderUnit unit)
Sets the unit type used for the dash space pattern (used to update interface labels)
static double toDouble(const QString &input, bool *ok)
Converts input string to double value.
static Q_INVOKABLE QString toAbbreviatedString(QgsUnitTypes::DistanceUnit unit)
Returns a translated abbreviation representing a distance unit.
RenderUnit
Rendering size units.