Skip to content
Permalink
Browse files

Merge branch 'symbology_copy_paste'

  • Loading branch information
mhugent committed Dec 5, 2013
2 parents f2fbb2f + 4260a23 commit 813459da48fbede6792c01cc2f9d24a74a77fa94
@@ -49,7 +49,7 @@ QgsRendererCategoryV2::QgsRendererCategoryV2( const QgsRendererCategoryV2& cat )

QgsRendererCategoryV2::~QgsRendererCategoryV2()
{
if ( mSymbol ) delete mSymbol;
delete mSymbol;
}

QgsRendererCategoryV2& QgsRendererCategoryV2::operator=( const QgsRendererCategoryV2 & cat )
@@ -1186,6 +1186,11 @@ void QgsGraduatedSymbolRendererV2::addClass( QgsSymbolV2* symbol )

}

void QgsGraduatedSymbolRendererV2::addClass( QgsRendererRangeV2 range )
{
mRanges.append( range );
}

void QgsGraduatedSymbolRendererV2::deleteClass( int idx )
{
mRanges.removeAt( idx );
@@ -95,6 +95,7 @@ class CORE_EXPORT QgsGraduatedSymbolRendererV2 : public QgsFeatureRendererV2
bool updateRangeLowerValue( int rangeIndex, double value );

void addClass( QgsSymbolV2* symbol );
void addClass( QgsRendererRangeV2 range );
void deleteClass( int idx );
void deleteAllClasses();

@@ -319,6 +319,52 @@ void QgsVectorRandomColorRampV2::updateColors()
}
}

/////////////

QgsRandomColorsV2::QgsRandomColorsV2()
{
srand( QTime::currentTime().msec() );
}

QgsRandomColorsV2::~QgsRandomColorsV2()
{

}

int QgsRandomColorsV2::count() const
{
return INT_MAX;
}

double QgsRandomColorsV2::value( int index ) const
{
Q_UNUSED( index );
return 0.0;
}

QColor QgsRandomColorsV2::color( double value ) const
{
Q_UNUSED( value );
int r = 1 + ( int )( 255.0 * rand() / ( RAND_MAX + 1.0 ) );
int g = 1 + ( int )( 255.0 * rand() / ( RAND_MAX + 1.0 ) );
int b = 1 + ( int )( 255.0 * rand() / ( RAND_MAX + 1.0 ) );
return QColor( r, g, b );
}

QString QgsRandomColorsV2::type() const
{
return "randomcolors";
}

QgsVectorColorRampV2* QgsRandomColorsV2::clone() const
{
return new QgsRandomColorsV2();
}

QgsStringMap QgsRandomColorsV2::properties() const
{
return QgsStringMap();
}

////////////

@@ -155,6 +155,25 @@ class CORE_EXPORT QgsVectorRandomColorRampV2 : public QgsVectorColorRampV2
QList<QColor> mColors;
};

class CORE_EXPORT QgsRandomColorsV2: public QgsVectorColorRampV2
{
public:
QgsRandomColorsV2();
~QgsRandomColorsV2();

int count() const;

double value( int index ) const;

QColor color( double value ) const;

QString type() const;

QgsVectorColorRampV2* clone() const;

QgsStringMap properties() const;
};


#define DEFAULT_COLORBREWER_SCHEMENAME "Spectral"
#define DEFAULT_COLORBREWER_COLORS 5
@@ -30,6 +30,7 @@
#include "qgsproject.h"
#include "qgsexpression.h"

#include <QKeyEvent>
#include <QMenu>
#include <QMessageBox>
#include <QStandardItemModel>
@@ -68,6 +69,21 @@ void QgsCategorizedSymbolRendererV2Model::addCategory( const QgsRendererCategory
endInsertRows();
}

QgsRendererCategoryV2 QgsCategorizedSymbolRendererV2Model::category( const QModelIndex &index )
{
if ( !mRenderer )
{
return QgsRendererCategoryV2();
}
const QgsCategoryList& catList = mRenderer->categories();
int row = index.row();
if ( row >= catList.size() )
{
return QgsRendererCategoryV2();
}
return catList.at( row );
}


Qt::ItemFlags QgsCategorizedSymbolRendererV2Model::flags( const QModelIndex & index ) const
{
@@ -355,6 +371,11 @@ QgsCategorizedSymbolRendererV2Widget::QgsCategorizedSymbolRendererV2Widget( QgsV
populateColumns();

cboCategorizedColorRamp->populate( mStyle );
int randomIndex = cboCategorizedColorRamp->findText( tr( "Random colors" ) );
if ( randomIndex != -1 )
{
cboCategorizedColorRamp->setCurrentIndex( randomIndex );
}

// set project default color ramp
QString defaultColorRamp = QgsProject::instance()->readEntry( "DefaultStyles", "/ColorRamp", "" );
@@ -822,6 +843,24 @@ QList<QgsSymbolV2*> QgsCategorizedSymbolRendererV2Widget::selectedSymbols()
return selectedSymbols;
}

QgsCategoryList QgsCategorizedSymbolRendererV2Widget::selectedCategoryList()
{
QgsCategoryList cl;

QItemSelectionModel* m = viewCategories->selectionModel();
QModelIndexList selectedIndexes = m->selectedRows( 1 );

if ( m && selectedIndexes.size() > 0 )
{
QModelIndexList::const_iterator indexIt = selectedIndexes.constBegin();
for ( ; indexIt != selectedIndexes.constEnd(); ++indexIt )
{
cl.append( mModel->category( *indexIt ) );
}
}
return cl;
}

void QgsCategorizedSymbolRendererV2Widget::showSymbolLevels()
{
showSymbolLevelsDialog( mRenderer );
@@ -831,3 +870,25 @@ void QgsCategorizedSymbolRendererV2Widget::rowsMoved()
{
viewCategories->selectionModel()->clear();
}

void QgsCategorizedSymbolRendererV2Widget::keyPressEvent( QKeyEvent* event )
{
if ( !event )
{
return;
}

if ( event->key() == Qt::Key_C && event->modifiers() == Qt::ControlModifier )
{
mCopyBuffer.clear();
mCopyBuffer = selectedCategoryList();
}
else if ( event->key() == Qt::Key_V && event->modifiers() == Qt::ControlModifier )
{
QgsCategoryList::const_iterator rIt = mCopyBuffer.constBegin();
for ( ; rIt != mCopyBuffer.constEnd(); ++rIt )
{
mModel->addCategory( *rIt );
}
}
}
@@ -46,6 +46,7 @@ class GUI_EXPORT QgsCategorizedSymbolRendererV2Model : public QAbstractItemModel
void setRenderer( QgsCategorizedSymbolRendererV2* renderer );

void addCategory( const QgsRendererCategoryV2 &cat );
QgsRendererCategoryV2 category( const QModelIndex &index );
void deleteRows( QList<int> rows );
void removeAllRows( );
void sort( int column, Qt::SortOrder order = Qt::AscendingOrder );
@@ -120,7 +121,9 @@ class GUI_EXPORT QgsCategorizedSymbolRendererV2Widget : public QgsRendererV2Widg
void changeCategorySymbol();

QList<QgsSymbolV2*> selectedSymbols();
QgsCategoryList selectedCategoryList();
void refreshSymbolView() { populateCategories(); }
void keyPressEvent( QKeyEvent* event );

protected:
QgsCategorizedSymbolRendererV2* mRenderer;
@@ -133,6 +136,7 @@ class GUI_EXPORT QgsCategorizedSymbolRendererV2Widget : public QgsRendererV2Widg

private:
QString mOldClassificationAttribute;
QgsCategoryList mCopyBuffer;
};

#endif // QGSCATEGORIZEDSYMBOLRENDERERV2WIDGET_H
@@ -54,14 +54,20 @@ void QgsColorRampComboBox::populate( QgsStyleV2* style )
delete ramp;
}

addItem( tr( "Random colors" ) );
addItem( tr( "New color ramp..." ) );
connect( this, SIGNAL( activated( int ) ), SLOT( colorRampChanged( int ) ) );
}

QgsVectorColorRampV2* QgsColorRampComboBox::currentColorRamp()
{
QString rampName = currentText();
if ( rampName == "[source]" && mSourceColorRamp )

if ( rampName == tr( "Random colors" ) )
{
return new QgsRandomColorsV2();
}
else if ( rampName == "[source]" && mSourceColorRamp )
return mSourceColorRamp->clone();
else
return mStyle->colorRamp( rampName );
@@ -28,6 +28,7 @@

#include "qgsproject.h"

#include <QKeyEvent>
#include <QMenu>
#include <QMessageBox>
#include <QStandardItemModel>
@@ -68,6 +69,28 @@ void QgsGraduatedSymbolRendererV2Model::addClass( QgsSymbolV2* symbol )
endInsertRows();
}

void QgsGraduatedSymbolRendererV2Model::addClass( QgsRendererRangeV2 range )
{
if ( !mRenderer )
{
return;
}
int idx = mRenderer->ranges().size();
beginInsertRows( QModelIndex(), idx, idx );
mRenderer->addClass( range );
endInsertRows();
}

QgsRendererRangeV2 QgsGraduatedSymbolRendererV2Model::rendererRange( const QModelIndex &index )
{
if ( !index.isValid() || !mRenderer || mRenderer->ranges().size() <= index.row() )
{
return QgsRendererRangeV2();
}

return mRenderer->ranges().value( index.row() );
}

Qt::ItemFlags QgsGraduatedSymbolRendererV2Model::flags( const QModelIndex & index ) const
{
Qt::ItemFlags flags = Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled;
@@ -606,6 +629,19 @@ QList<int> QgsGraduatedSymbolRendererV2Widget::selectedClasses()
return rows;
}

QgsRangeList QgsGraduatedSymbolRendererV2Widget::selectedRanges()
{
QgsRangeList selectedRanges;
QModelIndexList selectedRows = viewGraduated->selectionModel()->selectedRows();
QModelIndexList::const_iterator sIt = selectedRows.constBegin();

for ( ; sIt != selectedRows.constEnd(); ++sIt )
{
selectedRanges.append( mModel->rendererRange( *sIt ) );
}
return selectedRanges;
}

void QgsGraduatedSymbolRendererV2Widget::rangesDoubleClicked( const QModelIndex & idx )
{
if ( idx.isValid() && idx.column() == 0 )
@@ -622,6 +658,8 @@ void QgsGraduatedSymbolRendererV2Widget::rangesClicked( const QModelIndex & idx
mRowSelected = idx.row();
}



void QgsGraduatedSymbolRendererV2Widget::changeSelectedSymbols()
{
QItemSelectionModel* m = viewGraduated->selectionModel();
@@ -778,3 +816,25 @@ void QgsGraduatedSymbolRendererV2Widget::rowsMoved()
{
viewGraduated->selectionModel()->clear();
}

void QgsGraduatedSymbolRendererV2Widget::keyPressEvent( QKeyEvent* event )
{
if ( !event )
{
return;
}

if ( event->key() == Qt::Key_C && event->modifiers() == Qt::ControlModifier )
{
mCopyBuffer.clear();
mCopyBuffer = selectedRanges();
}
else if ( event->key() == Qt::Key_V && event->modifiers() == Qt::ControlModifier )
{
QgsRangeList::const_iterator rIt = mCopyBuffer.constBegin();
for ( ; rIt != mCopyBuffer.constEnd(); ++rIt )
{
mModel->addClass( *rIt );
}
}
}
@@ -43,7 +43,9 @@ class GUI_EXPORT QgsGraduatedSymbolRendererV2Model : public QAbstractItemModel

void setRenderer( QgsGraduatedSymbolRendererV2* renderer );

QgsRendererRangeV2 rendererRange( const QModelIndex &index );
void addClass( QgsSymbolV2* symbol );
void addClass( QgsRendererRangeV2 range );
void deleteRows( QList<int> rows );
void removeAllRows( );
void sort( int column, Qt::SortOrder order = Qt::AscendingOrder );
@@ -109,6 +111,7 @@ class GUI_EXPORT QgsGraduatedSymbolRendererV2Widget : public QgsRendererV2Widget

//! return a list of indexes for the classes under selection
QList<int> selectedClasses();
QgsRangeList selectedRanges();

//! populate column combos in categorized and graduated page
void populateColumns();
@@ -122,6 +125,8 @@ class GUI_EXPORT QgsGraduatedSymbolRendererV2Widget : public QgsRendererV2Widget
QgsSymbolV2* findSymbolForRange( double lowerBound, double upperBound, const QgsRangeList& ranges ) const;
void refreshSymbolView();

void keyPressEvent( QKeyEvent* event );

protected:
QgsGraduatedSymbolRendererV2* mRenderer;

@@ -133,6 +138,7 @@ class GUI_EXPORT QgsGraduatedSymbolRendererV2Widget : public QgsRendererV2Widget

QgsGraduatedSymbolRendererV2Model* mModel;

QgsRangeList mCopyBuffer;
};


0 comments on commit 813459d

Please sign in to comment.
You can’t perform that action at this time.