QGIS API Documentation  2.18.21-Las Palmas (9fba24a)
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 QString iconPath( const QString& iconFile )
21 {
22  // try active theme
24  if ( QFile::exists( path + iconFile ) )
25  return path + iconFile;
26 
27  // use default theme
28  return QgsApplication::defaultThemePath() + iconFile;
29 }
30 
32 {
33  setupUi( this );
34 
35  mAddButton->setIcon( QIcon( iconPath( "symbologyAdd.svg" ) ) );
36  mRemoveButton->setIcon( QIcon( iconPath( "symbologyRemove.svg" ) ) );
37 
38  double dash = 0;
39  double space = 0;
40  for ( int i = 0; i < ( v.size() - 1 ); ++i )
41  {
42  dash = v.at( i );
43  ++i;
44  space = v.at( i );
45  QTreeWidgetItem* entry = new QTreeWidgetItem();
46  entry->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsEnabled );
47  entry->setText( 0, QString::number( dash ) );
48  entry->setText( 1, QString::number( space ) );
49  mDashSpaceTreeWidget->addTopLevelItem( entry );
50  }
51 }
52 
54 {
55 
56 }
57 
58 void QgsDashSpaceDialog::on_mAddButton_clicked()
59 {
60  //add new (default) item
61  QTreeWidgetItem* entry = new QTreeWidgetItem();
62  entry->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsEnabled );
63  entry->setText( 0, "5" );
64  entry->setText( 1, "2" );
65  mDashSpaceTreeWidget->addTopLevelItem( entry );
66 }
67 
68 void QgsDashSpaceDialog::on_mRemoveButton_clicked()
69 {
70  //get active item
71  QTreeWidgetItem* currentItem = mDashSpaceTreeWidget->currentItem();
72  if ( currentItem )
73  {
74  mDashSpaceTreeWidget->takeTopLevelItem( mDashSpaceTreeWidget->indexOfTopLevelItem( currentItem ) );
75  }
76 }
77 
79 {
80  QVector<qreal> dashVector;
81  int nTopLevelItems = mDashSpaceTreeWidget->topLevelItemCount();
82  for ( int i = 0; i < nTopLevelItems; ++i )
83  {
84  QTreeWidgetItem* currentItem = mDashSpaceTreeWidget->topLevelItem( i );
85  if ( currentItem )
86  {
87  dashVector << currentItem->text( 0 ).toDouble() << currentItem->text( 1 ).toDouble();
88  }
89  }
90  return dashVector;
91 }
92 
void setupUi(QWidget *widget)
static QString defaultThemePath()
Returns the path to the default theme directory.
bool exists() const
double toDouble(bool *ok) const
QString iconPath(const QString &iconFile)
void setFlags(QFlags< Qt::ItemFlag > flags)
QString number(int n, int base)
QgsDashSpaceDialog(const QVector< qreal > &v, QWidget *parent=nullptr, const Qt::WindowFlags &f=nullptr)
const T & at(int i) const
QVector< qreal > dashDotVector() const
static QString activeThemePath()
Returns the path to the currently active theme directory.
void setText(int column, const QString &text)
typedef WindowFlags
int size() const
QString text(int column) const