void ItemPinnedSaver::updateLastPinned(int from, int to) { for (int row = to; row >= from; --row) { const auto index = m_model->index(row, 0); if ( isPinned(index) ) { m_lastPinned = row; break; } } }
void ItemPinnedSaver::onRowsMoved(const QModelIndex &, int start, int end, const QModelIndex &, int destinationRow) { if (!m_model) return; if ( (m_lastPinned >= start || m_lastPinned >= destinationRow) && (end >= m_lastPinned || destinationRow >= m_lastPinned) ) { if (start < destinationRow) updateLastPinned(start, destinationRow + end - start + 1); else updateLastPinned(destinationRow, end); } if (destinationRow != 0 || start < destinationRow) return; const int rowCount = end - start + 1; for (int row = destinationRow; row < destinationRow + rowCount; ++row) { if ( isPinned(m_model->index(row, 0)) ) return; } disconnect( m_model.data(), &QAbstractItemModel::rowsMoved, this, &ItemPinnedSaver::onRowsMoved ); // Shift rows below inserted up. for (int row = destinationRow + rowCount; row <= std::min(m_lastPinned, end); ++row) { const auto index = m_model->index(row, 0); if ( isPinned(index) ) moveRow(row, row - rowCount); } connect( m_model.data(), &QAbstractItemModel::rowsMoved, this, &ItemPinnedSaver::onRowsMoved ); }
void ItemPinnedSaver::onRowsRemoved(const QModelIndex &, int start, int end) { if (!m_model || m_lastPinned < start) return; disconnect( m_model.data(), &QAbstractItemModel::rowsMoved, this, &ItemPinnedSaver::onRowsMoved ); // Shift rows below removed down. const int rowCount = end - start + 1; for (int row = m_lastPinned - rowCount; row >= start; --row) { const auto index = m_model->index(row, 0); if ( isPinned(index) ) moveRow(row, row + rowCount + 1); } connect( m_model.data(), &QAbstractItemModel::rowsMoved, this, &ItemPinnedSaver::onRowsMoved ); }
void ItemPinnedSaver::onRowsInserted(const QModelIndex &, int start, int end) { if (!m_model || m_lastPinned < start) { updateLastPinned(start, end); return; } disconnect( m_model.data(), &QAbstractItemModel::rowsMoved, this, &ItemPinnedSaver::onRowsMoved ); // Shift rows below inserted up. const int rowCount = end - start + 1; for (int row = end + 1; row <= m_lastPinned + rowCount; ++row) { const auto index = m_model->index(row, 0); if ( isPinned(index) ) moveRow(row, row - rowCount); } connect( m_model.data(), &QAbstractItemModel::rowsMoved, this, &ItemPinnedSaver::onRowsMoved ); }
Application *LauncherModel::addApplication(const QString &appId, bool pinned) { auto app = new Application(appId, pinned, this); if (pinned && !app->isValid()) { pinLauncher(appId, false); return nullptr; } QObject::connect(app, &Application::launched, [=]() { QModelIndex modelIndex = index(indexFromAppId(appId)); emit dataChanged(modelIndex, modelIndex); QTimer::singleShot(5000, [=]() { if (app->isStarting()) { qDebug() << "Application failed to start!" << appId; auto i = indexFromAppId(appId); if (app->isPinned()) { QModelIndex modelIndex = index(i); app->setState(Application::NotRunning); emit dataChanged(modelIndex, modelIndex); } else { beginRemoveRows(QModelIndex(), i, i); m_list.takeAt(i)->deleteLater(); endRemoveRows(); } } else { qDebug() << "Application is now running" << appId; } }); }); m_list.append(app); return app; }
void Window::triggerAction(int identifier, const QVariantMap ¶meters) { switch (identifier) { case ActionsManager::CloneTabAction: if (canClone()) { m_mainWindow->addWindow(clone(true, m_mainWindow)); } break; case ActionsManager::PinTabAction: setPinned(!isPinned()); break; case ActionsManager::DetachTabAction: if (m_mainWindow->getWindowCount() > 1) { m_mainWindow->moveWindow(this); } break; case ActionsManager::SuspendTabAction: if (!m_contentsWidget || m_contentsWidget->close()) { m_session = getSession(); setContentsWidget(nullptr); } break; case ActionsManager::CloseTabAction: if (!isPinned()) { requestClose(); } break; case ActionsManager::GoAction: case ActionsManager::ActivateAddressFieldAction: case ActionsManager::ActivateSearchFieldAction: { AddressWidget *addressWidget(findAddressWidget()); SearchWidget *searchWidget(nullptr); for (int i = 0; i < m_searchWidgets.count(); ++i) { if (m_searchWidgets.at(i) && m_searchWidgets.at(i)->isVisible()) { searchWidget = m_searchWidgets.at(i); break; } } if (identifier == ActionsManager::ActivateSearchFieldAction && searchWidget) { searchWidget->activate(Qt::ShortcutFocusReason); } else if (addressWidget) { if (identifier == ActionsManager::ActivateAddressFieldAction) { addressWidget->activate(Qt::ShortcutFocusReason); } else if (identifier == ActionsManager::ActivateSearchFieldAction) { addressWidget->setText(QLatin1String("? ")); addressWidget->activate(Qt::OtherFocusReason); } else if (identifier == ActionsManager::GoAction) { addressWidget->handleUserInput(addressWidget->text(), SessionsManager::CurrentTabOpen); return; } } else if (identifier == ActionsManager::ActivateAddressFieldAction || identifier == ActionsManager::ActivateSearchFieldAction) { OpenAddressDialog dialog(this); if (identifier == ActionsManager::ActivateSearchFieldAction) { dialog.setText(QLatin1String("? ")); } connect(&dialog, SIGNAL(requestedLoadUrl(QUrl,SessionsManager::OpenHints)), this, SLOT(handleOpenUrlRequest(QUrl,SessionsManager::OpenHints))); connect(&dialog, SIGNAL(requestedOpenBookmark(BookmarksItem*,SessionsManager::OpenHints)), this, SIGNAL(requestedOpenBookmark(BookmarksItem*,SessionsManager::OpenHints))); connect(&dialog, SIGNAL(requestedSearch(QString,QString,SessionsManager::OpenHints)), this, SLOT(handleSearchRequest(QString,QString,SessionsManager::OpenHints))); dialog.exec(); } } break; case ActionsManager::PrintAction: { QPrinter printer; printer.setCreator(QStringLiteral("Otter Browser %1").arg(Application::getFullVersion())); QPrintDialog printDialog(&printer, this); printDialog.setWindowTitle(tr("Print Page")); if (printDialog.exec() != QDialog::Accepted) { break; } getContentsWidget()->print(&printer); } break; case ActionsManager::PrintPreviewAction: { QPrintPreviewDialog printPreviewDialog(this); printPreviewDialog.printer()->setCreator(QStringLiteral("Otter Browser %1").arg(Application::getFullVersion())); printPreviewDialog.setWindowFlags(printPreviewDialog.windowFlags() | Qt::WindowMaximizeButtonHint | Qt::WindowMinimizeButtonHint); printPreviewDialog.setWindowTitle(tr("Print Preview")); if (QApplication::activeWindow()) { printPreviewDialog.resize(QApplication::activeWindow()->size()); } connect(&printPreviewDialog, SIGNAL(paintRequested(QPrinter*)), getContentsWidget(), SLOT(print(QPrinter*))); printPreviewDialog.exec(); } break; case ActionsManager::BookmarkPageAction: { const QUrl url((parameters.contains(QLatin1String("url")) ? parameters[QLatin1String("url")].toUrl() : getUrl()).adjusted(QUrl::RemovePassword)); if (url.isEmpty()) { break; } const QVector<BookmarksItem*> bookmarks(BookmarksManager::getModel()->getBookmarks(url)); if (bookmarks.isEmpty()) { BookmarkPropertiesDialog dialog(url, (parameters.contains(QLatin1String("title")) ? parameters[QLatin1String("title")].toString() : getTitle()), parameters[QLatin1String("description")].toString(), nullptr, -1, true, this); dialog.exec(); } else { BookmarkPropertiesDialog dialog(bookmarks.at(0), this); dialog.exec(); } } break; case ActionsManager::FullScreenAction: if (m_addressBar) { m_addressBar->setVisible(m_addressBar->shouldBeVisible(m_mainWindow->isFullScreen())); } if (m_contentsWidget) { m_contentsWidget->triggerAction(identifier, parameters); } break; default: getContentsWidget()->triggerAction(identifier, parameters); break; }
inline void unpin() { assert(isPinned()); gain += pinNodeConstant(); assert(!isPinned()); }
void QgsMapToolPinLabels::pinUnpinLabels( const QgsRectangle &ext, QMouseEvent *e ) { bool doUnpin = e->modifiers() & Qt::ShiftModifier; bool toggleUnpinOrPin = e->modifiers() & Qt::ControlModifier; // get list of all drawn labels from all layers within, or touching, chosen extent const QgsLabelingResults *labelingResults = mCanvas->labelingResults(); if ( !labelingResults ) { QgsDebugMsg( QStringLiteral( "No labeling engine" ) ); return; } QList<QgsLabelPosition> labelPosList = labelingResults->labelsWithinRect( ext ); bool labelChanged = false; QList<QgsLabelPosition>::const_iterator it; for ( it = labelPosList.constBegin() ; it != labelPosList.constEnd(); ++it ) { const QgsLabelPosition &pos = *it; mCurrentLabel = LabelDetails( pos ); if ( !mCurrentLabel.valid ) { QgsDebugMsg( QStringLiteral( "Failed to get label details" ) ); continue; } // unpin label if ( isPinned() && ( doUnpin || toggleUnpinOrPin ) ) { // unpin previously pinned label (set attribute table fields to NULL) if ( pinUnpinCurrentFeature( false ) ) { labelChanged = true; } else { QgsDebugMsg( QStringLiteral( "Unpin failed for layer" ) ); } } // pin label else if ( !isPinned() && ( !doUnpin || toggleUnpinOrPin ) ) { // pin label's location, and optionally rotation, to attribute table if ( pinUnpinCurrentFeature( true ) ) { labelChanged = true; } else { QgsDebugMsg( QStringLiteral( "Pin failed for layer" ) ); } } } if ( labelChanged ) { mCurrentLabel.layer->triggerRepaint(); if ( !mShowPinned ) { // toggle it on (pin-unpin tool doesn't work well without it) QgisApp::instance()->actionShowPinnedLabels()->setChecked( true ); } } }
// public slot to render highlight rectangles around pinned labels void QgsMapToolPinLabels::highlightPinnedLabels() { removePinnedHighlights(); if ( !mShowPinned ) { return; } QgsDebugMsg( QStringLiteral( "Highlighting pinned labels" ) ); // get list of all drawn labels from all layers within given extent const QgsLabelingResults *labelingResults = mCanvas->labelingResults(); if ( !labelingResults ) { QgsDebugMsg( QStringLiteral( "No labeling engine" ) ); return; } QgsRectangle ext = mCanvas->extent(); QgsDebugMsg( QStringLiteral( "Getting labels from canvas extent" ) ); QList<QgsLabelPosition> labelPosList = labelingResults->labelsWithinRect( ext ); QApplication::setOverrideCursor( Qt::WaitCursor ); QList<QgsLabelPosition>::const_iterator it; for ( it = labelPosList.constBegin() ; it != labelPosList.constEnd(); ++it ) { const QgsLabelPosition &pos = *it; mCurrentLabel = LabelDetails( pos ); if ( isPinned() ) { QString labelStringID = QStringLiteral( "%0|%1|%2" ).arg( QString::number( pos.isDiagram ), pos.layerID, QString::number( pos.featureId ) ); // don't highlight again if ( mHighlights.contains( labelStringID ) ) { continue; } QColor lblcolor = QColor( 54, 129, 255, 63 ); QgsMapLayer *layer = QgsProject::instance()->mapLayer( pos.layerID ); if ( !layer ) { continue; } QgsVectorLayer *vlayer = dynamic_cast<QgsVectorLayer *>( layer ); if ( !vlayer ) { QgsDebugMsg( QStringLiteral( "Failed to cast to vector layer" ) ); continue; } if ( vlayer->isEditable() ) { lblcolor = QColor( 54, 129, 0, 63 ); } highlightLabel( pos, labelStringID, lblcolor ); } } QApplication::restoreOverrideCursor(); }