|
65 | 65 | #include <QtGlobal> |
66 | 66 | #include <QRegExp> |
67 | 67 | #include <QRegExpValidator> |
| 68 | +#include <QTimer> |
68 | 69 | // |
69 | 70 | // Mac OS X Includes |
70 | 71 | // Must include before GEOS 3 due to unqualified use of 'Point' |
|
106 | 107 | #include "qgsmaplayerregistry.h" |
107 | 108 | #include "qgsmapoverviewcanvas.h" |
108 | 109 | #include "qgsmaprender.h" |
| 110 | +#include "qgsmaptip.h" |
109 | 111 | #include "qgsmessageviewer.h" |
110 | 112 | #include "qgsoptions.h" |
111 | 113 | #include "qgspastetransformations.h" |
112 | 114 | #include "qgspluginitem.h" |
113 | 115 | #include "qgspluginmanager.h" |
114 | 116 | #include "qgspluginregistry.h" |
| 117 | +#include "qgspoint.h" |
115 | 118 | #include "qgsproject.h" |
116 | 119 | #include "qgsprojectproperties.h" |
117 | 120 | #include "qgsproviderregistry.h" |
@@ -324,6 +327,7 @@ static void customSrsValidation_(QgsSpatialRefSys* srs) |
324 | 327 | createCanvas(); |
325 | 328 | createOverview(); |
326 | 329 | createLegend(); |
| 330 | + createMapTips(); |
327 | 331 |
|
328 | 332 | mComposer = new QgsComposer(this); // Map composer |
329 | 333 | mInternalClipboard = new QgsClipboard; // create clipboard |
@@ -395,6 +399,8 @@ static void customSrsValidation_(QgsSpatialRefSys* srs) |
395 | 399 | restoreWindowState(); |
396 | 400 |
|
397 | 401 | mSplash->showMessage(tr("QGIS Ready!"), Qt::AlignHCenter | Qt::AlignBottom); |
| 402 | + |
| 403 | + mMapTipsVisible = false; |
398 | 404 | qApp->processEvents(); |
399 | 405 | } // QgisApp ctor |
400 | 406 |
|
@@ -792,6 +798,12 @@ void QgisApp::createActions() |
792 | 798 | mActionEditPaste->setStatusTip(tr("Paste selected features")); |
793 | 799 | connect(mActionEditPaste, SIGNAL(triggered()), this, SLOT(editPaste())); |
794 | 800 | mActionEditPaste->setEnabled(false); |
| 801 | + |
| 802 | + // maptips |
| 803 | + mActionMapTips = new QAction(QIcon(myIconPath+"/mActionMapTips.png"), tr("Map Tips"), this); |
| 804 | + mActionMapTips->setStatusTip(tr("Show information about a feature when the mouse is hovered over it")); |
| 805 | + connect ( mActionMapTips, SIGNAL ( triggered() ), this, SLOT ( toggleMapTips() ) ); |
| 806 | + mActionMapTips->setCheckable(true); |
795 | 807 |
|
796 | 808 | #ifdef HAVE_PYTHON |
797 | 809 | mActionShowPythonDialog = new QAction(tr("Python console"), this); |
@@ -1036,6 +1048,7 @@ void QgisApp::createToolBars() |
1036 | 1048 | mAttributesToolBar->addAction(mActionOpenTable); |
1037 | 1049 | mAttributesToolBar->addAction(mActionMeasure); |
1038 | 1050 | mAttributesToolBar->addAction(mActionMeasureArea); |
| 1051 | + mAttributesToolBar->addAction(mActionMapTips); |
1039 | 1052 | mAttributesToolBar->addAction(mActionShowBookmarks); |
1040 | 1053 | mAttributesToolBar->addAction(mActionNewBookmark); |
1041 | 1054 | // |
@@ -1365,6 +1378,18 @@ bool QgisApp::createDB() |
1365 | 1378 | return TRUE; |
1366 | 1379 | } |
1367 | 1380 |
|
| 1381 | +void QgisApp::createMapTips() |
| 1382 | +{ |
| 1383 | + // Set up the timer for maptips. The timer is reset everytime the mouse is moved |
| 1384 | + mpMapTipsTimer = new QTimer ( mMapCanvas ); |
| 1385 | + // connect the timer to the maptips slot |
| 1386 | + connect ( mpMapTipsTimer, SIGNAL ( timeout() ), this, SLOT ( showMapTip() ) ); |
| 1387 | + // set the interval to 0.850 seconds - timer will be started next time the mouse moves |
| 1388 | + mpMapTipsTimer->setInterval ( 850 ); |
| 1389 | + // Create the maptips object |
| 1390 | + mpMaptip = new QgsMapTip (); |
| 1391 | +} |
| 1392 | + |
1368 | 1393 | // Update file menu with the current list of recently accessed projects |
1369 | 1394 | void QgisApp::updateRecentProjectPaths() |
1370 | 1395 | { |
@@ -3402,6 +3427,7 @@ void QgisApp::attributeTable() |
3402 | 3427 | mMapLegend->legendLayerAttributeTable(); |
3403 | 3428 | } |
3404 | 3429 |
|
| 3430 | + |
3405 | 3431 | void QgisApp::deleteSelected() |
3406 | 3432 | { |
3407 | 3433 | QgsMapLayer *layer = mMapLegend->currentLayer(); |
@@ -3635,6 +3661,16 @@ void QgisApp::refreshMapCanvas() |
3635 | 3661 | mMapCanvas->refresh(); |
3636 | 3662 | } |
3637 | 3663 |
|
| 3664 | +void QgisApp::toggleMapTips() |
| 3665 | +{ |
| 3666 | + mMapTipsVisible = !mMapTipsVisible; |
| 3667 | + // if off, stop the timer |
| 3668 | + if ( !mMapTipsVisible ) |
| 3669 | + { |
| 3670 | + mpMapTipsTimer->stop(); |
| 3671 | + } |
| 3672 | +} |
| 3673 | + |
3638 | 3674 | void QgisApp::toggleEditing() |
3639 | 3675 | { |
3640 | 3676 | if(mMapCanvas && mMapCanvas->isDrawing()) |
@@ -3663,8 +3699,26 @@ void QgisApp::showMouseCoordinate(QgsPoint & p) |
3663 | 3699 | { |
3664 | 3700 | mCoordsLabel->setMinimumWidth(mCoordsLabel->width()); |
3665 | 3701 | } |
| 3702 | + |
| 3703 | + if ( mMapTipsVisible ) |
| 3704 | + { |
| 3705 | + // store the point, we need it for when the maptips timer fires |
| 3706 | + mLastMapPosition = p; |
| 3707 | + |
| 3708 | + // we use this slot to control the timer for maptips since it is fired each time |
| 3709 | + // the mouse moves. |
| 3710 | + if ( mMapCanvas->underMouse() ) |
| 3711 | + { |
| 3712 | + // Clear the maptip (this is done conditionally) |
| 3713 | + mpMaptip->clear ( mMapCanvas ); |
| 3714 | + // don't start the timer if the mouse is not over the map canvas |
| 3715 | + mpMapTipsTimer->start(); |
| 3716 | + QgsDebugMsg("Started maptips timer"); |
| 3717 | + } |
| 3718 | + } |
3666 | 3719 | } |
3667 | 3720 |
|
| 3721 | + |
3668 | 3722 | void QgisApp::showScale(double theScale) |
3669 | 3723 | { |
3670 | 3724 | if (theScale >= 1.0) |
@@ -4685,6 +4739,50 @@ void QgisApp::showStatusMessage(QString theMessage) |
4685 | 4739 | statusBar()->message(theMessage); |
4686 | 4740 | } |
4687 | 4741 |
|
| 4742 | +void QgisApp::showMapTip() |
| 4743 | + |
| 4744 | +{ |
| 4745 | + /* Show the maptip using tooltip */ |
| 4746 | + // Stop the timer while we look for a maptip |
| 4747 | + mpMapTipsTimer->stop(); |
| 4748 | + |
| 4749 | + // Only show tooltip if the mouse is over the canvas |
| 4750 | + if ( mMapCanvas->underMouse() ) |
| 4751 | + { |
| 4752 | + QPoint myPointerPos = mMapCanvas->mouseLastXY(); |
| 4753 | + |
| 4754 | + // Following is debug stuff |
| 4755 | + QgsDebugMsg ( "Mouse IS over canvas" ); |
| 4756 | + QgsDebugMsg ( "Maptips timer fired:" ); |
| 4757 | + QgsDebugMsg ( mLastMapPosition.stringRep() ); |
| 4758 | + QgsDebugMsg ( "Pixel coordinates of mouse position:" ); |
| 4759 | + QgsDebugMsg ( QString::number ( myPointerPos.x() ) + "," + QString::number ( myPointerPos.y() ) ); |
| 4760 | + // end debug stuff |
| 4761 | + |
| 4762 | + // Make sure there is an active layer before proceeding |
| 4763 | + |
| 4764 | + QgsMapLayer* mypLayer = mMapCanvas->currentLayer(); |
| 4765 | + if ( mypLayer ) |
| 4766 | + { |
| 4767 | + QgsDebugMsg("Current layer for maptip display is: " + mypLayer->source()); |
| 4768 | + // only process vector layers |
| 4769 | + if ( mypLayer->type() == QgsMapLayer::VECTOR ) |
| 4770 | + { |
| 4771 | + |
| 4772 | + |
| 4773 | + // Show the maptip if the maptips button is depressed |
| 4774 | + if(mMapTipsVisible) |
| 4775 | + { |
| 4776 | + mpMaptip->showMapTip ( mypLayer, mLastMapPosition, myPointerPos, mMapCanvas ); |
| 4777 | + } |
| 4778 | + } |
| 4779 | + } |
| 4780 | + else |
| 4781 | + { |
| 4782 | + QgsDebugMsg ( "Maptips require an active layer" ); |
| 4783 | + } |
| 4784 | + } |
| 4785 | +} |
4688 | 4786 | void QgisApp::projectPropertiesProjections() |
4689 | 4787 | { |
4690 | 4788 | // Driver to display the project props dialog and switch to the |
|
0 commit comments