void tst_QColumnView::clicked() { ColumnView view; QDirModel model; view.setModel(&model); view.resize(800,300); view.show(); QModelIndex home = model.index(QDir::homePath()); QVERIFY(home.isValid()); view.setCurrentIndex(home); QTest::qWait(ANIMATION_DELAY); QModelIndex parent = home.parent(); QVERIFY(parent.isValid()); qRegisterMetaType<QModelIndex>("QModelIndex"); QSignalSpy clickedSpy(&view, SIGNAL(clicked(const QModelIndex &))); QPoint localPoint = view.visualRect(home).center(); QTest::mouseClick(view.viewport(), Qt::LeftButton, 0, localPoint); QCOMPARE(clickedSpy.count(), 1); qApp->processEvents(); if (sizeof(qreal) != sizeof(double)) { QSKIP("Skipped due to rounding errors", SkipAll); } for (int i = 0; i < view.createdColumns.count(); ++i) { QAbstractItemView *column = view.createdColumns.at(i); if (column && column->selectionModel() && (column->rootIndex() == home)) QVERIFY(column->selectionModel()->selectedIndexes().isEmpty()); } }
QList<std::shared_ptr<const UICommon::GameFile>> GameList::GetSelectedGames() const { QAbstractItemView* view; QSortFilterProxyModel* proxy; if (currentWidget() == m_list) { view = m_list; proxy = m_list_proxy; } else { view = m_grid; proxy = m_grid_proxy; } QList<std::shared_ptr<const UICommon::GameFile>> selected_list; QItemSelectionModel* sel_model = view->selectionModel(); if (sel_model->hasSelection()) { QModelIndexList index_list = currentWidget() == m_list ? sel_model->selectedRows() : sel_model->selectedIndexes(); for (const auto& index : index_list) { QModelIndex model_index = proxy->mapToSource(index); selected_list.push_back(m_model->GetGameFile(model_index.row())); } } return selected_list; }
/** A method that simplifies checking a view's current item and selection */ static void verifyCurrentItemAndSelection(const QAbstractItemView& view, const QModelIndex& expectedCurrent, const QModelIndexList& expectedSelection) { QCOMPARE(view.currentIndex(), expectedCurrent); const QModelIndexList selectedIndexes = view.selectionModel()->selectedIndexes(); QCOMPARE(selectedIndexes.count(), expectedSelection.count()); foreach(const QModelIndex& index, expectedSelection) { QVERIFY(selectedIndexes.contains(index)); }
void TransactionView::openTransactionInLedger() { QAbstractItemView *view = transactionView; if (!view->selectionModel()) return; QModelIndexList selection = view->selectionModel()->selectedRows(0); if (!selection.isEmpty()) { QString url; if (fTestNet) { url = "http://testnet.MonedaDelEmprendimiento.com/transaction/"; } else { url = "http://ledger.MonedaDelEmprendimiento.com/transaction/"; } url.append(selection.at(0).data(TransactionTableModel::TxIDRole).toString()); QDesktopServices::openUrl(QUrl(url)); } }
void BookmarksWidget::rename() { QWidget *w = focusWidget(); QAbstractItemView *view = qobject_cast<QAbstractItemView*>(w); if (view) { QModelIndexList indexes = view->selectionModel()->selectedIndexes(); if (indexes.isEmpty()) return; QModelIndex index = indexes.first(); view->edit(index); } }
void OutputWidget::copySelection() { QWidget* widget = currentWidget(); if( !widget ) return; QAbstractItemView *view = dynamic_cast<QAbstractItemView*>(widget); if( !view ) return; QClipboard *cb = QApplication::clipboard(); QModelIndexList indexes = view->selectionModel()->selectedRows(); QString content; Q_FOREACH( const QModelIndex& index, indexes) { content += index.data().toString() + '\n'; }
QString GameList::GetSelectedGame() const { QAbstractItemView* view; QSortFilterProxyModel* proxy; if (currentWidget() == m_table) { view = m_table; proxy = m_table_proxy; } else { view = m_list; proxy = m_list_proxy; } QItemSelectionModel* sel_model = view->selectionModel(); if (sel_model->hasSelection()) { QModelIndex model_index = proxy->mapToSource(sel_model->selectedIndexes()[0]); return m_model->GetPath(model_index.row()); } return QStringLiteral(); }
std::shared_ptr<const UICommon::GameFile> GameList::GetSelectedGame() const { QAbstractItemView* view; QSortFilterProxyModel* proxy; if (currentWidget() == m_list) { view = m_list; proxy = m_list_proxy; } else { view = m_grid; proxy = m_grid_proxy; } QItemSelectionModel* sel_model = view->selectionModel(); if (sel_model->hasSelection()) { QModelIndex model_index = proxy->mapToSource(sel_model->selectedIndexes()[0]); return m_model->GetGameFile(model_index.row()); } return {}; }
PointViewerMainWindow::PointViewerMainWindow(const QGLFormat& format) : m_progressBar(0), m_pointView(0), m_shaderEditor(0), m_helpDialog(0), m_logTextView(0), m_maxPointCount(200*1000*1000), // 200 million m_geometries(0), m_ipcServer(0), m_hookManager(0) { #ifndef _WIN32 setWindowIcon(QIcon(":resource/icons/hicolor/256x256/apps/displaz.png")); #else // On windows, application icon is set via windows resource file #endif setWindowTitle("Displaz"); setAcceptDrops(true); m_helpDialog = new HelpDialog(this); m_geometries = new GeometryCollection(this); connect(m_geometries, SIGNAL(layoutChanged()), this, SLOT(updateTitle())); connect(m_geometries, SIGNAL(dataChanged(QModelIndex,QModelIndex)), this, SLOT(updateTitle())); connect(m_geometries, SIGNAL(rowsInserted(QModelIndex,int,int)), this, SLOT(updateTitle())); connect(m_geometries, SIGNAL(rowsRemoved(QModelIndex,int,int)), this, SLOT(updateTitle())); //-------------------------------------------------- // Set up file loader in a separate thread // // Some subtleties regarding qt thread usage are discussed here: // http://mayaposch.wordpress.com/2011/11/01/how-to-really-truly-use-qthreads-the-full-explanation // // Main point: each QObject has a thread affinity which determines which // thread its slots will execute on, when called via a connected signal. QThread* loaderThread = new QThread(); m_fileLoader = new FileLoader(m_maxPointCount); m_fileLoader->moveToThread(loaderThread); connect(loaderThread, SIGNAL(finished()), m_fileLoader, SLOT(deleteLater())); connect(loaderThread, SIGNAL(finished()), loaderThread, SLOT(deleteLater())); //connect(m_fileLoader, SIGNAL(finished()), this, SIGNAL(fileLoadFinished())); connect(m_fileLoader, SIGNAL(geometryLoaded(std::shared_ptr<Geometry>, bool, bool)), m_geometries, SLOT(addGeometry(std::shared_ptr<Geometry>, bool, bool))); connect(m_fileLoader, SIGNAL(geometryMutatorLoaded(std::shared_ptr<GeometryMutator>)), m_geometries, SLOT(mutateGeometry(std::shared_ptr<GeometryMutator>))); loaderThread->start(); //-------------------------------------------------- // Menus menuBar()->setNativeMenuBar(false); // OS X doesn't activate the native menu bar under Qt5 // File menu QMenu* fileMenu = menuBar()->addMenu(tr("&File")); QAction* openAct = fileMenu->addAction(tr("&Open")); openAct->setToolTip(tr("Open a data set")); openAct->setShortcuts(QKeySequence::Open); connect(openAct, SIGNAL(triggered()), this, SLOT(openFiles())); QAction* addAct = fileMenu->addAction(tr("&Add")); addAct->setToolTip(tr("Add a data set")); connect(addAct, SIGNAL(triggered()), this, SLOT(addFiles())); QAction* reloadAct = fileMenu->addAction(tr("&Reload")); reloadAct->setStatusTip(tr("Reload point files from disk")); reloadAct->setShortcut(Qt::Key_F5); connect(reloadAct, SIGNAL(triggered()), this, SLOT(reloadFiles())); fileMenu->addSeparator(); QAction* screenShotAct = fileMenu->addAction(tr("Scree&nshot")); screenShotAct->setStatusTip(tr("Save screen shot of 3D window")); screenShotAct->setShortcut(Qt::Key_F9); connect(screenShotAct, SIGNAL(triggered()), this, SLOT(screenShot())); fileMenu->addSeparator(); QAction* quitAct = fileMenu->addAction(tr("&Quit")); quitAct->setStatusTip(tr("Exit the application")); quitAct->setShortcuts(QKeySequence::Quit); connect(quitAct, SIGNAL(triggered()), this, SLOT(close())); // View menu QMenu* viewMenu = menuBar()->addMenu(tr("&View")); QAction* trackballMode = viewMenu->addAction(tr("Use &Trackball camera")); trackballMode->setCheckable(true); trackballMode->setChecked(false); // Background sub-menu QMenu* backMenu = viewMenu->addMenu(tr("Set &Background")); QSignalMapper* mapper = new QSignalMapper(this); // Selectable backgrounds (svg_names from SVG standard - see QColor docs) const char* backgroundNames[] = {/* "Display Name", "svg_name", */ "Default", "#3C3232", "Black", "black", "Dark Grey", "dimgrey", "Slate Grey", "#858C93", "Light Grey", "lightgrey", "White", "white" }; for(size_t i = 0; i < sizeof(backgroundNames)/sizeof(const char*); i+=2) { QAction* backgroundAct = backMenu->addAction(tr(backgroundNames[i])); QPixmap pixmap(50,50); QString colName = backgroundNames[i+1]; pixmap.fill(QColor(colName)); QIcon icon(pixmap); backgroundAct->setIcon(icon); mapper->setMapping(backgroundAct, colName); connect(backgroundAct, SIGNAL(triggered()), mapper, SLOT(map())); } connect(mapper, SIGNAL(mapped(QString)), this, SLOT(setBackground(QString))); backMenu->addSeparator(); QAction* backgroundCustom = backMenu->addAction(tr("&Custom")); connect(backgroundCustom, SIGNAL(triggered()), this, SLOT(chooseBackground())); // Check boxes for drawing various scene elements by category viewMenu->addSeparator(); QAction* drawBoundingBoxes = viewMenu->addAction(tr("Draw Bounding bo&xes")); drawBoundingBoxes->setCheckable(true); drawBoundingBoxes->setChecked(false); QAction* drawCursor = viewMenu->addAction(tr("Draw 3D &Cursor")); drawCursor->setCheckable(true); drawCursor->setChecked(true); QAction* drawAxes = viewMenu->addAction(tr("Draw &Axes")); drawAxes->setCheckable(true); drawAxes->setChecked(true); QAction* drawGrid = viewMenu->addAction(tr("Draw &Grid")); drawGrid->setCheckable(true); drawGrid->setChecked(false); QAction* drawAnnotations = viewMenu->addAction(tr("Draw A&nnotations")); drawAnnotations->setCheckable(true); drawAnnotations->setChecked(true); // Shader menu QMenu* shaderMenu = menuBar()->addMenu(tr("&Shader")); QAction* openShaderAct = shaderMenu->addAction(tr("&Open")); openShaderAct->setToolTip(tr("Open a shader file")); connect(openShaderAct, SIGNAL(triggered()), this, SLOT(openShaderFile())); QAction* editShaderAct = shaderMenu->addAction(tr("&Edit")); editShaderAct->setToolTip(tr("Open shader editor window")); QAction* saveShaderAct = shaderMenu->addAction(tr("&Save")); saveShaderAct->setToolTip(tr("Save current shader file")); connect(saveShaderAct, SIGNAL(triggered()), this, SLOT(saveShaderFile())); shaderMenu->addSeparator(); // Help menu QMenu* helpMenu = menuBar()->addMenu(tr("&Help")); QAction* helpAct = helpMenu->addAction(tr("User &Guide")); connect(helpAct, SIGNAL(triggered()), this, SLOT(helpDialog())); helpMenu->addSeparator(); QAction* aboutAct = helpMenu->addAction(tr("&About")); connect(aboutAct, SIGNAL(triggered()), this, SLOT(aboutDialog())); //-------------------------------------------------- // Point viewer m_pointView = new View3D(m_geometries, format, this); setCentralWidget(m_pointView); connect(drawBoundingBoxes, SIGNAL(triggered()), m_pointView, SLOT(toggleDrawBoundingBoxes())); connect(drawCursor, SIGNAL(triggered()), m_pointView, SLOT(toggleDrawCursor())); connect(drawAxes, SIGNAL(triggered()), m_pointView, SLOT(toggleDrawAxes())); connect(drawGrid, SIGNAL(triggered()), m_pointView, SLOT(toggleDrawGrid())); connect(drawAnnotations, SIGNAL(triggered()), m_pointView, SLOT(toggleDrawAnnotations())); connect(trackballMode, SIGNAL(triggered()), m_pointView, SLOT(toggleCameraMode())); connect(m_geometries, SIGNAL(rowsInserted(QModelIndex,int,int)), this, SLOT(geometryRowsInserted(QModelIndex,int,int))); //-------------------------------------------------- // Docked widgets // Shader parameters UI QDockWidget* shaderParamsDock = new QDockWidget(tr("Shader Parameters"), this); shaderParamsDock->setFeatures(QDockWidget::DockWidgetMovable | QDockWidget::DockWidgetClosable); QWidget* shaderParamsUI = new QWidget(shaderParamsDock); shaderParamsDock->setWidget(shaderParamsUI); m_pointView->setShaderParamsUIWidget(shaderParamsUI); // Shader editor UI QDockWidget* shaderEditorDock = new QDockWidget(tr("Shader Editor"), this); shaderEditorDock->setFeatures(QDockWidget::DockWidgetMovable | QDockWidget::DockWidgetClosable | QDockWidget::DockWidgetFloatable); QWidget* shaderEditorUI = new QWidget(shaderEditorDock); m_shaderEditor = new ShaderEditor(shaderEditorUI); QGridLayout* shaderEditorLayout = new QGridLayout(shaderEditorUI); shaderEditorLayout->setContentsMargins(2,2,2,2); shaderEditorLayout->addWidget(m_shaderEditor, 0, 0, 1, 1); connect(editShaderAct, SIGNAL(triggered()), shaderEditorDock, SLOT(show())); shaderEditorDock->setWidget(shaderEditorUI); shaderMenu->addAction(m_shaderEditor->compileAction()); connect(m_shaderEditor->compileAction(), SIGNAL(triggered()), this, SLOT(compileShaderFile())); // TODO: check if this is needed - test shader update functionality //connect(m_shaderEditor, SIGNAL(sendShader(QString)), // &m_pointView->shaderProgram(), SLOT(setShader(QString))); // Log viewer UI QDockWidget* logDock = new QDockWidget(tr("Log"), this); logDock->setFeatures(QDockWidget::DockWidgetMovable | QDockWidget::DockWidgetClosable); QWidget* logUI = new QWidget(logDock); m_logTextView = new LogViewer(logUI); m_logTextView->setReadOnly(true); m_logTextView->setTextInteractionFlags(Qt::TextSelectableByKeyboard | Qt::TextSelectableByMouse); m_logTextView->connectLogger(&g_logger); // connect to global logger m_progressBar = new QProgressBar(logUI); m_progressBar->setRange(0,100); m_progressBar->setValue(0); m_progressBar->hide(); connect(m_fileLoader, SIGNAL(loadStepStarted(QString)), this, SLOT(setProgressBarText(QString))); connect(m_fileLoader, SIGNAL(loadProgress(int)), m_progressBar, SLOT(setValue(int))); connect(m_fileLoader, SIGNAL(resetProgress()), m_progressBar, SLOT(hide())); QVBoxLayout* logUILayout = new QVBoxLayout(logUI); //logUILayout->setContentsMargins(2,2,2,2); logUILayout->addWidget(m_logTextView); logUILayout->addWidget(m_progressBar); //m_logTextView->setLineWrapMode(QPlainTextEdit::NoWrap); logDock->setWidget(logUI); // Data set list UI QDockWidget* dataSetDock = new QDockWidget(tr("Data Sets"), this); dataSetDock->setFeatures(QDockWidget::DockWidgetMovable | QDockWidget::DockWidgetClosable | QDockWidget::DockWidgetFloatable); DataSetUI* dataSetUI = new DataSetUI(this); dataSetDock->setWidget(dataSetUI); QAbstractItemView* dataSetOverview = dataSetUI->view(); dataSetOverview->setModel(m_geometries); connect(dataSetOverview, SIGNAL(doubleClicked(const QModelIndex&)), m_pointView, SLOT(centerOnGeometry(const QModelIndex&))); m_pointView->setSelectionModel(dataSetOverview->selectionModel()); // Set up docked widgets addDockWidget(Qt::RightDockWidgetArea, shaderParamsDock); addDockWidget(Qt::LeftDockWidgetArea, shaderEditorDock); addDockWidget(Qt::RightDockWidgetArea, logDock); addDockWidget(Qt::RightDockWidgetArea, dataSetDock); tabifyDockWidget(logDock, dataSetDock); logDock->raise(); shaderEditorDock->setVisible(false); // Add dock widget toggles to view menu viewMenu->addSeparator(); viewMenu->addAction(shaderParamsDock->toggleViewAction()); viewMenu->addAction(logDock->toggleViewAction()); viewMenu->addAction(dataSetDock->toggleViewAction()); // Create custom hook events from CLI at runtime m_hookManager = new HookManager(this); }