TorMapWidgetPopupMenu.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #include "TorMapWidgetPopupMenu.h"
00018 #include "Vidalia.h"
00019
00020 #include <MarbleModel.h>
00021 #include <MarblePlacemarkModel.h>
00022
00023 #include <QChar>
00024 #include <QVector>
00025 #include <QModelIndex>
00026
00027 using namespace Marble;
00028
00029
00030 TorMapWidgetPopupMenu::TorMapWidgetPopupMenu(TorMapWidget *widget)
00031 : QObject(widget),
00032 _widget(widget)
00033 {
00034 _leftClickMenu = new QMenu(widget);
00035 connect(_leftClickMenu, SIGNAL(triggered(QAction*)),
00036 this, SLOT(relaySelected(QAction*)));
00037 }
00038
00039 void
00040 TorMapWidgetPopupMenu::featureClicked(const QPoint &pos, Qt::MouseButton btn)
00041 {
00042 switch (btn) {
00043 case Qt::LeftButton:
00044 featureLeftClicked(pos);
00045 break;
00046
00047 case Qt::RightButton:
00048 break;
00049
00050 default:
00051 break;
00052 }
00053 }
00054
00055 void
00056 TorMapWidgetPopupMenu::featureLeftClicked(const QPoint &pos)
00057 {
00058 QVector<QModelIndex>::const_iterator it;
00059 QVector<QModelIndex> features = _widget->model()->whichFeatureAt(pos);
00060 QString name, id;
00061 int numRelays = 0;
00062
00063 _leftClickMenu->clear();
00064 for (it = features.constBegin(); it != features.constEnd(); ++it) {
00065 QChar role = (*it).data(MarblePlacemarkModel::GeoTypeRole).toChar();
00066 if (role == '1') {
00067
00068 name = (*it).data().toString();
00069 id = (*it).data(MarblePlacemarkModel::DescriptionRole).toString();
00070
00071 QAction *action = _leftClickMenu->addAction(name);
00072 action->setData(id);
00073 numRelays++;
00074 }
00075 }
00076
00077 if (numRelays == 1)
00078 emit displayRouterInfo(id);
00079 else if (numRelays > 1)
00080 _leftClickMenu->popup(_widget->mapToGlobal(pos));
00081 }
00082
00083 void
00084 TorMapWidgetPopupMenu::relaySelected(QAction *action)
00085 {
00086 QString id = action->data().toString();
00087 if (! id.isEmpty())
00088 emit displayRouterInfo(id);
00089 }
00090