~ubuntu-branches/ubuntu/wily/qgis/wily

« back to all changes in this revision

Viewing changes to src/plugins/diagram_overlay/qgslinearlyscalingdialog.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Johan Van de Wauw
  • Date: 2010-07-11 20:23:24 UTC
  • mfrom: (3.1.4 squeeze)
  • Revision ID: james.westby@ubuntu.com-20100711202324-5ktghxa7hracohmr
Tags: 1.4.0+12730-3ubuntu1
* Merge from Debian unstable (LP: #540941).
* Fix compilation issues with QT 4.7
* Add build-depends on libqt4-webkit-dev 

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
                         qgslinearlyscalingdialog.cpp  -  description
 
3
                         ----------------------------
 
4
    begin                : January 2007
 
5
    copyright            : (C) 2007 by Marco Hugentobler
 
6
    email                : marco dot hugentobler at karto dot baug dot ethz dot ch
 
7
 ***************************************************************************/
 
8
 
 
9
/***************************************************************************
 
10
 *                                                                         *
 
11
 *   This program is free software; you can redistribute it and/or modify  *
 
12
 *   it under the terms of the GNU General Public License as published by  *
 
13
 *   the Free Software Foundation; either version 2 of the License, or     *
 
14
 *   (at your option) any later version.                                   *
 
15
 *                                                                         *
 
16
 ***************************************************************************/
 
17
 
 
18
#include "qgslinearlyscalingdialog.h"
 
19
#include "qgsdiagramrenderer.h"
 
20
#include "qgsvectordataprovider.h"
 
21
#include "qgsbardiagramfactory.h"
 
22
#include "qgspiediagramfactory.h"
 
23
 
 
24
QgsLinearlyScalingDialog::QgsLinearlyScalingDialog( QgsVectorLayer* vl ): QgsDiagramRendererWidget( vl )
 
25
{
 
26
  setupUi( this );
 
27
  QObject::connect( mFindMaximumValueButton, SIGNAL( clicked() ), this, SLOT( insertMaximumAttributeValue() ) );
 
28
  mSizeUnitComboBox->addItem( tr( "Millimeter" ) );
 
29
  mSizeUnitComboBox->addItem( tr( "Map units" ) );
 
30
}
 
31
 
 
32
QgsLinearlyScalingDialog::~QgsLinearlyScalingDialog()
 
33
{
 
34
 
 
35
}
 
36
 
 
37
QgsDiagramRenderer* QgsLinearlyScalingDialog::createRenderer( int classAttr, const QgsAttributeList& attributes ) const
 
38
{
 
39
  //create a linearly scaling renderer
 
40
  QList<int> attributesList;
 
41
  attributesList.push_back( classAttr );
 
42
  QgsDiagramRenderer* renderer = new QgsDiagramRenderer( attributesList );
 
43
 
 
44
  //and items of renderer
 
45
  QList<QgsDiagramItem> itemList;
 
46
  QgsDiagramItem firstItem; firstItem.value = QVariant( 0.0 ); firstItem.size = 0;
 
47
  QgsDiagramItem secondItem;
 
48
  secondItem.value = QVariant( mValueLineEdit->text().toDouble() );
 
49
  secondItem.size = mSizeSpinBox->value();
 
50
  itemList.push_back( firstItem );
 
51
  itemList.push_back( secondItem );
 
52
  renderer->setDiagramItems( itemList );
 
53
  renderer->setItemInterpretation( QgsDiagramRenderer::LINEAR );
 
54
 
 
55
  return renderer;
 
56
}
 
57
 
 
58
void QgsLinearlyScalingDialog::applySettings( const QgsDiagramRenderer* renderer )
 
59
{
 
60
  const QgsDiagramRenderer* linearRenderer = dynamic_cast<const QgsDiagramRenderer *>( renderer );
 
61
  if ( linearRenderer )
 
62
  {
 
63
    QList<QgsDiagramItem> itemList = linearRenderer->diagramItems();
 
64
    QgsDiagramItem theItem = itemList.at( 1 ); //take the upper item
 
65
    mValueLineEdit->setText( theItem.value.toString() );
 
66
    mSizeSpinBox->setValue( theItem.size );
 
67
 
 
68
    if ( linearRenderer->factory() )
 
69
    {
 
70
      QgsDiagramFactory::SizeUnit sizeUnit = linearRenderer->factory()->sizeUnit();
 
71
      if ( sizeUnit == QgsDiagramFactory::MM )
 
72
      {
 
73
        mSizeUnitComboBox->setCurrentIndex( mSizeUnitComboBox->findText( tr( "Millimeter" ) ) );
 
74
      }
 
75
      else if ( sizeUnit == QgsDiagramFactory::MapUnits )
 
76
      {
 
77
        mSizeUnitComboBox->setCurrentIndex( mSizeUnitComboBox->findText( tr( "Map units" ) ) );
 
78
      }
 
79
    }
 
80
  }
 
81
}
 
82
 
 
83
void QgsLinearlyScalingDialog::insertMaximumAttributeValue()
 
84
{
 
85
  //find the maximum value for this attribute
 
86
  if ( mVectorLayer )
 
87
  {
 
88
    QgsVectorDataProvider *provider = dynamic_cast<QgsVectorDataProvider *>( mVectorLayer->dataProvider() );
 
89
    if ( provider )
 
90
    {
 
91
      mValueLineEdit->setText( provider->maximumValue( mClassificationField ).toString() );
 
92
    }
 
93
  }
 
94
}
 
95
 
 
96
QgsDiagramFactory::SizeUnit QgsLinearlyScalingDialog::sizeUnit() const
 
97
{
 
98
  if ( mSizeUnitComboBox->currentText() == tr( "Map units" ) )
 
99
  {
 
100
    return QgsDiagramFactory::MapUnits;
 
101
  }
 
102
  else
 
103
  {
 
104
    return QgsDiagramFactory::MM;
 
105
  }
 
106
}