Skip to content
Permalink
Browse files

Make table editing action text more descriptive

By describing the number of rows/columns affected, eg "Insert 2 Columns Before"
  • Loading branch information
nyalldawson committed Jan 14, 2020
1 parent 2e751dd commit 2117aa7a5db10b808aa7a702cc6a2a82ccf56658
@@ -144,6 +144,20 @@ if an automatic width should be used for the column.
This should be called after a call to setTableContents().

.. seealso:: :py:func:`tableColumnWidth`
%End

QList<int> rowsAssociatedWithSelection();
%Docstring
Returns a list of the rows associated with the current table selected cells.

.. seealso:: :py:func:`columnsAssociatedWithSelection`
%End

QList<int> columnsAssociatedWithSelection();
%Docstring
Returns a list of the columns associated with the current table selected cells.

.. seealso:: :py:func:`rowsAssociatedWithSelection`
%End

public slots:
@@ -52,16 +52,6 @@ QgsTableEditorDialog::QgsTableEditorDialog( QWidget *parent )

mTableWidget->setFocus();

QgsTableContents c;
c << QgsTableRow();
c.last() << QgsTableCell( "test" ) << QgsTableCell( "test2" );
c << QgsTableRow();
QgsTableCell cc( "test3" );
cc.setBackgroundColor( QColor( 255, 255, 255 ) );
cc.setForegroundColor( QColor( 255, 0, 255 ) );
c.last() << cc << QgsTableCell( "test4" );
mTableWidget->setTableContents( c );

connect( mTableWidget, &QgsTableEditorWidget::tableChanged, this, [ = ]
{
if ( !mBlockSignals )
@@ -98,7 +88,10 @@ QgsTableEditorDialog::QgsTableEditorDialog( QWidget *parent )
mFormattingWidget->setNumericFormat( mTableWidget->selectionNumericFormat(), mTableWidget->hasMixedSelectionNumericFormat() );
mFormattingWidget->setRowHeight( mTableWidget->selectionRowHeight() );
mFormattingWidget->setColumnWidth( mTableWidget->selectionColumnWidth() );

updateActionNamesFromSelection();
} );
updateActionNamesFromSelection();

addDockWidget( Qt::RightDockWidgetArea, mPropertiesDock );

@@ -147,4 +140,62 @@ void QgsTableEditorDialog::setTableColumnWidth( int column, double width )
mTableWidget->setTableColumnWidth( column, width );
}

void QgsTableEditorDialog::updateActionNamesFromSelection()
{
const int rowCount = mTableWidget->rowsAssociatedWithSelection().size();
const int columnCount = mTableWidget->columnsAssociatedWithSelection().size();

mActionInsertRowsAbove->setEnabled( rowCount > 0 );
mActionInsertRowsBelow->setEnabled( rowCount > 0 );
mActionDeleteRows->setEnabled( rowCount > 0 );
mActionSelectRow->setEnabled( rowCount > 0 );
if ( rowCount == 0 )
{
mActionInsertRowsAbove->setText( tr( "Rows Above" ) );
mActionInsertRowsBelow->setText( tr( "Rows Below" ) );
mActionDeleteRows->setText( tr( "Delete Rows" ) );
mActionSelectRow->setText( tr( "Select Rows" ) );
}
else if ( rowCount == 1 )
{
mActionInsertRowsAbove->setText( tr( "Row Above" ) );
mActionInsertRowsBelow->setText( tr( "Row Below" ) );
mActionDeleteRows->setText( tr( "Delete Row" ) );
mActionSelectRow->setText( tr( "Select Row" ) );
}
else
{
mActionInsertRowsAbove->setText( tr( "%1 Rows Above" ).arg( rowCount ) );
mActionInsertRowsBelow->setText( tr( "%1 Rows Below" ).arg( rowCount ) );
mActionDeleteRows->setText( tr( "Delete %1 Rows" ).arg( rowCount ) );
mActionSelectRow->setText( tr( "Select %1 Rows" ).arg( rowCount ) );
}

mActionInsertColumnsBefore->setEnabled( columnCount > 0 );
mActionInsertColumnsAfter->setEnabled( columnCount > 0 );
mActionDeleteColumns->setEnabled( columnCount > 0 );
mActionSelectColumn->setEnabled( columnCount > 0 );
if ( columnCount == 0 )
{
mActionInsertColumnsBefore->setText( tr( "Columns Before" ) );
mActionInsertColumnsAfter->setText( tr( "Columns After" ) );
mActionDeleteColumns->setText( tr( "Delete Columns" ) );
mActionSelectColumn->setText( tr( "Select Columns" ) );
}
else if ( columnCount == 1 )
{
mActionInsertColumnsBefore->setText( tr( "Column Before" ) );
mActionInsertColumnsAfter->setText( tr( "Column After" ) );
mActionDeleteColumns->setText( tr( "Delete Column" ) );
mActionSelectColumn->setText( tr( "Select Column" ) );
}
else
{
mActionInsertColumnsBefore->setText( tr( "%1 Columns Before" ).arg( columnCount ) );
mActionInsertColumnsAfter->setText( tr( "%1 Columns After" ).arg( columnCount ) );
mActionDeleteColumns->setText( tr( "Delete %1 Columns" ).arg( columnCount ) );
mActionSelectColumn->setText( tr( "Select %1 Columns" ).arg( columnCount ) );
}
}

#include "qgstableeditordialog.h"
@@ -111,6 +111,8 @@ class GUI_EXPORT QgsTableEditorDialog : public QMainWindow, private Ui::QgsTable
QgsPanelWidgetStack *mPropertiesStack = nullptr;
QgsTableEditorFormattingWidget *mFormattingWidget = nullptr;
bool mBlockSignals = false;

void updateActionNamesFromSelection();
};

#endif // QGSTABLEEDITORSHEETWIDGET_H
@@ -65,12 +65,12 @@ QgsTableEditorWidget::QgsTableEditorWidget( QWidget *parent )
mHeaderMenu->clear();
if ( isConsecutive )
{
QAction *insertBefore = mHeaderMenu->addAction( tr( "Insert Columns Before" ) );
QAction *insertBefore = mHeaderMenu->addAction( selectedColumns.size() > 1 ? tr( "Insert %1 Columns Before" ).arg( selectedColumns.size() ) : tr( "Insert Column Before" ) );
connect( insertBefore, &QAction::triggered, this, &QgsTableEditorWidget::insertColumnsBefore );
QAction *insertAfter = mHeaderMenu->addAction( tr( "Insert Columns After" ) );
QAction *insertAfter = mHeaderMenu->addAction( selectedColumns.size() > 1 ? tr( "Insert %1 Columns After" ).arg( selectedColumns.size() ) : tr( "Insert Column After" ) );
connect( insertAfter, &QAction::triggered, this, &QgsTableEditorWidget::insertColumnsAfter );
}
QAction *deleteSelected = mHeaderMenu->addAction( tr( "Delete Columns" ) );
QAction *deleteSelected = mHeaderMenu->addAction( selectedColumns.size() > 1 ? tr( "Delete %1 Columns" ).arg( selectedColumns.size() ) : tr( "Delete Column" ) );
connect( deleteSelected, &QAction::triggered, this, &QgsTableEditorWidget::deleteColumns );

mHeaderMenu->popup( horizontalHeader()->mapToGlobal( point ) );
@@ -107,12 +107,12 @@ QgsTableEditorWidget::QgsTableEditorWidget( QWidget *parent )
mHeaderMenu->clear();
if ( isConsecutive )
{
QAction *insertBefore = mHeaderMenu->addAction( tr( "Insert Rows Above" ) );
QAction *insertBefore = mHeaderMenu->addAction( selectedRows.size() > 1 ? tr( "Insert %1 Rows Above" ).arg( selectedRows.size() ) : tr( "Insert Row Above" ) );
connect( insertBefore, &QAction::triggered, this, &QgsTableEditorWidget::insertRowsAbove );
QAction *insertAfter = mHeaderMenu->addAction( tr( "Insert Rows Below" ) );
QAction *insertAfter = mHeaderMenu->addAction( selectedRows.size() > 1 ? tr( "Insert %1 Rows Below" ).arg( selectedRows.size() ) : tr( "Insert Row Below" ) );
connect( insertAfter, &QAction::triggered, this, &QgsTableEditorWidget::insertRowsBelow );
}
QAction *deleteSelected = mHeaderMenu->addAction( tr( "Delete Rows" ) );
QAction *deleteSelected = mHeaderMenu->addAction( selectedRows.size() > 1 ? tr( "Delete %1 Rows" ).arg( selectedRows.size() ) : tr( "Delete Row" ) );
connect( deleteSelected, &QAction::triggered, this, &QgsTableEditorWidget::deleteRows );

mHeaderMenu->popup( verticalHeader()->mapToGlobal( point ) );
@@ -582,6 +582,16 @@ void QgsTableEditorWidget::setTableColumnWidth( int col, double width )
emit tableChanged();
}

QList<int> QgsTableEditorWidget::rowsAssociatedWithSelection()
{
return collectUniqueRows( selectedIndexes() );
}

QList<int> QgsTableEditorWidget::columnsAssociatedWithSelection()
{
return collectUniqueColumns( selectedIndexes() );
}

void QgsTableEditorWidget::insertRowsBelow()
{
if ( rowCount() == 0 )
@@ -672,7 +682,7 @@ void QgsTableEditorWidget::insertColumnsAfter()

void QgsTableEditorWidget::deleteRows()
{
const QList< int > rows = collectUniqueRows( selectedIndexes() );
const QList< int > rows = rowsAssociatedWithSelection();
if ( rows.empty() )
return;

@@ -689,7 +699,7 @@ void QgsTableEditorWidget::deleteRows()

void QgsTableEditorWidget::deleteColumns()
{
const QList< int > columns = collectUniqueColumns( selectedIndexes() );
const QList< int > columns = columnsAssociatedWithSelection();
if ( columns.empty() )
return;

@@ -800,10 +810,9 @@ void QgsTableEditorWidget::setSelectionBackgroundColor( const QColor &color )

void QgsTableEditorWidget::setSelectionRowHeight( double height )
{
const QModelIndexList selection = selectedIndexes();
bool changed = false;
mBlockSignals++;
const QList< int > rows = collectUniqueRows( selection );
const QList< int > rows = rowsAssociatedWithSelection();
for ( int row : rows )
{
for ( int col = 0; col < columnCount(); ++col )
@@ -832,10 +841,9 @@ void QgsTableEditorWidget::setSelectionRowHeight( double height )

void QgsTableEditorWidget::setSelectionColumnWidth( double width )
{
const QModelIndexList selection = selectedIndexes();
bool changed = false;
mBlockSignals++;
const QList< int > cols = collectUniqueColumns( selection );
const QList< int > cols = columnsAssociatedWithSelection();
for ( int col : cols )
{
for ( int row = 0; row < rowCount(); ++row )
@@ -156,6 +156,20 @@ class GUI_EXPORT QgsTableEditorWidget : public QTableWidget
*/
void setTableColumnWidth( int column, double width );

/**
* Returns a list of the rows associated with the current table selected cells.
*
* \see columnsAssociatedWithSelection()
*/
QList<int> rowsAssociatedWithSelection();

/**
* Returns a list of the columns associated with the current table selected cells.
*
* \see rowsAssociatedWithSelection()
*/
QList<int> columnsAssociatedWithSelection();

public slots:

/**

0 comments on commit 2117aa7

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