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::setItemStopColor( const QColor& newColor ) { if ( mCurrentItem ) { setStopColor( mCurrentItem, newColor ); updatePreview(); } }
void QgsVectorGradientColorRampV2Dialog::addStop() { #if defined(Q_WS_MAC) && QT_VERSION >= 0x040500 && defined(QT_MAC_USE_COCOA) // Native Mac dialog works only for Qt Carbon // Qt bug: http://bugreports.qt.nokia.com/browse/QTBUG-14889 // also Qt 4.7 Mac Cocoa bug: calling QInputDialog::getInt after QColorDialog::getColor will freeze app // workaround: call QColorDialog::getColor below instead of here, // but not needed at this time because of the other Qt bug // FIXME need to also check max QT_VERSION when Qt bug(s) fixed QColor color = QColorDialog::getColor( QColor(), this, "", QColorDialog::DontUseNativeDialog ); #else QColor color = QColorDialog::getColor( QColor(), this ); #endif if ( !color.isValid() ) return; bool ok; int val = 50; #if QT_VERSION >= 0x40500 val = QInputDialog::getInt( this, tr( "Offset of the stop" ), tr( "Please enter offset in percents (%) of the new stop" ), val, 0, 100, 1, &ok ); #else QString res = QInputDialog::getText( this, tr( "Offset of the stop" ), tr( "Please enter offset in percents (%) of the new stop" ), QLineEdit::Normal, QString::number( val ), &ok ); if ( ok ) val = res.toInt( &ok ); if ( ok ) ok = val >= 0 && val <= 100; #endif if ( !ok ) return; double key = val / 100.0; QStringList lst; lst << "." << QString::number( val, 'f', 0 ); QTreeWidgetItem* item = new QTreeWidgetItem( lst ); setStopColor( item, color ); item->setData( 0, StopOffsetRole, key ); treeStops->addTopLevelItem( item ); treeStops->resizeColumnToContents( 0 ); updatePreview(); }
void QgsVectorGradientColorRampV2Dialog::stopDoubleClicked( QTreeWidgetItem* item, int column ) { if ( column == 0 ) { #if defined(Q_WS_MAC) && QT_VERSION >= 0x040500 && defined(QT_MAC_USE_COCOA) // Native Mac dialog works only for Qt Carbon // Qt bug: http://bugreports.qt.nokia.com/browse/QTBUG-14889 // FIXME need to also check max QT_VERSION when Qt bug fixed QColor color = QColorDialog::getColor( item->data( 0, StopColorRole ).value<QColor>(), this, "", QColorDialog::DontUseNativeDialog ); #else QColor color = QColorDialog::getColor( item->data( 0, StopColorRole ).value<QColor>(), this ); #endif if ( !color.isValid() ) return; setStopColor( item, color ); updatePreview(); } else { bool ok; double key = item->data( 0, StopOffsetRole ).toDouble(); int val = ( int )( key * 100 ); #if QT_VERSION >= 0x40500 val = QInputDialog::getInt( this, tr( "Offset of the stop" ), tr( "Please enter offset in percents (%) of the new stop" ), val, 0, 100, 1, &ok ); #else QString res = QInputDialog::getText( this, tr( "Offset of the stop" ), tr( "Please enter offset in percents (%) of the new stop" ), QLineEdit::Normal, QString::number( val ), &ok ); if ( ok ) val = res.toInt( &ok ); if ( ok ) ok = val >= 0 && val <= 100; #endif if ( !ok ) return; double newkey = val / 100.0; item->setText( 1, QString::number( val ) ); item->setData( 0, StopOffsetRole, newkey ); updatePreview(); } }
QgsVectorGradientColorRampV2Dialog::QgsVectorGradientColorRampV2Dialog( QgsVectorGradientColorRampV2* ramp, QWidget* parent ) : QDialog( parent ), mRamp( ramp ) { setupUi( this ); connect( btnColor1, SIGNAL( clicked() ), this, SLOT( setColor1() ) ); connect( btnColor2, SIGNAL( clicked() ), this, SLOT( setColor2() ) ); // handle stops QgsVectorGradientColorRampV2::StopsMap stops = ramp->stops(); groupStops->setChecked( !stops.isEmpty() ); QgsVectorGradientColorRampV2::StopsMap::iterator i; QList<QTreeWidgetItem *> items; for ( i = stops.begin(); i != stops.end(); ++i ) { QStringList lst; lst << "." << QString::number( i.key()*100, 'f', 0 ); QTreeWidgetItem* item = new QTreeWidgetItem( lst ); setStopColor( item, i.value() ); item->setData( 0, StopOffsetRole, i.key() ); items.append( item ); } treeStops->insertTopLevelItems( 0, items ); treeStops->resizeColumnToContents( 0 ); treeStops->sortByColumn( 1, Qt::AscendingOrder ); treeStops->setSortingEnabled( true ); connect( groupStops, SIGNAL( toggled( bool ) ), this, SLOT( toggledStops( bool ) ) ); connect( btnAddStop, SIGNAL( clicked() ), this, SLOT( addStop() ) ); connect( btnRemoveStop, SIGNAL( clicked() ), this, SLOT( removeStop() ) ); connect( treeStops, SIGNAL( itemDoubleClicked( QTreeWidgetItem*, int ) ), this, SLOT( stopDoubleClicked( QTreeWidgetItem*, int ) ) ); updatePreview(); }