void QgsPalettedRendererWidget::changeColor() { QItemSelection sel = mTreeView->selectionModel()->selection(); QModelIndex colorIndex = mModel->index( sel.first().top(), QgsPalettedRendererModel::ColorColumn ); QColor currentColor = mModel->data( colorIndex, Qt::DisplayRole ).value<QColor>(); QgsPanelWidget *panel = QgsPanelWidget::findParentPanel( qobject_cast< QWidget * >( parent() ) ); if ( panel && panel->dockMode() ) { QgsCompoundColorWidget *colorWidget = new QgsCompoundColorWidget( panel, currentColor, QgsCompoundColorWidget::LayoutVertical ); colorWidget->setPanelTitle( tr( "Select Color" ) ); colorWidget->setAllowOpacity( true ); connect( colorWidget, &QgsCompoundColorWidget::currentColorChanged, this, [ = ]( const QColor & color ) { setSelectionColor( sel, color ); } ); panel->openPanel( colorWidget ); } else { // modal dialog version... yuck QColor newColor = QgsColorDialog::getColor( currentColor, this, QStringLiteral( "Change color" ), true ); if ( newColor.isValid() ) { setSelectionColor( sel, newColor ); } } }
void QgsColorButton::showColorDialog() { QgsPanelWidget *panel = QgsPanelWidget::findParentPanel( this ); if ( panel && panel->dockMode() ) { QColor currentColor = color(); QgsCompoundColorWidget *colorWidget = new QgsCompoundColorWidget( panel, currentColor, QgsCompoundColorWidget::LayoutVertical ); colorWidget->setPanelTitle( mColorDialogTitle ); colorWidget->setAllowOpacity( mAllowOpacity ); if ( currentColor.isValid() ) { colorWidget->setPreviousColor( currentColor ); } connect( colorWidget, &QgsCompoundColorWidget::currentColorChanged, this, &QgsColorButton::setValidTemporaryColor ); panel->openPanel( colorWidget ); return; } QColor newColor; QgsSettings settings; if ( mAcceptLiveUpdates && settings.value( QStringLiteral( "qgis/live_color_dialogs" ), false ).toBool() ) { // live updating dialog - QgsColorDialog will automatically use native dialog if option is set newColor = QgsColorDialog::getLiveColor( color(), this, SLOT( setValidColor( const QColor & ) ), this, mColorDialogTitle, mAllowOpacity ); }
void QgsPropertyOverrideButton::showAssistant() { //first step - try to convert any existing expression to a transformer if one doesn't //already exist if ( !mProperty.transformer() ) { ( void )mProperty.convertToTransformer(); } QgsPanelWidget *panel = QgsPanelWidget::findParentPanel( this ); QgsPropertyAssistantWidget *widget = new QgsPropertyAssistantWidget( panel, mDefinition, mProperty, mVectorLayer ); widget->registerExpressionContextGenerator( mExpressionContextGenerator ); widget->setSymbol( mSymbol ); // we only show legend preview in dialog version if ( panel && panel->dockMode() ) { connect( widget, &QgsPropertyAssistantWidget::widgetChanged, this, [this, widget] { widget->updateProperty( this->mProperty ); mExpressionString = this->mProperty.asExpression(); mFieldName = this->mProperty.field(); updateSiblingWidgets( isActive() ); this->emit changed(); } ); connect( widget, &QgsPropertyAssistantWidget::panelAccepted, this, [ = ] { updateGui(); } ); panel->openPanel( widget ); return; } else { // Show the dialog version if not in a panel QDialog *dlg = new QDialog( this ); QString key = QStringLiteral( "/UI/paneldialog/%1" ).arg( widget->panelTitle() ); QgsSettings settings; dlg->restoreGeometry( settings.value( key ).toByteArray() ); dlg->setWindowTitle( widget->panelTitle() ); dlg->setLayout( new QVBoxLayout() ); dlg->layout()->addWidget( widget ); QDialogButtonBox *buttonBox = new QDialogButtonBox( QDialogButtonBox::Cancel | QDialogButtonBox::Help | QDialogButtonBox::Ok ); connect( buttonBox, &QDialogButtonBox::accepted, dlg, &QDialog::accept ); connect( buttonBox, &QDialogButtonBox::rejected, dlg, &QDialog::reject ); connect( buttonBox, &QDialogButtonBox::helpRequested, this, &QgsPropertyOverrideButton::showHelp ); dlg->layout()->addWidget( buttonBox ); if ( dlg->exec() == QDialog::Accepted ) { widget->updateProperty( mProperty ); mExpressionString = mProperty.asExpression(); mFieldName = mProperty.field(); widget->acceptPanel(); updateSiblingWidgets( isActive() ); updateGui(); emit changed(); } settings.setValue( key, dlg->saveGeometry() ); } }
void QgsGraduatedSymbolRendererWidget::changeGraduatedSymbol() { QgsPanelWidget *panel = QgsPanelWidget::findParentPanel( this ); std::unique_ptr< QgsSymbol > newSymbol( mGraduatedSymbol->clone() ); if ( panel && panel->dockMode() ) { QgsSymbolSelectorWidget *dlg = new QgsSymbolSelectorWidget( newSymbol.release(), mStyle, mLayer, panel ); dlg->setContext( mContext ); connect( dlg, &QgsPanelWidget::widgetChanged, this, &QgsGraduatedSymbolRendererWidget::updateSymbolsFromWidget ); connect( dlg, &QgsPanelWidget::panelAccepted, this, &QgsGraduatedSymbolRendererWidget::cleanUpSymbolSelector ); connect( dlg, &QgsPanelWidget::panelAccepted, this, &QgsGraduatedSymbolRendererWidget::updateGraduatedSymbolIcon ); panel->openPanel( dlg ); } else { QgsSymbolSelectorDialog dlg( newSymbol.get(), mStyle, mLayer, panel ); if ( !dlg.exec() || !newSymbol ) { return; } mGraduatedSymbol = std::move( newSymbol ); updateGraduatedSymbolIcon(); applyChangeToSymbol(); } }
void QgsColorButton::showColorDialog() { QgsPanelWidget *panel = QgsPanelWidget::findParentPanel( this ); if ( panel && panel->dockMode() ) { QColor currentColor = color(); QgsCompoundColorWidget *colorWidget = new QgsCompoundColorWidget( panel, currentColor, QgsCompoundColorWidget::LayoutVertical ); colorWidget->setPanelTitle( mColorDialogTitle ); colorWidget->setAllowOpacity( mAllowOpacity ); if ( currentColor.isValid() ) { colorWidget->setPreviousColor( currentColor ); } connect( colorWidget, &QgsCompoundColorWidget::currentColorChanged, this, &QgsColorButton::setValidTemporaryColor ); panel->openPanel( colorWidget ); return; } QColor newColor; QgsSettings settings; // first check if we need to use the limited native dialogs bool useNative = settings.value( QStringLiteral( "qgis/native_color_dialogs" ), false ).toBool(); if ( useNative ) { // why would anyone want this? who knows.... maybe the limited nature of native dialogs helps ease the transition for MapInfo users? newColor = QColorDialog::getColor( color(), this, mColorDialogTitle, mAllowOpacity ? QColorDialog::ShowAlphaChannel : ( QColorDialog::ColorDialogOption )0 ); } else { QgsColorDialog dialog( this, nullptr, color() ); dialog.setTitle( mColorDialogTitle ); dialog.setAllowOpacity( mAllowOpacity ); if ( dialog.exec() ) { newColor = dialog.color(); } } if ( newColor.isValid() ) { setValidColor( newColor ); } // reactivate button's window activateWindow(); }
void QgsFontButton::showSettingsDialog() { switch ( mMode ) { case ModeTextRenderer: { QgsPanelWidget *panel = QgsPanelWidget::findParentPanel( this ); if ( panel && panel->dockMode() ) { QgsTextFormatPanelWidget *formatWidget = new QgsTextFormatPanelWidget( mFormat, mMapCanvas, this ); formatWidget->setPanelTitle( mDialogTitle ); connect( formatWidget, &QgsTextFormatPanelWidget::widgetChanged, this, [ this, formatWidget ] { this->setTextFormat( formatWidget->format() ); } ); panel->openPanel( formatWidget ); return; } QgsTextFormatDialog dialog( mFormat, mMapCanvas, this ); dialog.setWindowTitle( mDialogTitle ); if ( dialog.exec() ) { setTextFormat( dialog.format() ); QgsFontUtils::addRecentFontFamily( mFormat.font().family() ); } break; } case ModeQFont: { bool ok; QFont newFont = QgsGuiUtils::getFont( ok, mFont, mDialogTitle ); if ( ok ) { QgsFontUtils::addRecentFontFamily( newFont.family() ); setCurrentFont( newFont ); } break; } } // reactivate button's window activateWindow(); }
void QgsColorRampButton::showColorRampDialog() { QgsPanelWidget *panel = QgsPanelWidget::findParentPanel( this ); bool panelMode = panel && panel->dockMode(); std::unique_ptr< QgsColorRamp > currentRamp( colorRamp() ); if ( !currentRamp ) return; setColorRampName( QString() ); if ( currentRamp->type() == QLatin1String( "gradient" ) ) { QgsGradientColorRamp *gradRamp = static_cast<QgsGradientColorRamp *>( currentRamp.get() ); QgsGradientColorRampDialog dlg( *gradRamp, this ); dlg.setWindowTitle( mColorRampDialogTitle ); if ( dlg.exec() ) { setColorRamp( dlg.ramp().clone() ); } } else if ( currentRamp->type() == QLatin1String( "random" ) ) { QgsLimitedRandomColorRamp *randRamp = static_cast<QgsLimitedRandomColorRamp *>( currentRamp.get() ); if ( panelMode ) { QgsLimitedRandomColorRampWidget *widget = new QgsLimitedRandomColorRampWidget( *randRamp, this ); widget->setPanelTitle( tr( "Edit ramp" ) ); connect( widget, &QgsLimitedRandomColorRampWidget::changed, this, &QgsColorRampButton::rampWidgetUpdated ); panel->openPanel( widget ); } else { QgsLimitedRandomColorRampDialog dlg( *randRamp, this ); if ( dlg.exec() ) { setColorRamp( dlg.ramp().clone() ); } } } else if ( currentRamp->type() == QLatin1String( "preset" ) ) { QgsPresetSchemeColorRamp *presetRamp = static_cast<QgsPresetSchemeColorRamp *>( currentRamp.get() ); if ( panelMode ) { QgsPresetColorRampWidget *widget = new QgsPresetColorRampWidget( *presetRamp, this ); widget->setPanelTitle( tr( "Edit ramp" ) ); connect( widget, &QgsPresetColorRampWidget::changed, this, &QgsColorRampButton::rampWidgetUpdated ); panel->openPanel( widget ); } else { QgsPresetColorRampDialog dlg( *presetRamp, this ); if ( dlg.exec() ) { setColorRamp( dlg.ramp().clone() ); } } } else if ( currentRamp->type() == QLatin1String( "colorbrewer" ) ) { QgsColorBrewerColorRamp *brewerRamp = static_cast<QgsColorBrewerColorRamp *>( currentRamp.get() ); if ( panelMode ) { QgsColorBrewerColorRampWidget *widget = new QgsColorBrewerColorRampWidget( *brewerRamp, this ); widget->setPanelTitle( tr( "Edit ramp" ) ); connect( widget, &QgsColorBrewerColorRampWidget::changed, this, &QgsColorRampButton::rampWidgetUpdated ); panel->openPanel( widget ); } else { QgsColorBrewerColorRampDialog dlg( *brewerRamp, this ); if ( dlg.exec() ) { setColorRamp( dlg.ramp().clone() ); } } } else if ( currentRamp->type() == QLatin1String( "cpt-city" ) ) { QgsCptCityColorRamp *cptCityRamp = static_cast<QgsCptCityColorRamp *>( currentRamp.get() ); QgsCptCityColorRampDialog dlg( *cptCityRamp, this ); if ( dlg.exec() ) { if ( dlg.saveAsGradientRamp() ) { setColorRamp( dlg.ramp().cloneGradientRamp() ); } else { setColorRamp( dlg.ramp().clone() ); } } } }