QGIS API Documentation  3.4.15-Madeira (e83d02e274)
qgsdashspacedialog.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgsdashspacedialog.cpp
3  ----------------------
4  begin : January 2010
5  copyright : (C) 2010 by Marco Hugentobler
6  email : marco at hugis dot net
7  ***************************************************************************
8  * *
9  * This program is free software; you can redistribute it and/or modify *
10  * it under the terms of the GNU General Public License as published by *
11  * the Free Software Foundation; either version 2 of the License, or *
12  * (at your option) any later version. *
13  * *
14  ***************************************************************************/
15 
16 #include "qgsdashspacedialog.h"
17 #include "qgsapplication.h"
18 #include <QFile>
19 
20 QgsDashSpaceDialog::QgsDashSpaceDialog( const QVector<qreal> &v, QWidget *parent, Qt::WindowFlags f ): QDialog( parent, f )
21 {
22  setupUi( this );
23  connect( mAddButton, &QPushButton::clicked, this, &QgsDashSpaceDialog::mAddButton_clicked );
24  connect( mRemoveButton, &QPushButton::clicked, this, &QgsDashSpaceDialog::mRemoveButton_clicked );
25 
26  mAddButton->setIcon( QgsApplication::getThemeIcon( "symbologyAdd.svg" ) );
27  mRemoveButton->setIcon( QgsApplication::getThemeIcon( "symbologyRemove.svg" ) );
28 
29  double dash = 0;
30  double space = 0;
31  for ( int i = 0; i < ( v.size() - 1 ); ++i )
32  {
33  dash = v.at( i );
34  ++i;
35  space = v.at( i );
36  QTreeWidgetItem *entry = new QTreeWidgetItem();
37  entry->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsEnabled );
38  entry->setText( 0, QString::number( dash ) );
39  entry->setText( 1, QString::number( space ) );
40  mDashSpaceTreeWidget->addTopLevelItem( entry );
41  }
42 }
43 
44 void QgsDashSpaceDialog::mAddButton_clicked()
45 {
46  //add new (default) item
47  QTreeWidgetItem *entry = new QTreeWidgetItem();
48  entry->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsEnabled );
49  entry->setText( 0, QStringLiteral( "5" ) );
50  entry->setText( 1, QStringLiteral( "2" ) );
51  mDashSpaceTreeWidget->addTopLevelItem( entry );
52 }
53 
54 void QgsDashSpaceDialog::mRemoveButton_clicked()
55 {
56  //get active item
57  QTreeWidgetItem *currentItem = mDashSpaceTreeWidget->currentItem();
58  if ( currentItem )
59  {
60  mDashSpaceTreeWidget->takeTopLevelItem( mDashSpaceTreeWidget->indexOfTopLevelItem( currentItem ) );
61  }
62 }
63 
64 QVector<qreal> QgsDashSpaceDialog::dashDotVector() const
65 {
66  QVector<qreal> dashVector;
67  int nTopLevelItems = mDashSpaceTreeWidget->topLevelItemCount();
68  for ( int i = 0; i < nTopLevelItems; ++i )
69  {
70  QTreeWidgetItem *currentItem = mDashSpaceTreeWidget->topLevelItem( i );
71  if ( currentItem )
72  {
73  dashVector << currentItem->text( 0 ).toDouble() << currentItem->text( 1 ).toDouble();
74  }
75  }
76  return dashVector;
77 }
78 
QVector< qreal > dashDotVector() const
static QIcon getThemeIcon(const QString &name)
Helper to get a theme icon.
QgsDashSpaceDialog(const QVector< qreal > &v, QWidget *parent=nullptr, Qt::WindowFlags f=nullptr)
Constructor for QgsDashSpaceDialog.