Skip to content

Commit f214a01

Browse files
committedSep 14, 2014
Merge pull request #1570 from slarosa/heatmap-plugin
[heatmap-plugin] replace messagebar to messagebox
2 parents e46aa62 + 7fdaf08 commit f214a01

File tree

2 files changed

+18
-11
lines changed

2 files changed

+18
-11
lines changed
 

‎src/plugins/heatmap/heatmap.cpp

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#include "qgsdistancearea.h"
3434
#include "qgscoordinatereferencesystem.h"
3535
#include "qgslogger.h"
36+
#include "qgsmessagebar.h"
3637

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

115+
// Start working on the input vector
116+
QgsVectorLayer* inputLayer = d.inputVectorLayer();
117+
if ( !inputLayer )
118+
{
119+
mQGisIface->messageBar()->pushMessage( tr( "Layer not found" ), tr( "The heatmap plugin requires at least one point vector layer" ), QgsMessageBar::INFO, mQGisIface->messageTimeout() );
120+
return;
121+
}
122+
114123
if ( d.exec() == QDialog::Accepted )
115124
{
116125
// everything runs here
@@ -123,9 +132,6 @@ void Heatmap::run()
123132
mDecay = d.decayRatio();
124133
int kernelShape = d.kernelShape();
125134

126-
// Start working on the input vector
127-
QgsVectorLayer* inputLayer = d.inputVectorLayer();
128-
129135
// Getting the rasterdataset in place
130136
GDALAllRegister();
131137

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

@@ -169,7 +175,7 @@ void Heatmap::run()
169175
heatmapDS = ( GDALDataset * ) GDALOpen( TO8F( d.outputFilename() ), GA_Update );
170176
if ( !heatmapDS )
171177
{
172-
QMessageBox::information( 0, tr( "Raster update error" ), tr( "Could not open the created raster for updating. The heatmap was not generated." ) );
178+
mQGisIface->messageBar()->pushMessage( tr( "Raster update error" ), tr( "Could not open the created raster for updating. The heatmap was not generated." ), QgsMessageBar::WARNING );
173179
return;
174180
}
175181
poBand = heatmapDS->GetRasterBand( 1 );
@@ -225,7 +231,7 @@ void Heatmap::run()
225231
QApplication::processEvents();
226232
if ( p.wasCanceled() )
227233
{
228-
QMessageBox::information( 0, tr( "Heatmap generation aborted" ), tr( "QGIS will now load the partially-computed raster." ) );
234+
mQGisIface->messageBar()->pushMessage( tr( "Heatmap generation aborted" ), tr( "QGIS will now load the partially-computed raster" ), QgsMessageBar::INFO, mQGisIface->messageTimeout() );
229235
break;
230236
}
231237

‎src/plugins/heatmap/heatmapgui.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -633,13 +633,14 @@ QString HeatmapGui::outputFormat()
633633
QgsVectorLayer* HeatmapGui::inputVectorLayer()
634634
{
635635
QString myLayerId = inputLayerCombo->itemData( inputLayerCombo->currentIndex() ).toString();
636-
637-
QgsVectorLayer* inputLayer = qobject_cast<QgsVectorLayer *>( QgsMapLayerRegistry::instance()->mapLayer( myLayerId ) );
638-
if ( !inputLayer )
636+
if ( !myLayerId.isEmpty() )
637+
{
638+
QgsVectorLayer* inputLayer = qobject_cast<QgsVectorLayer *>( QgsMapLayerRegistry::instance()->mapLayer( myLayerId ) );
639+
return inputLayer;
640+
}
641+
else
639642
{
640-
QMessageBox::information( 0, tr( "Layer not found" ), tr( "Layer %1 not found." ).arg( myLayerId ) );
641643
return 0;
642644
}
643-
return inputLayer;
644645
}
645646

0 commit comments

Comments
 (0)
Please sign in to comment.