Skip to content

Commit

Permalink
Merge pull request #60751 from qgis/backport-60546-to-release-3_42
Browse files Browse the repository at this point in the history
[Backport release-3_42] [ux] Fix and harmonize drag and drop in Graduated, Categorized and Point Cloud classification symbol lists
  • Loading branch information
alexbruy authored Feb 26, 2025
2 parents c1a8e00 + e5b242d commit 1f5debe
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 9 deletions.
17 changes: 14 additions & 3 deletions src/gui/pointcloud/qgspointcloudclassifiedrendererwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand All @@ -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 )
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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 );
Expand Down Expand Up @@ -706,6 +712,11 @@ void QgsPointCloudClassifiedRendererWidget::changeCategoryPointSize()
}
}

void QgsPointCloudClassifiedRendererWidget::rowsMoved()
{
viewCategories->selectionModel()->clear();
}

QList<int> QgsPointCloudClassifiedRendererWidget::selectedCategories()
{
QList<int> rows;
Expand Down
4 changes: 4 additions & 0 deletions src/gui/pointcloud/qgspointcloudclassifiedrendererwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<int, float> mPercentages;
Expand Down Expand Up @@ -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
Expand Down
11 changes: 8 additions & 3 deletions src/gui/symbology/qgscategorizedsymbolrendererwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() );
Expand Down Expand Up @@ -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;

Expand All @@ -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 )
Expand Down
11 changes: 8 additions & 3 deletions src/gui/symbology/qgsgraduatedsymbolrendererwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 )
{
Expand Down Expand Up @@ -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;

Expand All @@ -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 )
Expand Down

0 comments on commit 1f5debe

Please sign in to comment.