diff --git a/src/legend/qgslegend.cpp b/src/legend/qgslegend.cpp index 52ca5a37185..2ea246ae6d1 100755 --- a/src/legend/qgslegend.cpp +++ b/src/legend/qgslegend.cpp @@ -51,11 +51,6 @@ QgsLegend::QgsLegend(QgisApp* app, QWidget * parent, const char *name) { connect( this, SIGNAL(selectionChanged(QTreeWidgetItem *)), this, SLOT(updateLegendItem(QTreeWidgetItem *)) ); - - connect( this, SIGNAL(doubleClicked(QTreeWidgetItem *, const QPoint &, int)), - this, SLOT(handleDoubleClickEvent(QTreeWidgetItem*))); - - //just for a test connect( this, SIGNAL(itemChanged(QTreeWidgetItem*, int)), this, SLOT(handleItemChange(QTreeWidgetItem*, int))); @@ -212,9 +207,12 @@ void QgsLegend::mouseMoveEvent(QMouseEvent * e) qWarning("mouseMoveEvent::INSERT"); #endif setCursor( QCursor(Qt::PointingHandCursor) ); - removeItem(origin); - dest->insert(origin, false); - setCurrentItem(origin); + if(origin->parent() != dest) + { + removeItem(origin); + dest->insert(origin, false); + setCurrentItem(origin); + } } else//no action { @@ -321,35 +319,50 @@ void QgsLegend::mouseReleaseEvent(QMouseEvent * e) mItemBeingMoved = NULL; } -void QgsLegend::handleDoubleClickEvent(QTreeWidgetItem* item) +void QgsLegend::mouseDoubleClickEvent(QMouseEvent* e) { -#if 0 - QgsLegendItem* li = dynamic_cast(item); + QgsLegendItem* li = dynamic_cast(currentItem()); + QgsMapLayer* ml = 0; + if(li) { if(li->type() == QgsLegendItem::LEGEND_LAYER_FILE) { - QgsLegendLayerFile* llf = dynamic_cast(li); - if(llf) - { - QgsMapLayer* ml = llf->layer(); - if (ml && ml->type() == QgsMapLayer::RASTER) - { - QgsRasterLayerProperties *rlp = new QgsRasterLayerProperties(ml); - if (rlp->exec()) - { - delete rlp; - QCoreApplication::processEvents(); - } - } - else if(ml) //vector - { - ml->showLayerProperties(); - } - } + QgsLegendLayerFile* llf = dynamic_cast(li); + ml = llf->layer(); + } + else if(li->type() == QgsLegendItem::LEGEND_LAYER) + { + QgsLegendLayer* ll = dynamic_cast(li); + ml = ll->firstMapLayer(); + } + + if (ml && ml->type() == QgsMapLayer::RASTER) + { + QgsRasterLayerProperties *rlp = new QgsRasterLayerProperties(ml); + if (rlp->exec()) + { + delete rlp; + QCoreApplication::processEvents(); + } + } + else if(ml) //vector + { + ml->showLayerProperties(); + } + } +} + +void QgsLegend::keyPressEvent(QKeyEvent* e) +{ + if(e->key() == Qt::Key_Return) + { + QTreeWidgetItem* item = currentItem(); + if(item) + { + closePersistentEditor(item, 0); } } -#endif } void QgsLegend::handleRightClickEvent(QTreeWidgetItem* item, const QPoint& position) diff --git a/src/legend/qgslegend.h b/src/legend/qgslegend.h index 7d22809b1d9..807c3d72446 100755 --- a/src/legend/qgslegend.h +++ b/src/legend/qgslegend.h @@ -203,7 +203,8 @@ protected: * @return void */ void mouseReleaseEvent(QMouseEvent * e); - + void mouseDoubleClickEvent(QMouseEvent* e); + void keyPressEvent(QKeyEvent* e); /**Stores the necessary information about the position of an item in the hierarchy. Afterwards, this item may be moved back to the original position with resetToInitialPosition()*/ void storeInitialPosition(QTreeWidgetItem* li); @@ -213,8 +214,6 @@ this item may be moved back to the original position with resetToInitialPosition private slots: - /**Calls 'handleDoubleClickEvent' on the item*/ - void handleDoubleClickEvent(QTreeWidgetItem* item); /**Calls 'handleRightClickEvent' on the item*/ void handleRightClickEvent(QTreeWidgetItem* item, const QPoint& position); /**Removes the current legend group*/ diff --git a/src/legend/qgslegendlayerfilegroup.cpp b/src/legend/qgslegendlayerfilegroup.cpp index 9a1a5fc0bf0..f1e7ec8707f 100644 --- a/src/legend/qgslegendlayerfilegroup.cpp +++ b/src/legend/qgslegendlayerfilegroup.cpp @@ -46,7 +46,7 @@ QgsLegendItem::DRAG_ACTION QgsLegendLayerFileGroup::accept(const QgsLegendItem* if(li) { LEGEND_ITEM_TYPE type = li->type(); - if ( type == LEGEND_LAYER_FILE && this != li->parent()) + if ( type == LEGEND_LAYER_FILE /*&& this != li->parent()*/) { if(child(0) == 0) { diff --git a/src/legend/qgslegendsymbologygroup.cpp b/src/legend/qgslegendsymbologygroup.cpp index a771027fa44..7cd93774a90 100644 --- a/src/legend/qgslegendsymbologygroup.cpp +++ b/src/legend/qgslegendsymbologygroup.cpp @@ -70,14 +70,13 @@ int QgsLegendSymbologyGroup::compare (QTreeWidgetItem * i,int col, bool ascendin void QgsLegendSymbologyGroup::updateLayerSymbologySettings(const QgsMapLayer* thelayer) { -#if 0 //find the legend layer group node - QTreeWidgetItem* parent = this->parent(); + QgsLegendItem* parent = dynamic_cast(this->parent()); if(!parent) { return; } - QTreeWidgetItem* sibling = 0; + QgsLegendItem* sibling = 0; QgsLegendLayerFileGroup* group = 0; for(sibling = parent->firstChild(); sibling != 0; sibling = sibling->nextSibling()) { @@ -108,5 +107,4 @@ void QgsLegendSymbologyGroup::updateLayerSymbologySettings(const QgsMapLayer* th } } } -#endif }