void FlameGraphViewTest::testContextMenu() { int targetWidth = 0; int targetHeight = 0; { QMenu testMenu; testMenu.addActions(QmlProfilerTool::profilerContextMenuActions()); testMenu.addSeparator(); testMenu.show(); QTest::qWaitForWindowExposed(testMenu.window()); targetWidth = testMenu.width() / 2; int prevHeight = testMenu.height(); QAction dummy(QString("target"), this); testMenu.addAction(&dummy); targetHeight = (testMenu.height() + prevHeight) / 2; } QTimer timer; timer.setInterval(50); timer.start(); connect(&timer, &QTimer::timeout, this, [&]() { auto activePopup = qApp->activePopupWidget(); if (!activePopup || !activePopup->windowHandle()->isExposed()) return; QTest::mouseMove(activePopup, QPoint(targetWidth, targetHeight)); QTest::mouseClick(activePopup, Qt::LeftButton, Qt::NoModifier, QPoint(targetWidth, targetHeight)); if (!manager.isRestrictedToRange()) { // click somewhere else to remove the menu and return to outer function QTest::mouseClick(qApp->activePopupWidget(), Qt::LeftButton, Qt::NoModifier, QPoint(500, 500)); } }); QTest::mouseMove(&view, QPoint(250, 250)); QSignalSpy spy(&view, SIGNAL(showFullRange())); QContextMenuEvent event(QContextMenuEvent::Mouse, QPoint(250, 250)); QVERIFY(qApp->notify(&view, &event)); QCOMPARE(spy.count(), 0); manager.restrictToRange(1, 10); QVERIFY(qApp->notify(&view, &event)); if (spy.count() != 1) QTRY_COMPARE(spy.count(), 1); }
void FlameGraphView::contextMenuEvent(QContextMenuEvent *ev) { QMenu menu; QAction *getGlobalStatsAction = 0; QPoint position = ev->globalPos(); menu.addActions(QmlProfiler::QmlProfilerTool::profilerContextMenuActions()); menu.addSeparator(); getGlobalStatsAction = menu.addAction(tr("Show Full Range")); if (!isRestrictedToRange()) getGlobalStatsAction->setEnabled(false); if (menu.exec(position) == getGlobalStatsAction) emit showFullRange(); }
void HistogramDialog::pwCommandHandler ( CSI::Guid /*sessionid*/, CSI::Typeless command, CSI::Typeless /*responses*/) { std::string cmd = command["/cmd"].As<std::string>(); if( cmd == "setMarkers") { double x1 = command["/x1"].As<double>(); double x2 = command["/x2"].As<double>(); x1 = (x1 * m_imageWidth - m_marginLeft) / (m_imageWidth - m_marginLeft - m_marginRight); x2 = (x2 * m_imageWidth - m_marginLeft) / (m_imageWidth - m_marginLeft - m_marginRight); min_ = x1 * (zMax_ - zMin_) + zMin_; if( min_ < zMin_) min_ = zMin_; if( min_ > max_) min_ = max_; max_ = x2 * (zMax_ - zMin_) + zMin_; if( max_ > zMax_) max_ = zMax_; if( min_ > max_) max_ = min_; pwset ("/Histogram/Index", -1); recalculateHistogramDelayed (); // canvasRepaint (); // updateSliderState (); emit valuesChanged ( min_, max_); } else if( cmd == "show") { // show (); pwset("/Histogram/Visible", 1); } else if( cmd == "hide") { // hide (); pwset("/Histogram/Visible", 0); } else if( cmd == "preset") { int ind = command["/index"].As<int>(); bool zoom = command["/zoom"].As<bool>(); activatePreset ( ind, zoom); // updateSliderState (); } else if( cmd == "zoom") { zoomToSelection (); } else if( cmd == "unzoom") { showFullRange (); } else if( cmd == "resize") { m_imageWidth = command["/width"].As<int>(); recalculateHistogramDelayed (); } else if( cmd == "logScale") { m_logScale = command["/val"].As<bool>(); recalculateHistogramDelayed (); } else if( cmd == "smoothGraph") { m_smoothGraph = command["/val"].As<bool>(); recalculateHistogramDelayed (); } else if( cmd == "setCursor") { m_cursorX = command["/x"].As<int>(); recalculateHistogramDelayed (); } else if( cmd == "setVisible") { std::string val = command["/val"].As<std::string>(); m_visibleOnClient = command["/val"].As<bool>(); recalculateHistogramDelayed(); } else { dbg(0) << "Unknown histogram command " << cmd; } }