Skip to content

Commit d14dcd3

Browse files
author
mhugent
committedDec 30, 2005
replaced the Q3PopupMenu in the legend with the qt4 QMenu. Unfortunately, i couldn't find a way to bring the QSlider of the raster right click menu into QMenu (qgsrasterlayer.cpp, l. 3755)
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@4420 c8812cc2-4d05-0410-92ff-de0c093fc19c

File tree

10 files changed

+154
-122
lines changed

10 files changed

+154
-122
lines changed
 

‎src/legend/qgslegend.cpp

Lines changed: 97 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
#include <iostream>
3838
#include <QTreeWidgetItem>
3939
#include <Q3PopupMenu>
40+
#include <QMenu>
4041
#include <QFont>
4142
#include <QHeaderView>
4243

@@ -363,6 +364,59 @@ void QgsLegend::mouseDoubleClickEvent(QMouseEvent* e)
363364
}
364365
}
365366

367+
void QgsLegend::handleRightClickEvent(QTreeWidgetItem* item, const QPoint& position)
368+
{
369+
QMenu theMenu;
370+
371+
#if defined(Q_OS_MACX) || defined(WIN32)
372+
QString iconsPath(QCoreApplication::applicationDirPath()+QString("/share/qgis/images/icons/"));
373+
#else
374+
QString iconsPath(PKGDATAPATH);
375+
iconsPath+="/images/icons/";
376+
#endif
377+
378+
if(mMapCanvas->isDrawing())
379+
{
380+
return;
381+
}
382+
383+
QgsLegendItem* li = dynamic_cast<QgsLegendItem*>(item);
384+
if(li)
385+
{
386+
if(li->type() == QgsLegendItem::LEGEND_LAYER_FILE)
387+
{
388+
(static_cast<QgsLegendLayerFile*>(li))->layer()->contextMenu()->exec(position);
389+
return;
390+
}
391+
else if(li->type() == QgsLegendItem::LEGEND_LAYER)
392+
{
393+
theMenu.addAction(tr("&Properties"), this, SLOT(legendLayerShowProperties()));
394+
theMenu.addAction(QIcon(QPixmap(iconsPath+QString("inoverview.png"))), tr("&Add to overview"), this, SLOT(legendLayerAddToOverview()));
395+
theMenu.addAction(QIcon(QPixmap(iconsPath+QString("remove_from_overview.png"))), tr("&Remove from overview"), this, SLOT(legendLayerRemoveFromOverview()));
396+
theMenu.addAction(QIcon(QPixmap(iconsPath+QString("remove.png"))), tr("&Remove"), this, SLOT(legendLayerRemove()));
397+
}
398+
else if(li->type() == QgsLegendItem::LEGEND_GROUP)
399+
{
400+
theMenu.addAction(QPixmap(iconsPath+QString("remove.png")), tr("&Remove"), this, SLOT(legendGroupRemove()));
401+
}
402+
403+
if(li->type() == QgsLegendItem::LEGEND_LAYER || li->type() == QgsLegendItem::LEGEND_GROUP)
404+
{
405+
theMenu.addAction(tr("Re&name"), this, SLOT(openEditor()));
406+
}
407+
408+
409+
}
410+
411+
theMenu.addAction(QIcon(QPixmap(iconsPath+QString("folder_new.png"))), tr("&Add group"), this, SLOT(addGroup()));
412+
theMenu.addAction(QIcon(QPixmap(iconsPath+QString("expand_tree.png"))), tr("&Expand all"), this, SLOT(expandAll()));
413+
theMenu.addAction(QIcon(QPixmap(iconsPath+QString("collapse_tree.png"))), tr("&Collapse all"), this, SLOT(collapseAll()));
414+
415+
theMenu.exec(position);
416+
}
417+
418+
419+
#if 0
366420
void QgsLegend::handleRightClickEvent(QTreeWidgetItem* item, const QPoint& position)
367421
{
368422
#ifdef QGISDEBUG
@@ -430,6 +484,7 @@ void QgsLegend::handleRightClickEvent(QTreeWidgetItem* item, const QPoint& posit
430484
}
431485
}
432486
}
487+
#endif
433488

434489
int QgsLegend::getItemPos(QTreeWidgetItem* item)
435490
{
@@ -805,11 +860,17 @@ bool QgsLegend::readXML(QDomNode& legendnode)
805860
{
806861
group = new QgsLegendGroup(legendlayerelem.attribute("name"));
807862
insertTopLevelItem(0, group);
863+
808864
open = legendlayerelem.attribute("open");
809865
if(open == "true")
810-
{
811-
expandItem(group);
812-
}
866+
{
867+
setItemExpanded(group, true); //expand or collapse the item
868+
}
869+
else
870+
{
871+
setItemExpanded(group, false);
872+
}
873+
813874
if(prevchild)
814875
{
815876
moveItem(group, prevchild);
@@ -844,20 +905,30 @@ bool QgsLegend::readXML(QDomNode& legendnode)
844905
}
845906
}
846907
if(open == "true")
847-
{
848-
expandItem(theItem);
849-
}
908+
{
909+
setItemExpanded(theItem, true);
910+
}
911+
else
912+
{
913+
setItemExpanded(theItem, false);
914+
}
850915
theItem->setText(0, legendlayerelem.attribute("name"));
851916

852917
//file group
853918
secondLevelItem = theItem->firstChild();
854919
QDomNode filegroupnode = child.firstChild();
855920
QDomElement filegroupelem = filegroupnode.toElement();
921+
856922
open = filegroupelem.attribute("open");
857923
if(open == "true")
858-
{
859-
expandItem(secondLevelItem);
860-
}
924+
{
925+
setItemExpanded(secondLevelItem, true);
926+
}
927+
else
928+
{
929+
setItemExpanded(secondLevelItem, false);
930+
}
931+
861932
QDomNode layerfilenode = filegroupnode.firstChild();
862933
QDomElement layerfileelem = layerfilenode.toElement();
863934

@@ -923,6 +994,7 @@ bool QgsLegend::readXML(QDomNode& legendnode)
923994
mStateOfCheckBoxes.insert(std::make_pair(newfile, Qt::Unchecked));
924995
}
925996
newlayer->setLegendLayerFile(newfile);
997+
newlayer->setLegendSymbologyGroupParent(dynamic_cast<QgsLegendSymbologyGroup*>(secondLevelItem->nextSibling()));
926998
newlayer->initContextMenu(mApp);
927999

9281000
//move newfile as the last child of the legendlayerfilegroup
@@ -939,20 +1011,30 @@ bool QgsLegend::readXML(QDomNode& legendnode)
9391011
secondLevelItem = secondLevelItem->nextSibling();
9401012
QDomNode symbologygroupnode = filegroupnode.nextSibling();
9411013
QDomElement symbologygroupelem = symbologygroupnode.toElement();
1014+
9421015
open = symbologygroupelem.attribute("open");
9431016
if(open == "true")
944-
{
945-
expandItem(secondLevelItem);
946-
}
1017+
{
1018+
setItemExpanded(secondLevelItem, true);//expand or collapse the item
1019+
}
1020+
else
1021+
{
1022+
setItemExpanded(secondLevelItem, false);
1023+
}
9471024

9481025
//property group
9491026
secondLevelItem = secondLevelItem->nextSibling();
9501027
QDomNode propertygroupnode = symbologygroupnode.nextSibling();
9511028
QDomElement propertygroupelem = propertygroupnode.toElement();
9521029
open = propertygroupelem.attribute("open");
953-
{
954-
expandItem(secondLevelItem);
955-
}
1030+
if(open == "true")
1031+
{
1032+
setItemExpanded(secondLevelItem, true);
1033+
}
1034+
else
1035+
{
1036+
setItemExpanded(secondLevelItem, false);
1037+
}
9561038

9571039
if(child.nextSibling().isNull() && !child.parentNode().isNull()) //go one hierarchy step up
9581040
{

‎src/legend/qgslegendlayer.cpp

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ bool QgsLegendLayer::isLeafNode()
8282

8383
QgsLegendItem::DRAG_ACTION QgsLegendLayer::accept(LEGEND_ITEM_TYPE type)
8484
{
85-
if ( type == LEGEND_LAYER)
85+
if ( type == LEGEND_LAYER || type == LEGEND_GROUP)
8686
{
8787
return REORDER;
8888
}
@@ -100,27 +100,14 @@ QgsLegendItem::DRAG_ACTION QgsLegendLayer::accept(const QgsLegendItem* li) const
100100
if(li && li != this)
101101
{
102102
LEGEND_ITEM_TYPE type = li->type();
103-
if ( type == LEGEND_LAYER)//todo: only if both layers toplevel or both symbology compatible
103+
if ( type == LEGEND_LAYER || type == LEGEND_GROUP)
104104
{
105105
return REORDER;
106106
}
107107
}
108108
return NO_ACTION;
109109
}
110110

111-
void QgsLegendLayer::handleRightClickEvent(const QPoint& position)
112-
{
113-
/*QgsMapLayer* ml = firstMapLayer();
114-
if(ml)
115-
{
116-
QPopupMenu *mPopupMenu = ml->contextMenu();
117-
if (mPopupMenu)
118-
{
119-
mPopupMenu->exec(position);
120-
}
121-
}*/
122-
}
123-
124111
QgsMapLayer* QgsLegendLayer::firstMapLayer()
125112
{
126113
QTreeWidgetItem* llfgroup = QTreeWidgetItem::child(0); //the legend layer file group

‎src/legend/qgslegendlayer.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ class QgsLegendLayer : public QgsLegendItem, public QObject //for signal/ slot
4444
bool isLeafNode();
4545
QgsLegendItem::DRAG_ACTION accept(LEGEND_ITEM_TYPE type);
4646
QgsLegendItem::DRAG_ACTION accept(const QgsLegendItem* li) const;
47-
void handleRightClickEvent(const QPoint& position);
4847
/**Returns the map layer associated with the first QgsLegendLayerFile or 0 if
4948
there is no QgsLegendLayerFile*/
5049
QgsMapLayer* firstMapLayer();

‎src/legend/qgslegendlayerfile.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ QgsLegendLayerFile::QgsLegendLayerFile(QTreeWidgetItem * theLegendItem, QString
4141
QPainter p(&originalPixmap);
4242
p.drawPixmap(0,0,inOverviewPixmap);
4343
}
44-
QIcon originalIcon(originalPixmap);
4544
setFlags(Qt::ItemIsUserCheckable | Qt::ItemIsEnabled | Qt::ItemIsSelectable);
45+
QIcon originalIcon(originalPixmap);
4646
setCheckState (0, Qt::Checked );
4747
setText(0, theString);
4848
setIcon(0, originalIcon);
@@ -65,8 +65,8 @@ QgsLegendLayerFile::QgsLegendLayerFile(QString theString, QgsMapLayer* theLayer)
6565
QPainter p(&originalPixmap);
6666
p.drawPixmap(0,0,inOverviewPixmap);
6767
}
68-
QIcon originalIcon(originalPixmap);
6968
setFlags(Qt::ItemIsUserCheckable | Qt::ItemIsEnabled | Qt::ItemIsSelectable);
69+
QIcon originalIcon(originalPixmap);
7070
setCheckState (0, Qt::Checked );
7171
setText(0, theString);
7272
setIcon(0, originalIcon);

‎src/qgsmaplayer.cpp

Lines changed: 12 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
#include <qlabel.h>
2929
#include <q3listview.h>
3030
#include <qpainter.h>
31-
#include <q3popupmenu.h>
3231
#include <qevent.h>
3332

3433
#include "qgisapp.h"
@@ -40,6 +39,7 @@
4039
#include "qgslegendlayerfile.h"
4140
#include "qgslegendsymbologygroup.h"
4241
//Added by qt3to4:
42+
#include <QAction>
4343
#include <QPixmap>
4444
#include <QKeyEvent>
4545
#include <Q3Frame>
@@ -54,7 +54,7 @@ QgsMapLayer::QgsMapLayer(int type,
5454
// can be used) until we learn otherwise
5555
dataSource(source),
5656
internalName(lyrname),
57-
mShowInOverviewItemId(0),
57+
mShowInOverviewAction(0),
5858
mShowInOverview(false),
5959
mCoordinateTransform(0),
6060
mLegendSymbologyGroupParent(0),
@@ -474,11 +474,10 @@ void QgsMapLayer::invalidTransformInput()
474474

475475
void QgsMapLayer::updateOverviewPopupItem()
476476
{
477-
if (mShowInOverviewItemId != 0)
477+
if (mShowInOverviewAction)
478478
{
479-
popMenu->setItemChecked(mShowInOverviewItemId,mShowInOverview);
479+
mShowInOverviewAction->setChecked(mShowInOverview);
480480
}
481-
482481
}
483482

484483
const int &QgsMapLayer::featureType()
@@ -492,11 +491,6 @@ void QgsMapLayer::setFeatureType(const int &_newVal)
492491
geometryType = _newVal;
493492
}
494493

495-
Q3PopupMenu *QgsMapLayer::contextMenu()
496-
{
497-
return 0;
498-
}
499-
500494
std::vector<QgsField> const & QgsMapLayer::fields() const
501495
{
502496
static std::vector<QgsField> bogus; // bogus empty container
@@ -514,39 +508,24 @@ void QgsMapLayer::connectNotify( const char * signal )
514508

515509
void QgsMapLayer::initContextMenu(QgisApp * app)
516510
{
517-
popMenu = new Q3PopupMenu();
518-
519-
#if QT_VERSION < 0x040000
520-
myPopupLabel = new QLabel( popMenu );
521-
522-
myPopupLabel->setFrameStyle( Q3Frame::Panel | Q3Frame::Raised );
511+
popMenu = new QMenu();
523512

524-
// now set by children
525-
// myPopupLabel->setText( tr("<center><b>Vector Layer</b></center>") );
526-
527-
popMenu->insertItem(myPopupLabel,0);
528-
#else
529513
// Initialise and insert Qt4 QAction
530514
myPopupLabel = new QAction( popMenu );
531-
532515
popMenu->addAction(myPopupLabel);
533-
#endif
534-
535-
popMenu->insertItem(tr("&Zoom to extent of selected layer"), app, SLOT(zoomToLayerExtent()));
536-
popMenu->insertSeparator();
537-
538-
//disabled by Tim during Qt4 dialogs port FIXME !!!
539-
//app->actionInOverview->addTo( popMenu );
540-
mShowInOverviewItemId = popMenu->idAt(3);
541516

542-
popMenu->insertSeparator();
543-
popMenu->insertItem(tr("&Remove"), app, SLOT(removeLayer()));
517+
popMenu->addAction(tr("&Zoom to extent of selected layer"), app, SLOT(zoomToLayerExtent()));
518+
mShowInOverviewAction = popMenu->addAction(tr("Toggle in Overview"), app, SLOT(inOverview(bool)));
519+
mShowInOverviewAction->setCheckable(true);
520+
popMenu->addSeparator();
521+
popMenu->addSeparator();
522+
popMenu->addAction(tr("&Remove"), app, SLOT(removeLayer()));
544523

545524
// now give the sub-classes a chance to tailor the context menu
546525
initContextMenu_( app );
547526
//properties goes on bottom of menu for consistency with normal ui standards
548527
//e.g. kde stuff
549-
popMenu->insertItem(tr("&Properties"), this, SLOT(showLayerProperties()));
528+
popMenu->addAction(tr("&Properties"), this, SLOT(showLayerProperties()));
550529
} // QgsMapLayer::initContextMenu(QgisApp * app)
551530

552531

‎src/qgsmaplayer.h

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,6 @@
2626
#include <qpixmap.h>
2727
#include <qglobal.h>
2828

29-
#if QT_VERSION >= 0x040000
30-
#include <QAction>
31-
#endif
32-
3329
#include <qgsrect.h>
3430
#include <qgis.h>
3531
#include <qgsfield.h>
@@ -39,8 +35,9 @@
3935
#include <QEvent>
4036
#include <QKeyEvent>
4137
#include <QLabel>
42-
#include <Q3PopupMenu>
38+
#include <QMenu>
4339

40+
class QAction;
4441
class QgisApp;
4542
class QgsMapToPixel;
4643
class QgsFeature;
@@ -158,7 +155,7 @@ class QgsMapLayer : public QObject
158155
virtual const int &featureType();
159156

160157
/** Return the context menu for the layer */
161-
virtual Q3PopupMenu *contextMenu() = 0;
158+
virtual QMenu* contextMenu(){return popMenu;}
162159

163160
/**
164161
* Returns the sublayers of this layer
@@ -414,18 +411,13 @@ public slots:
414411
QString internalName;
415412

416413
//! context menu
417-
Q3PopupMenu *popMenu;
414+
QMenu* popMenu;
418415

419-
#if QT_VERSION < 0x040000
420-
//! label for popMenu
421-
QLabel * myPopupLabel;
422-
#else
423416
//! header for popMenu
424417
QAction * myPopupLabel;
425-
#endif
426418

427-
//! checkable item id in popmenu that sets overview status
428-
int mShowInOverviewItemId;
419+
//! the action in popmenu that sets overview status
420+
QAction* mShowInOverviewAction;
429421

430422
/** Whether this layer is to be shown in the overview map or not */
431423
bool mShowInOverview;

0 commit comments

Comments
 (0)
Please sign in to comment.