Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
wonder-sk committed Sep 14, 2014
2 parents fbea7d4 + a53bf7e commit a2f5126
Show file tree
Hide file tree
Showing 9 changed files with 359 additions and 240 deletions.
2 changes: 1 addition & 1 deletion resources/context_help/HeatmapGui
@@ -1,4 +1,4 @@
<h1>Heatmap Plugin Help</h1>
<h3>Heatmap Plugin Help</h3>
<p>The Heatmap plugin uses Kernel Density Estimation to create a density (heatmap)
raster of an input point vector layer. The density is calculated based on the
number of points in a location, with larger numbers of clustered points resulting
Expand Down
2 changes: 1 addition & 1 deletion resources/context_help/PythonConsole
@@ -1,4 +1,4 @@
<h1>Python Console for QGIS</h1>
<h3>Python Console for QGIS</h3>
<a href="#console">Console</a><br>
<a href="#editor">Editor</a><br>
<a href="#settings">Settings</a><br><br>
Expand Down
25 changes: 16 additions & 9 deletions src/app/qgssnappingdialog.cpp
Expand Up @@ -30,6 +30,7 @@
#include <QLineEdit>
#include <QDockWidget>
#include <QPushButton>
#include <QDoubleSpinBox>


class QgsSnappingDock : public QDockWidget
Expand Down Expand Up @@ -172,7 +173,7 @@ void QgsSnappingDialog::apply()
snapToList << "to_vertex_and_segment";
}

toleranceList << QString::number( qobject_cast<QLineEdit*>( mLayerTreeWidget->itemWidget( currentItem, 3 ) )->text().toDouble(), 'f' );
toleranceList << QString::number( qobject_cast<QDoubleSpinBox*>( mLayerTreeWidget->itemWidget( currentItem, 3 ) )->value(), 'f' );
toleranceUnitList << QString::number( qobject_cast<QComboBox*>( mLayerTreeWidget->itemWidget( currentItem, 4 ) )->currentIndex() );

QCheckBox *cbxAvoidIntersection = qobject_cast<QCheckBox*>( mLayerTreeWidget->itemWidget( currentItem, 5 ) );
Expand Down Expand Up @@ -274,12 +275,12 @@ void QgsSnappingDialog::addLayer( QgsMapLayer *theMapLayer )
mLayerTreeWidget->setItemWidget( item, 2, cbxSnapTo );

//snapping tolerance
QLineEdit *leTolerance = new QLineEdit( mLayerTreeWidget );
QDoubleValidator *validator = new QDoubleValidator( leTolerance );
leTolerance->setValidator( validator );
leTolerance->setText( QString::number( defaultSnappingTolerance, 'f' ) );
QDoubleSpinBox* sbTolerance = new QDoubleSpinBox( mLayerTreeWidget );
sbTolerance->setRange( 0., 100000000. );
sbTolerance->setDecimals( 5 );
sbTolerance->setValue( defaultSnappingTolerance );

mLayerTreeWidget->setItemWidget( item, 3, leTolerance );
mLayerTreeWidget->setItemWidget( item, 3, sbTolerance );

//snap to vertex/ snap to segment
QComboBox *cbxUnits = new QComboBox( mLayerTreeWidget );
Expand All @@ -295,14 +296,20 @@ void QgsSnappingDialog::addLayer( QgsMapLayer *theMapLayer )
mLayerTreeWidget->setItemWidget( item, 5, cbxAvoidIntersection );
}

//resize treewidget columns
for ( int i = 0 ; i < 4 ; ++i )
{
mLayerTreeWidget->resizeColumnToContents( i );
}

int idx = layerIdList.indexOf( currentVectorLayer->id() );
if ( idx < 0 )
{
if ( myDockFlag )
{
connect( cbxEnable, SIGNAL( stateChanged( int ) ), this, SLOT( apply() ) );
connect( cbxSnapTo, SIGNAL( currentIndexChanged( int ) ), this, SLOT( apply() ) );
connect( leTolerance, SIGNAL( textEdited( const QString ) ), this, SLOT( apply() ) );
connect( sbTolerance, SIGNAL( valueChanged( double ) ), this, SLOT( apply() ) );
connect( cbxUnits, SIGNAL( currentIndexChanged( int ) ), this, SLOT( apply() ) );

if ( cbxAvoidIntersection )
Expand Down Expand Up @@ -336,7 +343,7 @@ void QgsSnappingDialog::addLayer( QgsMapLayer *theMapLayer )
}

cbxSnapTo->setCurrentIndex( snappingStringIdx );
leTolerance->setText( QString::number( toleranceList[idx].toDouble(), 'f' ) );
sbTolerance->setValue( toleranceList[idx].toDouble() );
cbxUnits->setCurrentIndex( toleranceUnitList[idx].toInt() );
if ( cbxAvoidIntersection )
{
Expand All @@ -347,7 +354,7 @@ void QgsSnappingDialog::addLayer( QgsMapLayer *theMapLayer )
{
connect( cbxEnable, SIGNAL( stateChanged( int ) ), this, SLOT( apply() ) );
connect( cbxSnapTo, SIGNAL( currentIndexChanged( int ) ), this, SLOT( apply() ) );
connect( leTolerance, SIGNAL( textEdited( const QString ) ), this, SLOT( apply() ) );
connect( sbTolerance, SIGNAL( valueChanged( double ) ), this, SLOT( apply() ) );
connect( cbxUnits, SIGNAL( currentIndexChanged( int ) ), this, SLOT( apply() ) );

if ( cbxAvoidIntersection )
Expand Down
61 changes: 61 additions & 0 deletions src/gui/symbology-ng/qgsgraduatedsymbolrendererv2widget.cpp
Expand Up @@ -414,6 +414,7 @@ QgsGraduatedSymbolRendererV2Widget::QgsGraduatedSymbolRendererV2Widget( QgsVecto
connect( btnGraduatedDelete, SIGNAL( clicked() ), this, SLOT( deleteClasses() ) );
connect( btnDeleteAllClasses, SIGNAL( clicked() ), this, SLOT( deleteAllClasses() ) );
connect( btnGraduatedAdd, SIGNAL( clicked() ), this, SLOT( addClass() ) );
connect( cbxLinkBoundaries, SIGNAL( toggled( bool ) ), this, SLOT( toggleBoundariesLink( bool ) ) );

// initialize from previously set renderer
updateUiFromRenderer();
Expand Down Expand Up @@ -699,11 +700,57 @@ void QgsGraduatedSymbolRendererV2Widget::changeRange( int rangeIdx )
{
double lowerValue = dialog.lowerValue().toDouble();
double upperValue = dialog.upperValue().toDouble();

QString label = createLabel( range.lowerValue(), range.upperValue() );
QString newLabel;

mRenderer->updateRangeUpperValue( rangeIdx, upperValue );
mRenderer->updateRangeLowerValue( rangeIdx, lowerValue );

//If the label was the label automatically generated, we generate a new one for the new range
if ( range.label() == label )
{
newLabel = createLabel( lowerValue, upperValue );
mRenderer->updateRangeLabel( rangeIdx, newLabel );
}

//If the boundaries have to stay linked, we update the ranges above and below, as well as their label if needed
if ( cbxLinkBoundaries->isChecked() )
{
if ( rangeIdx > 0 )
{
const QgsRendererRangeV2& rangeLower = mRenderer->ranges()[rangeIdx - 1];
label = createLabel( rangeLower.lowerValue(), rangeLower.upperValue() );
mRenderer->updateRangeUpperValue( rangeIdx - 1, lowerValue );

if ( label == rangeLower.label() )
{
newLabel = createLabel( rangeLower.lowerValue(), lowerValue );
mRenderer->updateRangeLabel( rangeIdx - 1, newLabel );
}
}

if ( rangeIdx < mRenderer->ranges().size() - 1 )
{
const QgsRendererRangeV2& rangeUpper = mRenderer->ranges()[rangeIdx + 1];
label = createLabel( rangeUpper.lowerValue(), rangeUpper.upperValue() );
mRenderer->updateRangeLowerValue( rangeIdx + 1, upperValue );

if ( label == rangeUpper.label() )
{
newLabel = createLabel( upperValue, rangeUpper.upperValue() );
mRenderer->updateRangeLabel( rangeIdx + 1, newLabel );
}
}
}
}
}

QString QgsGraduatedSymbolRendererV2Widget::createLabel( double lowerValue, double upperValue )
{
return QString::number( lowerValue , 'f', 4 ) + " - " + QString::number( upperValue, 'f', 4 );
}

void QgsGraduatedSymbolRendererV2Widget::addClass()
{
mModel->addClass( mGraduatedSymbol );
Expand All @@ -720,6 +767,20 @@ void QgsGraduatedSymbolRendererV2Widget::deleteAllClasses()
mModel->removeAllRows();
}

void QgsGraduatedSymbolRendererV2Widget::toggleBoundariesLink( bool linked )
{
//If the checkbox controlling the link between boundaries was unchecked and we check it, we have to link the boundaries
//This is done by updating all lower ranges to the upper value of the range above
if ( linked )
{
for ( int i = 1;i < mRenderer->ranges().size();++i )
{
mRenderer->updateRangeLowerValue( i, mRenderer->ranges()[i-1].upperValue() );
}
refreshSymbolView();
}
}

void QgsGraduatedSymbolRendererV2Widget::changeCurrentValue( QStandardItem * item )
{
if ( item->column() == 2 )
Expand Down
4 changes: 4 additions & 0 deletions src/gui/symbology-ng/qgsgraduatedsymbolrendererv2widget.h
Expand Up @@ -94,6 +94,8 @@ class GUI_EXPORT QgsGraduatedSymbolRendererV2Widget : public QgsRendererV2Widget
void deleteClasses();
/**Removes all classes from the classification*/
void deleteAllClasses();
/**Toggle the link between classes boundaries */
void toggleBoundariesLink( bool linked );

void rotationFieldChanged( QString fldName );
void sizeScaleFieldChanged( QString fldName );
Expand All @@ -115,6 +117,8 @@ class GUI_EXPORT QgsGraduatedSymbolRendererV2Widget : public QgsRendererV2Widget
void changeRangeSymbol( int rangeIdx );
void changeRange( int rangeIdx );

QString createLabel( double lowerValue, double upperValue );

void changeSelectedSymbols();

QList<QgsSymbolV2*> selectedSymbols();
Expand Down
18 changes: 12 additions & 6 deletions src/plugins/heatmap/heatmap.cpp
Expand Up @@ -33,6 +33,7 @@
#include "qgsdistancearea.h"
#include "qgscoordinatereferencesystem.h"
#include "qgslogger.h"
#include "qgsmessagebar.h"

// Qt4 Related Includes
#include <QAction>
Expand Down Expand Up @@ -111,6 +112,14 @@ void Heatmap::run()
{
HeatmapGui d( mQGisIface->mainWindow(), QgisGui::ModalDialogFlags, &mSessionSettings );

// Start working on the input vector
QgsVectorLayer* inputLayer = d.inputVectorLayer();
if ( !inputLayer )
{
mQGisIface->messageBar()->pushMessage( tr( "Layer not found" ), tr( "The heatmap plugin requires at least one point vector layer" ), QgsMessageBar::INFO, mQGisIface->messageTimeout() );
return;
}

if ( d.exec() == QDialog::Accepted )
{
// everything runs here
Expand All @@ -123,9 +132,6 @@ void Heatmap::run()
mDecay = d.decayRatio();
int kernelShape = d.kernelShape();

// Start working on the input vector
QgsVectorLayer* inputLayer = d.inputVectorLayer();

// Getting the rasterdataset in place
GDALAllRegister();

Expand All @@ -135,7 +141,7 @@ void Heatmap::run()
myDriver = GetGDALDriverManager()->GetDriverByName( d.outputFormat().toUtf8() );
if ( myDriver == NULL )
{
QMessageBox::information( 0, tr( "GDAL driver error" ), tr( "Cannot open the driver for the specified format" ) );
mQGisIface->messageBar()->pushMessage( tr( "GDAL driver error" ), tr( "Cannot open the driver for the specified format" ), QgsMessageBar::WARNING, mQGisIface->messageTimeout() );
return;
}

Expand Down Expand Up @@ -169,7 +175,7 @@ void Heatmap::run()
heatmapDS = ( GDALDataset * ) GDALOpen( TO8F( d.outputFilename() ), GA_Update );
if ( !heatmapDS )
{
QMessageBox::information( 0, tr( "Raster update error" ), tr( "Could not open the created raster for updating. The heatmap was not generated." ) );
mQGisIface->messageBar()->pushMessage( tr( "Raster update error" ), tr( "Could not open the created raster for updating. The heatmap was not generated." ), QgsMessageBar::WARNING );
return;
}
poBand = heatmapDS->GetRasterBand( 1 );
Expand Down Expand Up @@ -225,7 +231,7 @@ void Heatmap::run()
QApplication::processEvents();
if ( p.wasCanceled() )
{
QMessageBox::information( 0, tr( "Heatmap generation aborted" ), tr( "QGIS will now load the partially-computed raster." ) );
mQGisIface->messageBar()->pushMessage( tr( "Heatmap generation aborted" ), tr( "QGIS will now load the partially-computed raster" ), QgsMessageBar::INFO, mQGisIface->messageTimeout() );
break;
}

Expand Down
11 changes: 6 additions & 5 deletions src/plugins/heatmap/heatmapgui.cpp
Expand Up @@ -633,13 +633,14 @@ QString HeatmapGui::outputFormat()
QgsVectorLayer* HeatmapGui::inputVectorLayer()
{
QString myLayerId = inputLayerCombo->itemData( inputLayerCombo->currentIndex() ).toString();

QgsVectorLayer* inputLayer = qobject_cast<QgsVectorLayer *>( QgsMapLayerRegistry::instance()->mapLayer( myLayerId ) );
if ( !inputLayer )
if ( !myLayerId.isEmpty() )
{
QgsVectorLayer* inputLayer = qobject_cast<QgsVectorLayer *>( QgsMapLayerRegistry::instance()->mapLayer( myLayerId ) );
return inputLayer;
}
else
{
QMessageBox::information( 0, tr( "Layer not found" ), tr( "Layer %1 not found." ).arg( myLayerId ) );
return 0;
}
return inputLayer;
}

12 changes: 11 additions & 1 deletion src/ui/qgsgraduatedsymbolrendererv2widget.ui
Expand Up @@ -6,7 +6,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>505</width>
<width>615</width>
<height>339</height>
</rect>
</property>
Expand Down Expand Up @@ -240,6 +240,16 @@
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="cbxLinkBoundaries">
<property name="text">
<string>Link classes boundaries</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<spacer>
<property name="orientation">
Expand Down

0 comments on commit a2f5126

Please sign in to comment.