QGIS API Documentation  2.99.0-Master (69af2f5)
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
23  QString path = QgsApplication::activeThemePath();
24  if ( QFile::exists( path + iconFile ) )
25  return path + iconFile;
26 
27  // use default theme
28  return QgsApplication::defaultThemePath() + iconFile;
29 }
30 
31 QgsDashSpaceDialog::QgsDashSpaceDialog( const QVector<qreal> &v, QWidget *parent, Qt::WindowFlags f ): QDialog( parent, f )
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 
53 void QgsDashSpaceDialog::on_mAddButton_clicked()
54 {
55  //add new (default) item
56  QTreeWidgetItem *entry = new QTreeWidgetItem();
57  entry->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsEnabled );
58  entry->setText( 0, QStringLiteral( "5" ) );
59  entry->setText( 1, QStringLiteral( "2" ) );
60  mDashSpaceTreeWidget->addTopLevelItem( entry );
61 }
62 
63 void QgsDashSpaceDialog::on_mRemoveButton_clicked()
64 {
65  //get active item
66  QTreeWidgetItem *currentItem = mDashSpaceTreeWidget->currentItem();
67  if ( currentItem )
68  {
69  mDashSpaceTreeWidget->takeTopLevelItem( mDashSpaceTreeWidget->indexOfTopLevelItem( currentItem ) );
70  }
71 }
72 
73 QVector<qreal> QgsDashSpaceDialog::dashDotVector() const
74 {
75  QVector<qreal> dashVector;
76  int nTopLevelItems = mDashSpaceTreeWidget->topLevelItemCount();
77  for ( int i = 0; i < nTopLevelItems; ++i )
78  {
79  QTreeWidgetItem *currentItem = mDashSpaceTreeWidget->topLevelItem( i );
80  if ( currentItem )
81  {
82  dashVector << currentItem->text( 0 ).toDouble() << currentItem->text( 1 ).toDouble();
83  }
84  }
85  return dashVector;
86 }
87 
static QString defaultThemePath()
Returns the path to the default theme directory.
QString iconPath(const QString &iconFile)
QgsDashSpaceDialog(const QVector< qreal > &v, QWidget *parent=nullptr, Qt::WindowFlags f=0)
QVector< qreal > dashDotVector() const
static QString activeThemePath()
Returns the path to the currently active theme directory.