measuretool.diff

Patch for enhancements. - zicke -, 2010-08-27 11:26 AM

Download (12.8 KB)

View differences:

src/app/qgsmeasuredialog.h (working copy)
66 66
  private:
67 67

  
68 68
    //! formats distance to most appropriate units
69
    QString formatDistance( double distance );
69
    QString formatDistance( double distance, int decimalPlaces );
70 70

  
71 71
    //! formats area to most appropriate units
72
    QString formatArea( double area );
72
    QString formatArea( double area, int decimalPlaces );
73 73

  
74 74
    //! shows/hides table, shows correct units
75 75
    void updateUi();
src/app/qgsoptions.cpp (working copy)
201 201
  {
202 202
    mDegreesRadioButton->setChecked( true );
203 203
  }
204

  
205

  
204
  
205
  // set decimal places of the measure tool
206
  int decimalPlaces = settings.value("/qgis/measure/decimalplaces","3").toInt();
207
  mDecimalPlacesSpinBox->setRange(0,12);
208
  mDecimalPlacesSpinBox->setValue( decimalPlaces );
209
  
210
  // set if base unit of measure tool should be changed
211
  bool baseUnit = settings.value("qgis/measure/keepbaseunit", false).toBool();
212
  if ( baseUnit == true ) 
213
  {
214
    mKeepBaseUnitCheckBox->setChecked( true );
215
  }
216
  else 
217
  {
218
    mKeepBaseUnitCheckBox->setChecked( false );
219
  }
220
  
221
  
206 222
  // add the themes to the combo box on the option dialog
207 223
  QDir myThemeDir( ":/images/themes/" );
208 224
  myThemeDir.setFilter( QDir::Dirs );
......
579 595
    angleUnitString = "gon";
580 596
  }
581 597
  settings.setValue( "/qgis/measure/angleunits", angleUnitString );
598
  
599
  
600
  int decimalPlaces = mDecimalPlacesSpinBox->value();
601
  settings.setValue( "/qgis/measure/decimalplaces", decimalPlaces );
602
  
603
  bool baseUnit = mKeepBaseUnitCheckBox->isChecked();
604
  settings.setValue( "/qgis/measure/keepbaseunit", baseUnit );
582 605

  
606
 
583 607
  //set the color for selections
584 608
  QColor myColor = pbnSelectionColor->color();
585 609
  settings.setValue( "/qgis/default_selection_color_red", myColor.red() );
src/app/qgsmeasuredialog.cpp (working copy)
50 50
  mTable->addTopLevelItem( item );
51 51

  
52 52
  //mTable->setHeaderLabels(QStringList() << tr("Segments (in meters)") << tr("Total") << tr("Azimuth") );
53
  
54
  QSettings settings;
55
  
53 56

  
54 57
  updateUi();
55 58
}
......
85 88

  
86 89
void QgsMeasureDialog::mouseMove( QgsPoint &point )
87 90
{
91
  QSettings settings;
92
  int decimalPlaces = settings.value("/qgis/measure/decimalplaces","3").toInt();
93
  
88 94
  // show current distance/area while moving the point
89 95
  // by creating a temporary copy of point array
90 96
  // and adding moving point at the end
......
93 99
    QList<QgsPoint> tmpPoints = mTool->points();
94 100
    tmpPoints.append( point );
95 101
    double area = mTool->canvas()->mapRenderer()->distanceArea()->measurePolygon( tmpPoints );
96
    editTotal->setText( formatArea( area ) );
102
    editTotal->setText( formatArea( area, decimalPlaces ) );
97 103
  }
98 104
  else if ( !mMeasureArea && mTool->points().size() > 0 )
99 105
  {
100 106
    QgsPoint p1( mTool->points().last() ), p2( point );
101 107

  
102 108
    double d = mTool->canvas()->mapRenderer()->distanceArea()->measureLine( p1, p2 );
103
    editTotal->setText( formatDistance( mTotal + d ) );
109
    editTotal->setText( formatDistance( mTotal + d, decimalPlaces ) );
104 110
    QGis::UnitType myDisplayUnits;
105 111
    // Ignore units
106 112
    convertMeasurement( d, myDisplayUnits, false );
107 113
    QTreeWidgetItem *item = mTable->topLevelItem( mTable->topLevelItemCount() - 1 );
108
    item->setText( 0, QLocale::system().toString( d, 'f', 2 ) );
114
    item->setText( 0, QLocale::system().toString( d, 'f', decimalPlaces ) );
109 115
  }
110 116
}
111 117

  
112 118
void QgsMeasureDialog::addPoint( QgsPoint &point )
113 119
{
120
  QSettings settings;
121
  int decimalPlaces = settings.value("/qgis/measure/decimalplaces","3").toInt();
122
  
114 123
  int numPoints = mTool->points().size();
115 124
  if ( mMeasureArea && numPoints > 2 )
116 125
  {
117 126
    double area = mTool->canvas()->mapRenderer()->distanceArea()->measurePolygon( mTool->points() );
118
    editTotal->setText( formatArea( area ) );
127
    editTotal->setText( formatArea( area, decimalPlaces ) );
119 128
  }
120 129
  else if ( !mMeasureArea && numPoints > 1 )
121 130
  {
......
126 135
    double d = mTool->canvas()->mapRenderer()->distanceArea()->measureLine( p1, p2 );
127 136

  
128 137
    mTotal += d;
129
    editTotal->setText( formatDistance( mTotal ) );
138
    editTotal->setText( formatDistance( mTotal, decimalPlaces ) );
130 139

  
131 140
    QGis::UnitType myDisplayUnits;
132 141
    // Ignore units
133 142
    convertMeasurement( d, myDisplayUnits, false );
134 143

  
135 144
    QTreeWidgetItem *item = mTable->topLevelItem( mTable->topLevelItemCount() - 1 );
136
    item->setText( 0, QLocale::system().toString( d, 'f', 2 ) );
145
    item->setText( 0, QLocale::system().toString( d, 'f', decimalPlaces ) );
137 146

  
138
    item = new QTreeWidgetItem( QStringList( QLocale::system().toString( 0.0, 'f', 2 ) ) );
147
    item = new QTreeWidgetItem( QStringList( QLocale::system().toString( 0.0, 'f', decimalPlaces ) ) );
139 148
    item->setTextAlignment( 0, Qt::AlignRight );
140 149
    mTable->addTopLevelItem( item );
141 150
    mTable->scrollToItem( item );
......
175 184
  settings.setValue( key, height() );
176 185
}
177 186

  
178
QString QgsMeasureDialog::formatDistance( double distance )
187
QString QgsMeasureDialog::formatDistance( double distance, int decimalPlaces )
179 188
{
189
  QSettings settings;
190
  bool baseUnit = settings.value("/qgis/measure/keepbaseunit", false).toBool();
191
  
180 192
  QGis::UnitType myDisplayUnits;
181 193
  convertMeasurement( distance, myDisplayUnits, false );
182
  return QgsDistanceArea::textUnit( distance, 2, myDisplayUnits, false );
194
  
195
  if ( baseUnit == false ) 
196
  {
197
    return QgsDistanceArea::textUnit( distance, decimalPlaces, myDisplayUnits, false );
198
  }
199
  else 
200
  {
201
    QString unitLabel;
202
  
203
    switch ( myDisplayUnits )
204
    {
205
      case QGis::Meters:
206
	unitLabel = " m";
207
	break;
208
      case QGis::Feet:
209
	    if ( fabs( distance ) == 1.0 )
210
	      unitLabel = QObject::tr( " foot" );
211
	    else
212
	      unitLabel = QObject::tr( " feet" );
213
	    break;
214
      case QGis::Degrees:
215
	  if ( fabs( distance ) == 1.0 )
216
	    unitLabel = QObject::tr( " degree" );
217
	  else
218
	    unitLabel = QObject::tr( " degrees" ); 
219
	  break;
220
      case QGis::UnknownUnit:
221
	unitLabel = QObject::tr( " unknown" );
222
	break;
223
    }
224
    
225
    return QLocale::system().toString( distance, 'f', decimalPlaces ) + unitLabel;
226
  }
227

  
183 228
}
184 229

  
185
QString QgsMeasureDialog::formatArea( double area )
230
QString QgsMeasureDialog::formatArea( double area, int decimalPlaces )
186 231
{
232
  QSettings settings;
233
  bool baseUnit = settings.value("/qgis/measure/keepbaseunit", false).toBool();
234

  
187 235
  QGis::UnitType myDisplayUnits;
188 236
  convertMeasurement( area, myDisplayUnits, true );
189
  return QgsDistanceArea::textUnit( area, 2, myDisplayUnits, true );
237
  
238
  if ( baseUnit == false ) 
239
  {
240
    return QgsDistanceArea::textUnit( area, decimalPlaces, myDisplayUnits, true );
241
  }
242
  else 
243
  {
244
    QString unitLabel;
245
  
246
    switch ( myDisplayUnits )
247
    {
248
      case QGis::Meters:
249
	unitLabel = " m2";
250
	break;
251
      case QGis::Feet:
252
	unitLabel = QObject::tr( " sq ft" );
253
	break;
254
      case QGis::Degrees:
255
	unitLabel = QObject::tr( " sq.deg." ); 
256
	break;
257
      case QGis::UnknownUnit:
258
	unitLabel = QObject::tr( " unknown" );
259
	break;
260
    }
261
    return QLocale::system().toString( area, 'f', decimalPlaces ) + unitLabel;
262
  }
263
 
190 264
}
191 265

  
192 266
void QgsMeasureDialog::updateUi()
193 267
{
268
  QSettings settings;
269
  int decimalPlaces = settings.value("/qgis/measure/decimalplaces","3").toInt();
270
  
194 271
  double dummy = 1.0;
195 272
  QGis::UnitType myDisplayUnits;
196 273
  // The dummy distance is ignored
......
216 293
  if ( mMeasureArea )
217 294
  {
218 295
    mTable->hide();
219
    editTotal->setText( formatArea( 0 ) );
296
    editTotal->setText( formatArea( 0, decimalPlaces ) );
220 297
  }
221 298
  else
222 299
  {
223 300
    mTable->show();
224
    editTotal->setText( formatDistance( 0 ) );
301
    editTotal->setText( formatDistance( 0, decimalPlaces ) );
225 302
  }
226 303

  
227 304
}
src/ui/qgsoptionsbase.ui (working copy)
7 7
    <x>0</x>
8 8
    <y>0</y>
9 9
    <width>813</width>
10
    <height>605</height>
10
    <height>622</height>
11 11
   </rect>
12 12
  </property>
13 13
  <property name="windowTitle">
......
215 215
   <item row="0" column="1">
216 216
    <widget class="QStackedWidget" name="stackedWidget">
217 217
     <property name="currentIndex">
218
      <number>0</number>
218
      <number>2</number>
219 219
     </property>
220 220
     <widget class="QWidget" name="stackedWidgetPage1">
221 221
      <layout class="QVBoxLayout" name="verticalLayout_10">
......
696 696
          <string>Measure tool</string>
697 697
         </property>
698 698
         <layout class="QGridLayout" name="gridLayout">
699
          <item row="0" column="0">
699
          <item row="1" column="0">
700 700
           <widget class="QLabel" name="textLabel1_8">
701 701
            <property name="text">
702 702
             <string>Ellipsoid for distance calculations</string>
703 703
            </property>
704 704
           </widget>
705 705
          </item>
706
          <item row="0" column="1">
706
          <item row="1" column="1">
707 707
           <widget class="QComboBox" name="cmbEllipsoid"/>
708 708
          </item>
709
          <item row="1" column="0">
709
          <item row="2" column="0">
710 710
           <widget class="QLabel" name="textLabel1_10">
711 711
            <property name="text">
712 712
             <string>Rubberband color</string>
713 713
            </property>
714 714
           </widget>
715 715
          </item>
716
          <item row="1" column="1">
716
          <item row="2" column="1">
717 717
           <widget class="QgsColorButton" name="pbnMeasureColor">
718 718
            <property name="minimumSize">
719 719
             <size>
......
726 726
            </property>
727 727
           </widget>
728 728
          </item>
729
          <item row="1" column="2" colspan="2">
729
          <item row="2" column="2" colspan="2">
730 730
           <spacer>
731 731
            <property name="orientation">
732 732
             <enum>Qt::Horizontal</enum>
......
739 739
            </property>
740 740
           </spacer>
741 741
          </item>
742
          <item row="2" column="0">
742
          <item row="5" column="0">
743 743
           <widget class="QLabel" name="textLabel1_11">
744 744
            <property name="text">
745 745
             <string>Preferred measurements units</string>
746 746
            </property>
747 747
           </widget>
748 748
          </item>
749
          <item row="2" column="1">
749
          <item row="5" column="1">
750 750
           <widget class="QRadioButton" name="radMeters">
751 751
            <property name="text">
752 752
             <string>Meters</string>
753 753
            </property>
754 754
           </widget>
755 755
          </item>
756
          <item row="2" column="2">
756
          <item row="5" column="2">
757 757
           <widget class="QRadioButton" name="radFeet">
758 758
            <property name="text">
759 759
             <string>Feet</string>
760 760
            </property>
761 761
           </widget>
762 762
          </item>
763
          <item row="3" column="0">
763
          <item row="6" column="0">
764 764
           <widget class="QLabel" name="mAngleUnitsLabel">
765 765
            <property name="text">
766 766
             <string>Preferred angle units</string>
767 767
            </property>
768 768
           </widget>
769 769
          </item>
770
          <item row="3" column="1">
770
          <item row="6" column="1">
771 771
           <widget class="QRadioButton" name="mDegreesRadioButton">
772 772
            <property name="text">
773 773
             <string>Degrees</string>
774 774
            </property>
775 775
           </widget>
776 776
          </item>
777
          <item row="3" column="2">
777
          <item row="6" column="2">
778 778
           <widget class="QRadioButton" name="mRadiansRadioButton">
779 779
            <property name="text">
780 780
             <string>Radians</string>
781 781
            </property>
782 782
           </widget>
783 783
          </item>
784
          <item row="3" column="3">
784
          <item row="6" column="3">
785 785
           <widget class="QRadioButton" name="mGonRadioButton">
786 786
            <property name="text">
787 787
             <string>Gon</string>
788 788
            </property>
789 789
           </widget>
790 790
          </item>
791
          <item row="3" column="0">
792
           <widget class="QLabel" name="label_12">
793
            <property name="text">
794
             <string>Decimal places</string>
795
            </property>
796
           </widget>
797
          </item>
798
          <item row="3" column="1">
799
           <widget class="QSpinBox" name="mDecimalPlacesSpinBox"/>
800
          </item>
801
          <item row="4" column="0">
802
           <widget class="QLabel" name="label_13">
803
            <property name="text">
804
             <string>Keep base unit</string>
805
            </property>
806
           </widget>
807
          </item>
808
          <item row="4" column="1">
809
           <widget class="QCheckBox" name="mKeepBaseUnitCheckBox">
810
            <property name="text">
811
             <string/>
812
            </property>
813
           </widget>
814
          </item>
791 815
         </layout>
792 816
        </widget>
793 817
       </item>