17#include "moc_qgsdashspacedialog.cpp"
21#include <QDialogButtonBox>
32 for (
int i = 0; i < ( vectorPattern.size() - 1 ); ++i )
34 const double dash = vectorPattern.at( i );
36 const double space = vectorPattern.at( i );
37 total += dash + space;
38 QTreeWidgetItem *entry =
new QTreeWidgetItem();
39 entry->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsEnabled );
40 entry->setText( 0, QLocale().toString( dash ) );
41 entry->setText( 1, QLocale().toString( space ) );
42 mDashSpaceTreeWidget->addTopLevelItem( entry );
45 mPatternLengthLabel->setText( QLocale().toString( total,
'f', 6 ) );
47 connect( mAddButton, &QPushButton::clicked,
this, &QgsDashSpaceWidget::mAddButton_clicked );
48 connect( mRemoveButton, &QPushButton::clicked,
this, &QgsDashSpaceWidget::mRemoveButton_clicked );
49 connect( mDashSpaceTreeWidget, &QTreeWidget::itemChanged,
this, [
this ] { emit
widgetChanged(); } );
55 for ( qreal part : pattern )
59 mPatternLengthLabel->setText( QLocale().toString( total,
'f', 6 ) );
63void QgsDashSpaceWidget::mAddButton_clicked()
66 QTreeWidgetItem *entry =
new QTreeWidgetItem();
67 entry->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsEnabled );
68 entry->setText( 0, QStringLiteral(
"5" ) );
69 entry->setText( 1, QStringLiteral(
"2" ) );
70 mDashSpaceTreeWidget->addTopLevelItem( entry );
74void QgsDashSpaceWidget::mRemoveButton_clicked()
77 QTreeWidgetItem *currentItem = mDashSpaceTreeWidget->currentItem();
80 mDashSpaceTreeWidget->takeTopLevelItem( mDashSpaceTreeWidget->indexOfTopLevelItem( currentItem ) );
87 QVector<qreal> dashVector;
88 const int nTopLevelItems = mDashSpaceTreeWidget->topLevelItemCount();
89 dashVector.reserve( nTopLevelItems * 2 );
90 for (
int i = 0; i < nTopLevelItems; ++i )
92 QTreeWidgetItem *currentItem = mDashSpaceTreeWidget->topLevelItem( i );
103 QTreeWidgetItem *headerItem = mDashSpaceTreeWidget->headerItem();
110 QVBoxLayout *vLayout =
new QVBoxLayout();
112 vLayout->addWidget( mWidget );
113 QDialogButtonBox *bbox =
new QDialogButtonBox( QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal );
114 connect( bbox, &QDialogButtonBox::accepted,
this, &QgsDashSpaceDialog::accept );
115 connect( bbox, &QDialogButtonBox::rejected,
this, &QgsDashSpaceDialog::reject );
116 vLayout->addWidget( bbox );
117 setLayout( vLayout );
118 setWindowTitle( tr(
"Custom Dash Pattern" ) );
RenderUnit
Rendering size units.
static QIcon getThemeIcon(const QString &name, const QColor &fillColor=QColor(), const QColor &strokeColor=QColor())
Helper to get a theme icon.
void setUnit(Qgis::RenderUnit unit)
Sets the unit type used for the dash space pattern (used to update interface labels)
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.
static double toDouble(const QString &input, bool *ok)
Converts input string to double value.
static Q_INVOKABLE QString toAbbreviatedString(Qgis::DistanceUnit unit)
Returns a translated abbreviation representing a distance unit.