Skip to content
Permalink
Browse files
Double-click handling, changed current layer handling
  • Loading branch information
wonder-sk committed May 21, 2014
1 parent ca97459 commit bbdf1444c8dab3b610a7052ef1fe8f726de28398
Showing with 65 additions and 18 deletions.
  1. +28 −1 src/app/qgisapp.cpp
  2. +2 −0 src/app/qgisapp.h
  3. +32 −14 src/gui/layertree/qgslayertreeview.cpp
  4. +3 −3 src/gui/layertree/qgslayertreeview.h
@@ -375,6 +375,30 @@ void QgisApp::emitCustomSrsValidation( QgsCoordinateReferenceSystem &srs )
emit customSrsValidation( srs );
}

void QgisApp::layerTreeViewDoubleClicked(const QModelIndex& index)
{
Q_UNUSED( index );

QSettings settings;
switch ( settings.value( "/qgis/legendDoubleClickAction", 0 ).toInt() )
{
case 0:
QgisApp::instance()->layerProperties();
break;
case 1:
QgisApp::instance()->attributeTable();
break;
default:
break;
}
}

void QgisApp::activeLayerChanged(QgsMapLayer* layer)
{
if ( mMapCanvas )
mMapCanvas->setCurrentLayer( layer );
}

/**
* This function contains forced validation of CRS used in QGIS.
* There are 3 options depending on the settings:
@@ -2359,6 +2383,9 @@ void QgisApp::initLayerTreeView()
mLayerTreeView->setModel( model );
mLayerTreeView->setMenuProvider( new QgsAppLayerTreeViewMenuProvider(mLayerTreeView, mMapCanvas) );

connect( mLayerTreeView, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(layerTreeViewDoubleClicked(QModelIndex)) );
connect( mLayerTreeView, SIGNAL(currentLayerChanged(QgsMapLayer*)), this, SLOT(activeLayerChanged(QgsMapLayer*)) );

mLayerTreeDock->setWidget( mLayerTreeView );
addDockWidget( Qt::LeftDockWidgetArea, mLayerTreeDock );
}
@@ -7474,7 +7501,7 @@ void QgisApp::openURL( QString url, bool useQgisDocDirectory )
/** Get a pointer to the currently selected map layer */
QgsMapLayer *QgisApp::activeLayer()
{
return mMapLegend ? mMapLegend->currentLayer() : 0;
return mLayerTreeView ? mLayerTreeView->currentLayer() : 0;
}

/** set the current layer */
@@ -466,6 +466,8 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow
#endif

public slots:
void layerTreeViewDoubleClicked(const QModelIndex& index);
void activeLayerChanged(QgsMapLayer* layer);
//! Zoom to full extent
void zoomFull();
//! Zoom to the previous extent
@@ -9,7 +9,6 @@

QgsLayerTreeView::QgsLayerTreeView(QWidget *parent)
: QTreeView(parent)
, mCurrentLayer(0)
, mDefaultActions(0)
, mMenuProvider(0)
{
@@ -18,6 +17,7 @@ QgsLayerTreeView::QgsLayerTreeView(QWidget *parent)
setDragEnabled(true);
setAcceptDrops(true);
setDropIndicatorShown(true);
setEditTriggers(EditKeyPressed | SelectedClicked);

setSelectionMode(ExtendedSelection);

@@ -39,7 +39,7 @@ void QgsLayerTreeView::setModel(QAbstractItemModel* model)

QTreeView::setModel(model);

connect(selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)), this, SLOT(onCurrentChanged(QModelIndex)));
connect(selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)), this, SLOT(onCurrentChanged(QModelIndex,QModelIndex)));

updateExpandedStateFromNode(layerTreeModel()->rootGroup());
}
@@ -64,16 +64,16 @@ void QgsLayerTreeView::setMenuProvider(QgsLayerTreeViewMenuProvider* menuProvide

QgsMapLayer* QgsLayerTreeView::currentLayer() const
{
return mCurrentLayer;
return layerForIndex( currentIndex() );
}

void QgsLayerTreeView::setCurrentLayer(QgsMapLayer* layer)
{
if (mCurrentLayer == layer)
QgsLayerTreeLayer* nodeLayer = layerTreeModel()->rootGroup()->findLayer(layer->id());
if (!nodeLayer)
return;

mCurrentLayer = layer;
emit currentLayerChanged(mCurrentLayer);
setCurrentIndex( layerTreeModel()->node2index(nodeLayer) );
}


@@ -117,17 +117,16 @@ void QgsLayerTreeView::updateExpandedStateToNode(QModelIndex index)
node->setExpanded(isExpanded(index));
}

void QgsLayerTreeView::onCurrentChanged(QModelIndex current)
void QgsLayerTreeView::onCurrentChanged(QModelIndex current, QModelIndex previous)
{
QgsLayerTreeNode* node = layerTreeModel()->index2node(current);
if (!node)
return; // TODO: maybe also support symbology nodes
QgsMapLayer* layerPrevious = layerForIndex(previous);
QgsMapLayer* layerCurrent = layerForIndex(current);

QgsMapLayer* layer = 0;
if (node->nodeType() == QgsLayerTreeNode::NodeLayer)
layer = static_cast<QgsLayerTreeLayer*>(node)->layer();
if (layerPrevious == layerCurrent)
return;

setCurrentLayer(layer);
qDebug("current layer changed!");
emit currentLayerChanged(layerCurrent);
}

void QgsLayerTreeView::updateExpandedStateFromNode(QgsLayerTreeNode* node)
@@ -139,6 +138,25 @@ void QgsLayerTreeView::updateExpandedStateFromNode(QgsLayerTreeNode* node)
updateExpandedStateFromNode(child);
}

QgsMapLayer* QgsLayerTreeView::layerForIndex(const QModelIndex& index) const
{
QgsLayerTreeNode* node = layerTreeModel()->index2node(index);
if (node)
{
if (node->nodeType() == QgsLayerTreeNode::NodeLayer)
return static_cast<QgsLayerTreeLayer*>(node)->layer();
}
else
{
// possibly a symbology node
QgsLayerTreeModelSymbologyNode* symnode = layerTreeModel()->index2symnode(index);
if (symnode)
return symnode->parent()->layer();
}

return 0;
}

QgsLayerTreeNode* QgsLayerTreeView::currentNode() const
{
return layerTreeModel()->index2node(selectionModel()->currentIndex());
@@ -41,6 +41,8 @@ class GUI_EXPORT QgsLayerTreeView : public QTreeView

void updateExpandedStateFromNode(QgsLayerTreeNode* node);

QgsMapLayer* layerForIndex(const QModelIndex& index) const;

signals:
void currentLayerChanged(QgsMapLayer* layer);

@@ -52,11 +54,9 @@ protected slots:

void updateExpandedStateToNode(QModelIndex index);

void onCurrentChanged(QModelIndex current);
void onCurrentChanged(QModelIndex current, QModelIndex previous);

protected:
QgsMapLayer* mCurrentLayer;

QgsLayerTreeViewDefaultActions* mDefaultActions;
QgsLayerTreeViewMenuProvider* mMenuProvider;
};

0 comments on commit bbdf144

Please sign in to comment.