void QgsVectorGradientColorRampV2Dialog::updateStops()
{
  QgsGradientStopsList stops = mRamp->stops();
  groupStops->setChecked( !stops.isEmpty() );

  QList<QTreeWidgetItem *> items;
  for ( QgsGradientStopsList::iterator it = stops.begin();
        it != stops.end(); ++it )
  {
    double val = it->offset * 100.0;
    QStringList lst;
    lst << "." << QString(( val < 10 ) ? '0' + QString::number( val ) : QString::number( val ) );
    QTreeWidgetItem* item = new QTreeWidgetItem( lst );

    setStopColor( item, it->color );
    item->setData( 0, StopOffsetRole, it->offset );

    items.append( item );
  }
  treeStops->clear();
  treeStops->insertTopLevelItems( 0, items );
  treeStops->resizeColumnToContents( 0 );
  treeStops->setColumnWidth( 0, treeStops->columnWidth( 0 ) + 20 );
  treeStops->sortByColumn( 1, Qt::AscendingOrder );
  treeStops->setSortingEnabled( true );
}
void QgsVectorGradientColorRampV2Dialog::updatePreview()
{
  // update ramp stops from the tree widget
  QgsGradientStopsList stops;
  if ( groupStops->isChecked() )
  {
    int count = treeStops->topLevelItemCount();
    for ( int i = 0; i < count; i++ )
    {
      QTreeWidgetItem* item = treeStops->topLevelItem( i );
      double offset = item->data( 0, StopOffsetRole ).toDouble();
      QColor color = item->data( 0, StopColorRole ).value<QColor>();
      stops.append( QgsGradientStop( offset, color ) );
    }
  }
  mRamp->setStops( stops );

  // generate the preview
  QSize size( 300, 40 );
  lblPreview->setPixmap( QgsSymbolLayerV2Utils::colorRampPreviewPixmap( mRamp, size ) );

  btnColor1->setColor( mRamp->color1() );
  btnColor2->setColor( mRamp->color2() );
}
Пример #3
0
QgsVectorColorRampV2* QgsVectorGradientColorRampV2::create( const QgsStringMap& props )
{
  // color1 and color2
  QColor color1 = DEFAULT_GRADIENT_COLOR1;
  QColor color2 = DEFAULT_GRADIENT_COLOR2;
  if ( props.contains( "color1" ) )
    color1 = QgsSymbolLayerV2Utils::decodeColor( props["color1"] );
  if ( props.contains( "color2" ) )
    color2 = QgsSymbolLayerV2Utils::decodeColor( props["color2"] );

  //stops
  QgsGradientStopsList stops;
  if ( props.contains( "stops" ) )
  {
    Q_FOREACH ( const QString& stop, props["stops"].split( ':' ) )
    {
      int i = stop.indexOf( ';' );
      if ( i == -1 )
        continue;

      QColor c = QgsSymbolLayerV2Utils::decodeColor( stop.mid( i + 1 ) );
      stops.append( QgsGradientStop( stop.left( i ).toDouble(), c ) );
    }
  }