Skip to content

Commit 4645dd7

Browse files
committed
[GRASS] tools window made dockable
1 parent 0ed89fc commit 4645dd7

File tree

4 files changed

+192
-214
lines changed

4 files changed

+192
-214
lines changed

src/plugins/grass/qgsgrassplugin.cpp

+17-26
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,11 @@ QgsGrassPlugin::QgsGrassPlugin( QgisInterface * theQgisInterFace )
8888

8989
QgsGrassPlugin::~QgsGrassPlugin()
9090
{
91-
if ( mTools )
92-
mTools->closeTools();
91+
QgsDebugMsg( "entered." );
92+
// When main app is closed, QgsGrassTools (probably because of dock widget) are destroyed before QgsGrassPlugin
93+
// -> do not call mTools here
94+
//if ( mTools )
95+
// mTools->closeTools();
9396
if ( mEdit )
9497
mEdit->closeEdit();
9598
QString err = QgsGrass::closeMapset();
@@ -243,35 +246,24 @@ void QgsGrassPlugin::initGui()
243246
mRegionBand->setWidth( mRegionPen.width() );
244247

245248
mapsetChanged();
249+
250+
// open tools when plugin is loaded so that main app restores tools dock widget state
251+
mTools = new QgsGrassTools( qGisInterface, qGisInterface->mainWindow() );
252+
qGisInterface->addDockWidget( Qt::RightDockWidgetArea, mTools );
246253
}
247254

248255
void QgsGrassPlugin::mapsetChanged()
249256
{
250257
if ( !QgsGrass::activeMode() )
251258
{
252-
#ifdef GRASS_DIRECT
253-
mOpenToolsAction->setEnabled( true );
254-
#else
255-
mOpenToolsAction->setEnabled( false );
256-
#endif
257259
mRegionAction->setEnabled( false );
258260
mEditRegionAction->setEnabled( false );
259261
mRegionBand->reset();
260262
mCloseMapsetAction->setEnabled( false );
261263
mNewVectorAction->setEnabled( false );
262-
263-
#if 0
264-
if ( mTools )
265-
{
266-
mTools->hide();
267-
delete mTools;
268-
mTools = 0;
269-
}
270-
#endif
271264
}
272265
else
273266
{
274-
mOpenToolsAction->setEnabled( true );
275267
mRegionAction->setEnabled( true );
276268
mEditRegionAction->setEnabled( true );
277269
mCloseMapsetAction->setEnabled( true );
@@ -282,12 +274,11 @@ void QgsGrassPlugin::mapsetChanged()
282274
mRegionAction->setChecked( on );
283275
switchRegion( on );
284276

285-
#if 0
286277
if ( mTools )
287278
{
288279
mTools->mapsetChanged();
289280
}
290-
#endif
281+
291282
QString gisdbase = QgsGrass::getDefaultGisdbase();
292283
QString location = QgsGrass::getDefaultLocation();
293284
try
@@ -304,7 +295,6 @@ void QgsGrassPlugin::mapsetChanged()
304295
setTransform();
305296
redrawRegion();
306297
}
307-
if ( mTools ) mTools->mapsetChanged();
308298
}
309299

310300
void QgsGrassPlugin::saveMapset()
@@ -475,13 +465,14 @@ void QgsGrassPlugin::addRaster()
475465
// Open tools
476466
void QgsGrassPlugin::openTools()
477467
{
468+
#if 0
478469
if ( !mTools )
479470
{
480471
mTools = new QgsGrassTools( qGisInterface, qGisInterface->mainWindow(), 0, Qt::Dialog );
481472

482473
connect( mTools, SIGNAL( regionChanged() ), this, SLOT( redrawRegion() ) );
483474
}
484-
475+
#endif
485476
mTools->show();
486477
}
487478

@@ -885,11 +876,8 @@ void QgsGrassPlugin::unload()
885876
delete mEditAction;
886877
delete mNewVectorAction;
887878

888-
if ( mToolBarPointer )
889-
{
890-
delete mToolBarPointer;
891-
mToolBarPointer = 0;
892-
}
879+
delete mToolBarPointer;
880+
mToolBarPointer = 0;
893881

894882
// disconnect slots of QgsGrassPlugin so they're not fired also after unload
895883
disconnect( mCanvas, SIGNAL( renderComplete( QPainter * ) ), this, SLOT( postRender( QPainter * ) ) );
@@ -899,6 +887,9 @@ void QgsGrassPlugin::unload()
899887
QWidget* qgis = qGisInterface->mainWindow();
900888
disconnect( qgis, SIGNAL( projectRead() ), this, SLOT( projectRead() ) );
901889
disconnect( qgis, SIGNAL( newProject() ), this, SLOT( newProject() ) );
890+
891+
delete mTools;
892+
mTools = 0;
902893
}
903894

904895
// Set icons to the current theme

src/plugins/grass/qgsgrasstools.cpp

+31-18
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,13 @@
4848
#endif
4949

5050

51-
QgsGrassTools::QgsGrassTools( QgisInterface *iface,
52-
QWidget * parent, const char * name, Qt::WindowFlags f )
53-
: QDialog( parent, f ), QgsGrassToolsBase()
51+
QgsGrassTools::QgsGrassTools( QgisInterface *iface, QWidget * parent, const char * name, Qt::WindowFlags f )
52+
: QDockWidget( parent, f )
5453
, mBrowser( 0 )
55-
, mModulesListModel( 0 ), mModelProxy( 0 ), mDirectModulesListModel( 0 ), mDirectModelProxy( 0 )
54+
, mModulesListModel( 0 )
55+
, mModelProxy( 0 )
56+
, mDirectModulesListModel( 0 )
57+
, mDirectModelProxy( 0 )
5658
{
5759
Q_UNUSED( name );
5860
setupUi( this );
@@ -65,9 +67,6 @@ QgsGrassTools::QgsGrassTools( QgisInterface *iface,
6567
mIface = iface;
6668
mCanvas = mIface->mapCanvas();
6769

68-
connect( qApp, SIGNAL( aboutToQuit() ),
69-
this, SLOT( closeTools() ) );
70-
7170
//statusBar()->hide();
7271

7372
// set the dialog title
@@ -125,23 +124,36 @@ void QgsGrassTools::showTabs()
125124
}
126125
else
127126
{
127+
#ifdef GRASS_DIRECT
128128
title = tr( "GRASS Direct Tools" );
129+
#else
130+
title = tr( "GRASS Tools" );
131+
#endif
129132
}
130133
setWindowTitle( title );
131134

132-
mTabWidget->removeTab( mTabWidget->indexOf( mModulesTreeTab ) );
135+
// we always show tabs but disabled if not active
136+
// direct mode currently disabled
133137
mTabWidget->removeTab( mTabWidget->indexOf( mDirectModulesTreeTab ) );
134-
mTabWidget->removeTab( mTabWidget->indexOf( mModulesListTab ) );
135138
mTabWidget->removeTab( mTabWidget->indexOf( mDirectModulesListTab ) );
139+
if ( mTabWidget->indexOf( mBrowser ) < 0 )
140+
{
141+
mTabWidget->insertTab( 2, mBrowser, tr( "Browser" ) );
142+
}
143+
#if 0
144+
mTabWidget->removeTab( mTabWidget->indexOf( mModulesListTab ) );
145+
mTabWidget->removeTab( mTabWidget->indexOf( mModulesTreeTab ) );
136146
mTabWidget->removeTab( mTabWidget->indexOf( mBrowser ) );
137147

148+
mTabWidget->insertTab( 0, mModulesTreeTab, tr( "Modules Tree" ) );
149+
mTabWidget->insertTab( 1, mModulesListTab, tr( "Modules List" ) );
150+
151+
repaint();
152+
#endif
153+
138154
QString conf = QgsApplication::pkgDataPath() + "/grass/config/default.qgc";
139155
if ( QgsGrass::activeMode() )
140156
{
141-
mTabWidget->insertTab( 0, mModulesTreeTab, tr( "Modules Tree" ) );
142-
mTabWidget->insertTab( 1, mModulesListTab, tr( "Modules List" ) );
143-
mTabWidget->insertTab( 2, mBrowser, tr( "Browser" ) );
144-
repaint();
145157
QgsDebugMsg( QString( "topLevelItemCount = %1" ).arg( mModulesTree->topLevelItemCount() ) );
146158
if ( mModulesTree->topLevelItemCount() == 0 )
147159
{
@@ -151,9 +163,11 @@ void QgsGrassTools::showTabs()
151163
QApplication::restoreOverrideCursor();
152164
}
153165
QgsDebugMsg( QString( "topLevelItemCount = %1" ).arg( mModulesTree->topLevelItemCount() ) );
166+
mTabWidget->setEnabled( true );
154167
}
155168
else
156169
{
170+
#ifdef GRASS_DIRECT
157171
// Remove open indirect modules tabs
158172
for ( int i = mTabWidget->count() - 1; i >= 0; i-- )
159173
{
@@ -174,6 +188,9 @@ void QgsGrassTools::showTabs()
174188
loadConfig( conf, mDirectModulesTree, mDirectModulesListModel, true );
175189
QApplication::restoreOverrideCursor();
176190
}
191+
#else
192+
mTabWidget->setEnabled( false );
193+
#endif
177194
}
178195
}
179196

@@ -463,7 +480,7 @@ void QgsGrassTools::mapsetChanged()
463480
{
464481
QgsDebugMsg( "entered." );
465482

466-
//closeTools();
483+
closeTools();
467484
showTabs();
468485
}
469486

@@ -520,16 +537,12 @@ void QgsGrassTools::closeTools()
520537
for ( int i = mTabWidget->count() - 1; i > 2; i-- )
521538
{
522539
delete mTabWidget->widget( i );
523-
mTabWidget->removeTab( i );
524540
}
525541
}
526542

527-
528-
529543
//
530544
// Helper function for Tim's experimental model list
531545
//
532-
533546
void QgsGrassTools::on_mFilterInput_textChanged( QString theText )
534547
{
535548
QgsDebugMsg( "GRASS modules filter changed to :" + theText );

src/plugins/grass/qgsgrasstools.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
#ifndef QGSGRASSTOOLS_H
1717
#define QGSGRASSTOOLS_H
1818

19+
#include <QDockWidget>
20+
1921
#include "ui_qgsgrasstoolsbase.h"
2022

2123
class QgisInterface;
@@ -27,16 +29,14 @@ class QDomElement;
2729
//
2830
// For experimental filterable list model by Tim
2931
//
30-
class QDockWidget;
3132
class QSortFilterProxyModel;
3233
class QStandardItemModel;
3334

34-
3535
/*! \class QgsGrassTools
3636
* \brief Interface to GRASS modules.
3737
*
3838
*/
39-
class QgsGrassTools: public QDialog, private Ui::QgsGrassToolsBase
39+
class QgsGrassTools: public QDockWidget, private Ui::QgsGrassToolsBase
4040
{
4141
Q_OBJECT
4242

0 commit comments

Comments
 (0)