Skip to content
Permalink
Browse files

[GRASS] tools window made dockable

  • Loading branch information
blazek committed Apr 29, 2015
1 parent 0ed89fc commit 4645dd750dac04121dc4753bd70c859713fcc213
@@ -88,8 +88,11 @@ QgsGrassPlugin::QgsGrassPlugin( QgisInterface * theQgisInterFace )

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

mapsetChanged();

// open tools when plugin is loaded so that main app restores tools dock widget state
mTools = new QgsGrassTools( qGisInterface, qGisInterface->mainWindow() );
qGisInterface->addDockWidget( Qt::RightDockWidgetArea, mTools );
}

void QgsGrassPlugin::mapsetChanged()
{
if ( !QgsGrass::activeMode() )
{
#ifdef GRASS_DIRECT
mOpenToolsAction->setEnabled( true );
#else
mOpenToolsAction->setEnabled( false );
#endif
mRegionAction->setEnabled( false );
mEditRegionAction->setEnabled( false );
mRegionBand->reset();
mCloseMapsetAction->setEnabled( false );
mNewVectorAction->setEnabled( false );

#if 0
if ( mTools )
{
mTools->hide();
delete mTools;
mTools = 0;
}
#endif
}
else
{
mOpenToolsAction->setEnabled( true );
mRegionAction->setEnabled( true );
mEditRegionAction->setEnabled( true );
mCloseMapsetAction->setEnabled( true );
@@ -282,12 +274,11 @@ void QgsGrassPlugin::mapsetChanged()
mRegionAction->setChecked( on );
switchRegion( on );

#if 0
if ( mTools )
{
mTools->mapsetChanged();
}
#endif

QString gisdbase = QgsGrass::getDefaultGisdbase();
QString location = QgsGrass::getDefaultLocation();
try
@@ -304,7 +295,6 @@ void QgsGrassPlugin::mapsetChanged()
setTransform();
redrawRegion();
}
if ( mTools ) mTools->mapsetChanged();
}

void QgsGrassPlugin::saveMapset()
@@ -475,13 +465,14 @@ void QgsGrassPlugin::addRaster()
// Open tools
void QgsGrassPlugin::openTools()
{
#if 0
if ( !mTools )
{
mTools = new QgsGrassTools( qGisInterface, qGisInterface->mainWindow(), 0, Qt::Dialog );

connect( mTools, SIGNAL( regionChanged() ), this, SLOT( redrawRegion() ) );
}

#endif
mTools->show();
}

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

if ( mToolBarPointer )
{
delete mToolBarPointer;
mToolBarPointer = 0;
}
delete mToolBarPointer;
mToolBarPointer = 0;

// disconnect slots of QgsGrassPlugin so they're not fired also after unload
disconnect( mCanvas, SIGNAL( renderComplete( QPainter * ) ), this, SLOT( postRender( QPainter * ) ) );
@@ -899,6 +887,9 @@ void QgsGrassPlugin::unload()
QWidget* qgis = qGisInterface->mainWindow();
disconnect( qgis, SIGNAL( projectRead() ), this, SLOT( projectRead() ) );
disconnect( qgis, SIGNAL( newProject() ), this, SLOT( newProject() ) );

delete mTools;
mTools = 0;
}

// Set icons to the current theme
@@ -48,11 +48,13 @@
#endif


QgsGrassTools::QgsGrassTools( QgisInterface *iface,
QWidget * parent, const char * name, Qt::WindowFlags f )
: QDialog( parent, f ), QgsGrassToolsBase()
QgsGrassTools::QgsGrassTools( QgisInterface *iface, QWidget * parent, const char * name, Qt::WindowFlags f )
: QDockWidget( parent, f )
, mBrowser( 0 )
, mModulesListModel( 0 ), mModelProxy( 0 ), mDirectModulesListModel( 0 ), mDirectModelProxy( 0 )
, mModulesListModel( 0 )
, mModelProxy( 0 )
, mDirectModulesListModel( 0 )
, mDirectModelProxy( 0 )
{
Q_UNUSED( name );
setupUi( this );
@@ -65,9 +67,6 @@ QgsGrassTools::QgsGrassTools( QgisInterface *iface,
mIface = iface;
mCanvas = mIface->mapCanvas();

connect( qApp, SIGNAL( aboutToQuit() ),
this, SLOT( closeTools() ) );

//statusBar()->hide();

// set the dialog title
@@ -125,23 +124,36 @@ void QgsGrassTools::showTabs()
}
else
{
#ifdef GRASS_DIRECT
title = tr( "GRASS Direct Tools" );
#else
title = tr( "GRASS Tools" );
#endif
}
setWindowTitle( title );

mTabWidget->removeTab( mTabWidget->indexOf( mModulesTreeTab ) );
// we always show tabs but disabled if not active
// direct mode currently disabled
mTabWidget->removeTab( mTabWidget->indexOf( mDirectModulesTreeTab ) );
mTabWidget->removeTab( mTabWidget->indexOf( mModulesListTab ) );
mTabWidget->removeTab( mTabWidget->indexOf( mDirectModulesListTab ) );
if ( mTabWidget->indexOf( mBrowser ) < 0 )
{
mTabWidget->insertTab( 2, mBrowser, tr( "Browser" ) );
}
#if 0
mTabWidget->removeTab( mTabWidget->indexOf( mModulesListTab ) );
mTabWidget->removeTab( mTabWidget->indexOf( mModulesTreeTab ) );
mTabWidget->removeTab( mTabWidget->indexOf( mBrowser ) );

mTabWidget->insertTab( 0, mModulesTreeTab, tr( "Modules Tree" ) );
mTabWidget->insertTab( 1, mModulesListTab, tr( "Modules List" ) );

repaint();
#endif

QString conf = QgsApplication::pkgDataPath() + "/grass/config/default.qgc";
if ( QgsGrass::activeMode() )
{
mTabWidget->insertTab( 0, mModulesTreeTab, tr( "Modules Tree" ) );
mTabWidget->insertTab( 1, mModulesListTab, tr( "Modules List" ) );
mTabWidget->insertTab( 2, mBrowser, tr( "Browser" ) );
repaint();
QgsDebugMsg( QString( "topLevelItemCount = %1" ).arg( mModulesTree->topLevelItemCount() ) );
if ( mModulesTree->topLevelItemCount() == 0 )
{
@@ -151,9 +163,11 @@ void QgsGrassTools::showTabs()
QApplication::restoreOverrideCursor();
}
QgsDebugMsg( QString( "topLevelItemCount = %1" ).arg( mModulesTree->topLevelItemCount() ) );
mTabWidget->setEnabled( true );
}
else
{
#ifdef GRASS_DIRECT
// Remove open indirect modules tabs
for ( int i = mTabWidget->count() - 1; i >= 0; i-- )
{
@@ -174,6 +188,9 @@ void QgsGrassTools::showTabs()
loadConfig( conf, mDirectModulesTree, mDirectModulesListModel, true );
QApplication::restoreOverrideCursor();
}
#else
mTabWidget->setEnabled( false );
#endif
}
}

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

//closeTools();
closeTools();
showTabs();
}

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



//
// Helper function for Tim's experimental model list
//

void QgsGrassTools::on_mFilterInput_textChanged( QString theText )
{
QgsDebugMsg( "GRASS modules filter changed to :" + theText );
@@ -16,6 +16,8 @@
#ifndef QGSGRASSTOOLS_H
#define QGSGRASSTOOLS_H

#include <QDockWidget>

#include "ui_qgsgrasstoolsbase.h"

class QgisInterface;
@@ -27,16 +29,14 @@ class QDomElement;
//
// For experimental filterable list model by Tim
//
class QDockWidget;
class QSortFilterProxyModel;
class QStandardItemModel;


/*! \class QgsGrassTools
* \brief Interface to GRASS modules.
*
*/
class QgsGrassTools: public QDialog, private Ui::QgsGrassToolsBase
class QgsGrassTools: public QDockWidget, private Ui::QgsGrassToolsBase
{
Q_OBJECT

0 comments on commit 4645dd7

Please sign in to comment.
You can’t perform that action at this time.