|
31 | 31 | #include "qgssnappingdialog.h"
|
32 | 32 | #include "qgsrasterlayer.h"
|
33 | 33 | #include "qgsgenericprojectionselector.h"
|
| 34 | +#include "qgsstylev2.h" |
| 35 | +#include "qgssymbolv2.h" |
| 36 | +#include "qgsstylev2managerdialog.h" |
| 37 | +#include "qgsvectorcolorrampv2.h" |
| 38 | +#include "qgssymbolv2propertiesdialog.h" |
34 | 39 |
|
35 | 40 | //qt includes
|
36 | 41 | #include <QColorDialog>
|
@@ -276,6 +281,10 @@ QgsProjectProperties::QgsProjectProperties( QgsMapCanvas* mapCanvas, QWidget *pa
|
276 | 281 | twWFSLayers->setRowCount( j );
|
277 | 282 | twWFSLayers->verticalHeader()->setResizeMode( QHeaderView::ResizeToContents );
|
278 | 283 |
|
| 284 | + // Default Styles |
| 285 | + mStyle = QgsStyleV2::defaultStyle(); |
| 286 | + populateStyles(); |
| 287 | + |
279 | 288 | restoreState();
|
280 | 289 | }
|
281 | 290 |
|
@@ -506,6 +515,13 @@ void QgsProjectProperties::apply()
|
506 | 515 | }
|
507 | 516 | QgsProject::instance()->writeEntry( "WFSLayers", "/", wfsLayerList );
|
508 | 517 |
|
| 518 | + // Default Styles |
| 519 | + QgsProject::instance()->writeEntry( "DefaultStyles", "/Marker", cboStyleMarker->currentText() ); |
| 520 | + QgsProject::instance()->writeEntry( "DefaultStyles", "/Line", cboStyleLine->currentText() ); |
| 521 | + QgsProject::instance()->writeEntry( "DefaultStyles", "/Fill", cboStyleFill->currentText() ); |
| 522 | + QgsProject::instance()->writeEntry( "DefaultStyles", "/ColorRamp", cboStyleColorRamp->currentText() ); |
| 523 | + QgsProject::instance()->writeEntry( "DefaultStyles", "/RandomColors", cbxStyleRandomColors->isChecked() ); |
| 524 | + |
509 | 525 | //todo XXX set canvas color
|
510 | 526 | emit refresh();
|
511 | 527 | }
|
@@ -677,3 +693,136 @@ void QgsProjectProperties::on_pbnWMSSetUsedSRS_clicked()
|
677 | 693 | mWMSList->clear();
|
678 | 694 | mWMSList->addItems( crsList.values() );
|
679 | 695 | }
|
| 696 | + |
| 697 | +void QgsProjectProperties::populateStyles() |
| 698 | +{ |
| 699 | + // Styles - taken from qgsstylev2managerdialog |
| 700 | + |
| 701 | + // use QComboBox and QString lists for shorter code |
| 702 | + QStringList prefList; |
| 703 | + QList<QComboBox*> cboList; |
| 704 | + cboList << cboStyleMarker; |
| 705 | + prefList << QgsProject::instance()->readEntry( "DefaultStyles", "/Marker", "" ); |
| 706 | + cboList << cboStyleLine; |
| 707 | + prefList << QgsProject::instance()->readEntry( "DefaultStyles", "/Line", "" ); |
| 708 | + cboList << cboStyleFill; |
| 709 | + prefList << QgsProject::instance()->readEntry( "DefaultStyles", "/Fill", "" ); |
| 710 | + cboList << cboStyleColorRamp; |
| 711 | + prefList << QgsProject::instance()->readEntry( "DefaultStyles", "/ColorRamp", "" ); |
| 712 | + for ( int i = 0; i < cboList.count(); i++ ) |
| 713 | + { |
| 714 | + cboList[i]->clear(); |
| 715 | + cboList[i]->addItem( "" ); |
| 716 | + } |
| 717 | + |
| 718 | + // populate symbols |
| 719 | + QStringList symbolNames = mStyle->symbolNames(); |
| 720 | + for ( int i = 0; i < symbolNames.count(); ++i ) |
| 721 | + { |
| 722 | + QString name = symbolNames[i]; |
| 723 | + QgsSymbolV2* symbol = mStyle->symbol( name ); |
| 724 | + QComboBox* cbo = 0; |
| 725 | + switch ( symbol->type() ) |
| 726 | + { |
| 727 | + case QgsSymbolV2::Marker : |
| 728 | + cbo = cboStyleMarker; |
| 729 | + break; |
| 730 | + case QgsSymbolV2::Line : |
| 731 | + cbo = cboStyleLine; |
| 732 | + break; |
| 733 | + case QgsSymbolV2::Fill : |
| 734 | + cbo = cboStyleFill; |
| 735 | + break; |
| 736 | + } |
| 737 | + if ( cbo ) |
| 738 | + { |
| 739 | + QIcon icon = QgsSymbolLayerV2Utils::symbolPreviewIcon( symbol, cbo->iconSize() ); |
| 740 | + cbo->addItem( icon, name ); |
| 741 | + } |
| 742 | + delete symbol; |
| 743 | + } |
| 744 | + |
| 745 | + // populate color ramps |
| 746 | + QStringList colorRamps = mStyle->colorRampNames(); |
| 747 | + for ( int i = 0; i < colorRamps.count(); ++i ) |
| 748 | + { |
| 749 | + QString name = colorRamps[i]; |
| 750 | + QgsVectorColorRampV2* ramp = mStyle->colorRamp( name ); |
| 751 | + QIcon icon = QgsSymbolLayerV2Utils::colorRampPreviewIcon( ramp, cboStyleColorRamp->iconSize() ); |
| 752 | + cboStyleColorRamp->addItem( icon, name ); |
| 753 | + delete ramp; |
| 754 | + } |
| 755 | + |
| 756 | + // set current index if found |
| 757 | + for ( int i = 0; i < cboList.count(); i++ ) |
| 758 | + { |
| 759 | + int index = cboList[i]->findText( prefList[i], Qt::MatchCaseSensitive ); |
| 760 | + if ( index >= 0 ) |
| 761 | + cboList[i]->setCurrentIndex( index ); |
| 762 | + } |
| 763 | + |
| 764 | + // random colors? |
| 765 | + cbxStyleRandomColors->setChecked( QgsProject::instance()->readBoolEntry( "DefaultStyles", "/RandomColors", true ) ); |
| 766 | + |
| 767 | +} |
| 768 | + |
| 769 | +void QgsProjectProperties::on_pbtnStyleManager_clicked() |
| 770 | +{ |
| 771 | + QgsStyleV2ManagerDialog dlg( mStyle, this ); |
| 772 | + dlg.exec(); |
| 773 | + populateStyles(); |
| 774 | +} |
| 775 | + |
| 776 | +void QgsProjectProperties::on_pbtnStyleMarker_clicked() |
| 777 | +{ |
| 778 | + editSymbol( cboStyleMarker ); |
| 779 | +} |
| 780 | + |
| 781 | +void QgsProjectProperties::on_pbtnStyleLine_clicked() |
| 782 | +{ |
| 783 | + editSymbol( cboStyleLine ); |
| 784 | +} |
| 785 | + |
| 786 | +void QgsProjectProperties::on_pbtnStyleFill_clicked() |
| 787 | +{ |
| 788 | + editSymbol( cboStyleFill ); |
| 789 | +} |
| 790 | + |
| 791 | +void QgsProjectProperties::editSymbol( QComboBox* cbo ) |
| 792 | +{ |
| 793 | + QString symbolName = cbo->currentText(); |
| 794 | + if ( symbolName == "" ) |
| 795 | + { |
| 796 | + QMessageBox::information( this, "", tr( "Select a valid symbol" ) ); |
| 797 | + return; |
| 798 | + } |
| 799 | + QgsSymbolV2* symbol = mStyle->symbol( symbolName ); |
| 800 | + if ( ! symbol ) |
| 801 | + { |
| 802 | + QMessageBox::warning( this, "", tr( "Invalid symbol : " ) + symbolName ); |
| 803 | + return; |
| 804 | + } |
| 805 | + |
| 806 | + // let the user edit the symbol and update list when done |
| 807 | + QgsSymbolV2PropertiesDialog dlg( symbol, 0, this ); |
| 808 | + if ( dlg.exec() == 0 ) |
| 809 | + { |
| 810 | + delete symbol; |
| 811 | + return; |
| 812 | + } |
| 813 | + |
| 814 | + // by adding symbol to style with the same name the old effectively gets overwritten |
| 815 | + mStyle->addSymbol( symbolName, symbol ); |
| 816 | + |
| 817 | + // update icon |
| 818 | + QIcon icon = QgsSymbolLayerV2Utils::symbolPreviewIcon( symbol, cbo->iconSize() ); |
| 819 | + cbo->setItemIcon( cbo->currentIndex(), icon ); |
| 820 | +} |
| 821 | + |
| 822 | +void QgsProjectProperties::on_pbtnStyleColorRamp_clicked() |
| 823 | +{ |
| 824 | + // TODO for now just open style manager |
| 825 | + // code in QgsStyleV2ManagerDialog::editColorRamp() |
| 826 | + on_pbtnStyleManager_clicked(); |
| 827 | +} |
| 828 | + |
0 commit comments