Skip to content
Permalink
Browse files

[FEATURE]: possibility to copy/paste entries in renderer widgets (usi…

…ng ctrl+c/ctrl+v)
  • Loading branch information
mhugent committed Dec 2, 2013
1 parent f21562c commit b232e74c261434323de04e7f68e3629f62c47cee
@@ -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();

@@ -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
{
@@ -822,6 +838,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 +865,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
@@ -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,20 @@ QList<int> QgsGraduatedSymbolRendererV2Widget::selectedClasses()
return rows;
}

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

const QgsRangeList& ranges = mRenderer->ranges();
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 +659,8 @@ void QgsGraduatedSymbolRendererV2Widget::rangesClicked( const QModelIndex & idx
mRowSelected = idx.row();
}



void QgsGraduatedSymbolRendererV2Widget::changeSelectedSymbols()
{
QItemSelectionModel* m = viewGraduated->selectionModel();
@@ -778,3 +817,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;
};


@@ -25,6 +25,7 @@
#include "qgslogger.h"
#include "qstring.h"

#include <QKeyEvent>
#include <QMenu>
#include <QProgressDialog>
#include <QSettings>
@@ -110,6 +111,7 @@ QgsRuleBasedRendererV2Widget::QgsRuleBasedRendererV2Widget( QgsVectorLayer* laye

QgsRuleBasedRendererV2Widget::~QgsRuleBasedRendererV2Widget()
{
qDeleteAll( mCopyBuffer );
delete mRenderer;
}

@@ -366,6 +368,23 @@ QList<QgsSymbolV2*> QgsRuleBasedRendererV2Widget::selectedSymbols()
return symbolList;
}

QgsRuleBasedRendererV2::RuleList QgsRuleBasedRendererV2Widget::selectedRules()
{
QgsRuleBasedRendererV2::RuleList rl;
QItemSelection sel = viewRules->selectionModel()->selection();
foreach ( QItemSelectionRange range, sel )
{
QModelIndex parent = range.parent();
QgsRuleBasedRendererV2::Rule* parentRule = mModel->ruleForIndex( parent );
QgsRuleBasedRendererV2::RuleList& children = parentRule->children();
for ( int row = range.top(); row <= range.bottom(); row++ )
{
rl.append( children[row]->clone() );
}
}
return rl;
}

void QgsRuleBasedRendererV2Widget::refreshSymbolView()
{
// TODO: model/view
@@ -377,6 +396,30 @@ void QgsRuleBasedRendererV2Widget::refreshSymbolView()
*/
}

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

if ( event->key() == Qt::Key_C && event->modifiers() == Qt::ControlModifier )
{
qDeleteAll( mCopyBuffer );
mCopyBuffer.clear();
mCopyBuffer = selectedRules();
}
else if ( event->key() == Qt::Key_V && event->modifiers() == Qt::ControlModifier )
{
QgsRuleBasedRendererV2::RuleList::const_iterator rIt = mCopyBuffer.constBegin();
for ( ; rIt != mCopyBuffer.constEnd(); ++rIt )
{
int rows = mModel->rowCount();
mModel->insertRule( QModelIndex(), rows, ( *rIt )->clone() );
}
}
}

#include "qgssymbollevelsv2dialog.h"

void QgsRuleBasedRendererV2Widget::setRenderingOrder()
@@ -136,14 +136,18 @@ class GUI_EXPORT QgsRuleBasedRendererV2Widget : public QgsRendererV2Widget, priv
QgsRuleBasedRendererV2::Rule* currentRule();

QList<QgsSymbolV2*> selectedSymbols();
QgsRuleBasedRendererV2::RuleList selectedRules();
void refreshSymbolView();
void keyPressEvent( QKeyEvent* event );

QgsRuleBasedRendererV2* mRenderer;
QgsRuleBasedRendererV2Model* mModel;

QMenu* mRefineMenu;
QAction* mDeleteAction;

QgsRuleBasedRendererV2::RuleList mCopyBuffer;

protected slots:
void copy();
void paste();

0 comments on commit b232e74

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