diff --git a/src/gui/pointcloud/qgspointcloudclassifiedrendererwidget.cpp b/src/gui/pointcloud/qgspointcloudclassifiedrendererwidget.cpp index e03d76a97dc9..1af671b435f6 100644 --- a/src/gui/pointcloud/qgspointcloudclassifiedrendererwidget.cpp +++ b/src/gui/pointcloud/qgspointcloudclassifiedrendererwidget.cpp @@ -78,12 +78,13 @@ QgsPointCloudCategory QgsPointCloudClassifiedRendererModel::category( const QMod Qt::ItemFlags QgsPointCloudClassifiedRendererModel::flags( const QModelIndex &index ) const { + // Flat list, to ease drop handling valid indexes are not dropEnabled if ( !index.isValid() || mCategories.empty() ) { return Qt::ItemIsDropEnabled; } - Qt::ItemFlags flags = Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled | Qt::ItemIsUserCheckable; + Qt::ItemFlags flags = Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsDragEnabled | Qt::ItemIsUserCheckable; if ( index.column() == 1 || index.column() == 2 || index.column() == 3 ) { flags |= Qt::ItemIsEditable; @@ -292,8 +293,8 @@ QMimeData *QgsPointCloudClassifiedRendererModel::mimeData( const QModelIndexList bool QgsPointCloudClassifiedRendererModel::dropMimeData( const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent ) { - Q_UNUSED( row ) Q_UNUSED( column ) + Q_UNUSED( parent ) // Unused because only invalid indexes have Qt::ItemIsDropEnabled if ( action != Qt::MoveAction ) return true; @@ -311,7 +312,10 @@ bool QgsPointCloudClassifiedRendererModel::dropMimeData( const QMimeData *data, rows.append( r ); } - int to = parent.row(); + // Items may come unsorted depending on selecion order + std::sort( rows.begin(), rows.end() ); + + int to = row; // to is -1 if dragged outside items, i.e. below any item, // then move to the last position if ( to == -1 ) @@ -339,6 +343,7 @@ bool QgsPointCloudClassifiedRendererModel::dropMimeData( const QMimeData *data, } emit dataChanged( createIndex( 0, 0 ), createIndex( mCategories.size(), 0 ) ); emit categoriesChanged(); + emit rowsMoved(); return false; } @@ -425,6 +430,7 @@ QgsPointCloudClassifiedRendererWidget::QgsPointCloudClassifiedRendererWidget( Qg connect( mAttributeComboBox, &QgsPointCloudAttributeComboBox::attributeChanged, this, &QgsPointCloudClassifiedRendererWidget::attributeChanged ); connect( mModel, &QgsPointCloudClassifiedRendererModel::categoriesChanged, this, &QgsPointCloudClassifiedRendererWidget::emitWidgetChanged ); + connect( mModel, &QgsPointCloudClassifiedRendererModel::rowsMoved, this, &QgsPointCloudClassifiedRendererWidget::rowsMoved ); connect( viewCategories, &QAbstractItemView::doubleClicked, this, &QgsPointCloudClassifiedRendererWidget::categoriesDoubleClicked ); connect( btnAddCategories, &QAbstractButton::clicked, this, &QgsPointCloudClassifiedRendererWidget::addCategories ); @@ -706,6 +712,11 @@ void QgsPointCloudClassifiedRendererWidget::changeCategoryPointSize() } } +void QgsPointCloudClassifiedRendererWidget::rowsMoved() +{ + viewCategories->selectionModel()->clear(); +} + QList QgsPointCloudClassifiedRendererWidget::selectedCategories() { QList rows; diff --git a/src/gui/pointcloud/qgspointcloudclassifiedrendererwidget.h b/src/gui/pointcloud/qgspointcloudclassifiedrendererwidget.h index cdaedb1449c0..10d30854d4be 100644 --- a/src/gui/pointcloud/qgspointcloudclassifiedrendererwidget.h +++ b/src/gui/pointcloud/qgspointcloudclassifiedrendererwidget.h @@ -70,6 +70,9 @@ class GUI_EXPORT QgsPointCloudClassifiedRendererModel : public QAbstractItemMode signals: void categoriesChanged(); + //! Informs views that categories were moved (e.g., via mCategories.move()) in the model. + void rowsMoved(); + private: QgsPointCloudCategoryList mCategories; QMap mPercentages; @@ -126,6 +129,7 @@ class GUI_EXPORT QgsPointCloudClassifiedRendererWidget : public QgsPointCloudRen void changeCategoryColor(); void changeCategoryOpacity(); void changeCategoryPointSize(); + void rowsMoved(); private: //! Sets default category and available classes diff --git a/src/gui/symbology/qgscategorizedsymbolrendererwidget.cpp b/src/gui/symbology/qgscategorizedsymbolrendererwidget.cpp index df461a52d892..c67b657841cb 100644 --- a/src/gui/symbology/qgscategorizedsymbolrendererwidget.cpp +++ b/src/gui/symbology/qgscategorizedsymbolrendererwidget.cpp @@ -108,12 +108,13 @@ QgsRendererCategory QgsCategorizedSymbolRendererModel::category( const QModelInd Qt::ItemFlags QgsCategorizedSymbolRendererModel::flags( const QModelIndex &index ) const { + // Flat list, to ease drop handling valid indexes are not dropEnabled if ( !index.isValid() || !mRenderer ) { return Qt::ItemIsDropEnabled; } - Qt::ItemFlags flags = Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled | Qt::ItemIsUserCheckable; + Qt::ItemFlags flags = Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsDragEnabled | Qt::ItemIsUserCheckable; if ( index.column() == 1 ) { const QgsRendererCategory category = mRenderer->categories().value( index.row() ); @@ -398,8 +399,8 @@ QMimeData *QgsCategorizedSymbolRendererModel::mimeData( const QModelIndexList &i bool QgsCategorizedSymbolRendererModel::dropMimeData( const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent ) { - Q_UNUSED( row ) Q_UNUSED( column ) + Q_UNUSED( parent ) // Unused because only invalid indexes have Qt::ItemIsDropEnabled if ( action != Qt::MoveAction ) return true; @@ -417,7 +418,11 @@ bool QgsCategorizedSymbolRendererModel::dropMimeData( const QMimeData *data, Qt: rows.append( r ); } - int to = parent.row(); + // Items may come unsorted depending on selecion order + std::sort( rows.begin(), rows.end() ); + + int to = row; + // to is -1 if dragged outside items, i.e. below any item, // then move to the last position if ( to == -1 ) diff --git a/src/gui/symbology/qgsgraduatedsymbolrendererwidget.cpp b/src/gui/symbology/qgsgraduatedsymbolrendererwidget.cpp index e9c030725a75..605e54c5624b 100644 --- a/src/gui/symbology/qgsgraduatedsymbolrendererwidget.cpp +++ b/src/gui/symbology/qgsgraduatedsymbolrendererwidget.cpp @@ -134,12 +134,13 @@ QgsRendererRange QgsGraduatedSymbolRendererModel::rendererRange( const QModelInd Qt::ItemFlags QgsGraduatedSymbolRendererModel::flags( const QModelIndex &index ) const { + // Flat list, to ease drop handling valid indexes are not dropEnabled if ( !index.isValid() ) { return Qt::ItemIsDropEnabled; } - Qt::ItemFlags flags = Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled | Qt::ItemIsUserCheckable; + Qt::ItemFlags flags = Qt::ItemIsSelectable | Qt::ItemIsEnabled | Qt::ItemIsDragEnabled | Qt::ItemIsUserCheckable; if ( index.column() == 2 ) { @@ -306,8 +307,8 @@ QMimeData *QgsGraduatedSymbolRendererModel::mimeData( const QModelIndexList &ind bool QgsGraduatedSymbolRendererModel::dropMimeData( const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent ) { - Q_UNUSED( row ) Q_UNUSED( column ) + Q_UNUSED( parent ) // Unused because only invalid indexes have Qt::ItemIsDropEnabled if ( action != Qt::MoveAction ) return true; @@ -325,7 +326,11 @@ bool QgsGraduatedSymbolRendererModel::dropMimeData( const QMimeData *data, Qt::D rows.append( r ); } - int to = parent.row(); + // Items may come unsorted depending on selecion order + std::sort( rows.begin(), rows.end() ); + + int to = row; + // to is -1 if dragged outside items, i.e. below any item, // then move to the last position if ( to == -1 )