void QgsCptCityColorRampDialog::mListWidget_itemClicked( QListWidgetItem *item ) { QgsCptCityColorRampItem *rampItem = mListRamps.at( item->data( Qt::UserRole ).toInt() ); if ( rampItem ) { buttonBox->button( QDialogButtonBox::Ok )->setEnabled( true ); lblSchemeName->setText( QFileInfo( rampItem->name() ).fileName() ); mRamp.copy( &rampItem->ramp() ); QgsDebugMsg( QStringLiteral( "variant= %1 - %2 variants" ).arg( mRamp.variantName() ).arg( mRamp.variantList().count() ) ); populateVariants(); } else { QgsDebugMsg( QStringLiteral( "invalid item" ) ); } }
void QgsCptCityColorRampV2Dialog::populateVariants( QString newVariant ) { QStringList variantList; QgsCptCityColorRampItem *item = dynamic_cast< QgsCptCityColorRampItem* >( mModel->dataItem( mBrowserView->currentIndex() ) ); if ( item ) variantList = item->ramp().variantList(); cboVariantName->blockSignals( true ); cboVariantName->clear(); if ( variantList.isEmpty() ) { cboVariantName->setEnabled( false ); cboVariantName->setVisible( false ); on_cboVariantName_currentIndexChanged( -1 ); } else { QString oldVariant = cboVariantName->currentText(); QgsCptCityColorRampV2 ramp( mRamp->schemeName(), mRamp->variantList(), QString() ); QPixmap blankPixmap( cboVariantName->iconSize() ); blankPixmap.fill( Qt::white ); QIcon blankIcon( blankPixmap ); int index; foreach ( QString variant, variantList ) { QString variantStr = variant; if ( variantStr.startsWith( "-" ) || variantStr.startsWith( "_" ) ) variantStr.remove( 0, 1 ); cboVariantName->addItem( " " + variantStr ); index = cboVariantName->count() - 1; cboVariantName->setItemData( index, variant, Qt::UserRole ); ramp.setVariantName( variant ); if ( ramp.loadFile() ) cboVariantName->setItemIcon( index, QgsSymbolLayerV2Utils::colorRampPreviewIcon( &ramp, cboVariantName->iconSize() ) ); else cboVariantName->setItemIcon( index, blankIcon ); cboVariantName->setItemData( index, Qt::AlignHCenter, Qt::TextAlignmentRole ); } cboVariantName->blockSignals( false ); cboVariantName->setEnabled( true ); cboVariantName->setVisible( true ); // try to set the original variant again (if exists) int idx; if ( newVariant != QString() ) { if ( newVariant.startsWith( "-" ) || newVariant.startsWith( "_" ) ) newVariant.remove( 0, 1 ); newVariant = " " + newVariant; idx = cboVariantName->findText( newVariant ); } else idx = cboVariantName->findText( oldVariant ); // if not found use the item in the middle if ( idx == -1 ) { idx = cboVariantName->count() / 2; } cboVariantName->setCurrentIndex( idx ); // updatePreview(); }