QGIS API Documentation  2.8.2-Wien
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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( 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.png" ) ) );
36  mRemoveButton->setIcon( QIcon( iconPath( "symbologyRemove.png" ) ) );
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 
78 QVector<qreal> QgsDashSpaceDialog::dashDotVector() const
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