QGIS API Documentation  master-28efcda
src/gui/symbology-ng/qgsdashspacedialog.cpp
Go to the documentation of this file.
00001 /***************************************************************************
00002     qgsdashspacedialog.cpp
00003     ----------------------
00004     begin                : January 2010
00005     copyright            : (C) 2010 by Marco Hugentobler
00006     email                : marco at hugis dot net
00007  ***************************************************************************
00008  *                                                                         *
00009  *   This program is free software; you can redistribute it and/or modify  *
00010  *   it under the terms of the GNU General Public License as published by  *
00011  *   the Free Software Foundation; either version 2 of the License, or     *
00012  *   (at your option) any later version.                                   *
00013  *                                                                         *
00014  ***************************************************************************/
00015 
00016 #include "qgsdashspacedialog.h"
00017 #include "qgsapplication.h"
00018 #include <QFile>
00019 
00020 QString iconPath( QString iconFile )
00021 {
00022   // try active theme
00023   QString path = QgsApplication::activeThemePath();
00024   if ( QFile::exists( path + iconFile ) )
00025     return path + iconFile;
00026 
00027   // use default theme
00028   return QgsApplication::defaultThemePath() + iconFile;
00029 }
00030 
00031 QgsDashSpaceDialog::QgsDashSpaceDialog( const QVector<qreal>& v, QWidget* parent, Qt::WindowFlags f ): QDialog( parent, f )
00032 {
00033   setupUi( this );
00034 
00035   mAddButton->setIcon( QIcon( iconPath( "symbologyAdd.png" ) ) );
00036   mRemoveButton->setIcon( QIcon( iconPath( "symbologyRemove.png" ) ) );
00037 
00038   double dash = 0;
00039   double space = 0;
00040   for ( int i = 0; i < ( v.size() - 1 ); ++i )
00041   {
00042     dash = v.at( i );
00043     ++i;
00044     space = v.at( i );
00045     QTreeWidgetItem* entry = new QTreeWidgetItem();
00046     entry->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsEnabled );
00047     entry->setText( 0, QString::number( dash ) );
00048     entry->setText( 1, QString::number( space ) );
00049     mDashSpaceTreeWidget->addTopLevelItem( entry );
00050   }
00051 }
00052 
00053 QgsDashSpaceDialog::~QgsDashSpaceDialog()
00054 {
00055 
00056 }
00057 
00058 void QgsDashSpaceDialog::on_mAddButton_clicked()
00059 {
00060   //add new (default) item
00061   QTreeWidgetItem* entry = new QTreeWidgetItem();
00062   entry->setFlags( Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsEnabled );
00063   entry->setText( 0, "5" );
00064   entry->setText( 1, "2" );
00065   mDashSpaceTreeWidget->addTopLevelItem( entry );
00066 }
00067 
00068 void QgsDashSpaceDialog::on_mRemoveButton_clicked()
00069 {
00070   //get active item
00071   QTreeWidgetItem* currentItem = mDashSpaceTreeWidget->currentItem();
00072   if ( currentItem )
00073   {
00074     mDashSpaceTreeWidget->takeTopLevelItem( mDashSpaceTreeWidget->indexOfTopLevelItem( currentItem ) );
00075   }
00076 }
00077 
00078 QVector<qreal> QgsDashSpaceDialog::dashDotVector() const
00079 {
00080   QVector<qreal> dashVector;
00081   int nTopLevelItems = mDashSpaceTreeWidget->topLevelItemCount();
00082   for ( int i = 0; i < nTopLevelItems; ++i )
00083   {
00084     QTreeWidgetItem* currentItem = mDashSpaceTreeWidget->topLevelItem( i );
00085     if ( currentItem )
00086     {
00087       dashVector << currentItem->text( 0 ).toDouble() << currentItem->text( 1 ).toDouble();
00088     }
00089   }
00090   return dashVector;
00091 }
00092 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines