17#include "moc_qgsdashspacedialog.cpp"
21#include <QDialogButtonBox>
33 for (
int i = 0; i < ( vectorPattern.size() - 1 ); ++i )
35 const double dash = vectorPattern.at( i );
37 const double space = vectorPattern.at( i );
38 total += dash + space;
39 QTreeWidgetItem *entry =
new QTreeWidgetItem();
40 entry->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsEnabled );
41 entry->setText( 0, QLocale().toString( dash ) );
42 entry->setText( 1, QLocale().toString( space ) );
43 mDashSpaceTreeWidget->addTopLevelItem( entry );
46 mPatternLengthLabel->setText( QLocale().toString( total,
'f', 6 ) );
48 connect( mAddButton, &QPushButton::clicked,
this, &QgsDashSpaceWidget::mAddButton_clicked );
49 connect( mRemoveButton, &QPushButton::clicked,
this, &QgsDashSpaceWidget::mRemoveButton_clicked );
50 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();
109 : QDialog( parent, f )
111 QVBoxLayout *vLayout =
new QVBoxLayout();
113 vLayout->addWidget( mWidget );
114 QDialogButtonBox *bbox =
new QDialogButtonBox( QDialogButtonBox::Ok | QDialogButtonBox::Cancel, Qt::Horizontal );
115 connect( bbox, &QDialogButtonBox::accepted,
this, &QgsDashSpaceDialog::accept );
116 connect( bbox, &QDialogButtonBox::rejected,
this, &QgsDashSpaceDialog::reject );
117 vLayout->addWidget( bbox );
118 setLayout( vLayout );
119 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.