コード例 #1
0
void QgsRuleBasedRendererWidget::editRule( const QModelIndex &index )
{
  if ( !index.isValid() )
    return;

  QgsRuleBasedRenderer::Rule *rule = mModel->ruleForIndex( index );
  QgsPanelWidget *panel = QgsPanelWidget::findParentPanel( this );

  if ( panel && panel->dockMode() )
  {
    QgsRendererRulePropsWidget *widget = new QgsRendererRulePropsWidget( rule, mLayer, mStyle, this, mContext );//panel?
    widget->setPanelTitle( tr( "Edit Rule" ) );
    connect( widget, &QgsPanelWidget::panelAccepted, this, &QgsRuleBasedRendererWidget::ruleWidgetPanelAccepted );
    connect( widget, &QgsPanelWidget::widgetChanged, this, &QgsRuleBasedRendererWidget::liveUpdateRuleFromPanel );
    openPanel( widget );
    return;
  }

  QgsRendererRulePropsDialog dlg( rule, mLayer, mStyle, this, mContext );
  if ( dlg.exec() )
  {
    mModel->updateRule( index.parent(), index.row() );
    mModel->clearFeatureCounts();
    emit widgetChanged();
  }
}
コード例 #2
0
ファイル: qgscolorbutton.cpp プロジェクト: ndavid/QGIS
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 );
  }
コード例 #3
0
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 );
    }
  }
}
コード例 #4
0
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() );
  }
}
コード例 #5
0
void QgsGraduatedSymbolRendererWidget::changeRangeSymbol( int rangeIdx )
{
  const QgsRendererRange &range = mRenderer->ranges()[rangeIdx];
  std::unique_ptr< QgsSymbol > newSymbol( range.symbol()->clone() );
  QgsPanelWidget *panel = QgsPanelWidget::findParentPanel( this );
  if ( panel && panel->dockMode() )
  {
    // bit tricky here - the widget doesn't take ownership of the symbol. So we need it to last for the duration of the
    // panel's existence. Accordingly, just kinda give it ownership here, and clean up in cleanUpSymbolSelector
    QgsSymbolSelectorWidget *dlg = new QgsSymbolSelectorWidget( newSymbol.release(), mStyle, mLayer, panel );
    dlg->setContext( mContext );
    dlg->setPanelTitle( range.label() );
    connect( dlg, &QgsPanelWidget::widgetChanged, this, &QgsGraduatedSymbolRendererWidget::updateSymbolsFromWidget );
    connect( dlg, &QgsPanelWidget::panelAccepted, this, &QgsGraduatedSymbolRendererWidget::cleanUpSymbolSelector );
    openPanel( dlg );
  }
  else
  {
    QgsSymbolSelectorDialog dlg( newSymbol.get(), mStyle, mLayer, panel );
    dlg.setContext( mContext );
    if ( !dlg.exec() || !newSymbol )
    {
      return;
    }

    mGraduatedSymbol = std::move( newSymbol );
    applyChangeToSymbol();
  }
}
コード例 #6
0
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();
  }
}
コード例 #7
0
ファイル: qgspanelwidgetstack.cpp プロジェクト: mterente/QGIS
void QgsPanelWidgetStack::acceptCurrentPanel()
{
  // You can't accept the main panel.
  if ( mStackedWidget->currentIndex() <= 0 )
    return;

  QgsPanelWidget* widget = currentPanel();
  widget->acceptPanel();
}
コード例 #8
0
ファイル: qgscolorbutton.cpp プロジェクト: dmarteau/QGIS
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();
}
コード例 #9
0
ファイル: qgsfontbutton.cpp プロジェクト: cz172638/QGIS
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();
}
コード例 #10
0
void QgsSymbolsListWidget::openStyleManager()
{
  // prefer to use global window manager to open the style manager, if possible!
  // this allows reuse of an existing non-modal window instead of opening a new modal window.
  // Note that we only use the non-modal dialog if we're open in the panel -- if we're already
  // open as part of a modal dialog, then we MUST use another modal dialog or the result will
  // not be focusable!
  QgsPanelWidget *panel = QgsPanelWidget::findParentPanel( this );
  if ( !panel || !panel->dockMode()
       || !QgsGui::windowManager()
       || !QgsGui::windowManager()->openStandardDialog( QgsWindowManagerInterface::DialogStyleManager ) )
  {
    // fallback to modal dialog
    QgsStyleManagerDialog dlg( mStyle, this );
    dlg.exec();

    updateModelFilters(); // probably not needed -- the model should automatically update if any changes were made
  }
}
コード例 #11
0
ファイル: qgscolorrampbutton.cpp プロジェクト: cz172638/QGIS
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() );
      }
    }
  }
}