Skip to content
Permalink
Browse files

[layouts] Improve UI for formatting manual table cells

Instead of the confusing duplicate settings for foreground color
vs cell text color, remove the foreground color button and only
expose this color setting via the cell text color.
  • Loading branch information
nyalldawson committed Sep 22, 2020
1 parent 8e9bf8b commit 8dd75cc9cc436b77cbb2c1c6984671247d4eaaec
@@ -76,7 +76,7 @@ Returns ``True`` if the current selection has a mix of numeric formats.
.. seealso:: :py:func:`selectionNumericFormat`
%End

QColor selectionForegroundColor();
QColor selectionForegroundColor() /Deprecated/;
%Docstring
Returns the foreground color for the currently selected cells.

@@ -86,6 +86,9 @@ invalid color will be returned.
.. seealso:: :py:func:`setSelectionForegroundColor`

.. seealso:: :py:func:`selectionBackgroundColor`

.. deprecated::
use selectionTextFormat() instead.
%End

QColor selectionBackgroundColor();
@@ -278,13 +281,16 @@ current selected cells.
Clears the contents of the currently selected cells.
%End

void setSelectionForegroundColor( const QColor &color );
void setSelectionForegroundColor( const QColor &color ) /Deprecated/;
%Docstring
Sets the foreground color for the currently selected cells.

.. seealso:: :py:func:`selectionForegroundColor`

.. seealso:: :py:func:`setSelectionBackgroundColor`

.. deprecated::
Use setSelectionTextFormat() instead.
%End

void setSelectionBackgroundColor( const QColor &color );
@@ -77,7 +77,6 @@ QgsTableEditorDialog::QgsTableEditorDialog( QWidget *parent )

mPropertiesDock->setFeatures( QDockWidget::NoDockWidgetFeatures );

connect( mFormattingWidget, &QgsTableEditorFormattingWidget::foregroundColorChanged, mTableWidget, &QgsTableEditorWidget::setSelectionForegroundColor );
connect( mFormattingWidget, &QgsTableEditorFormattingWidget::backgroundColorChanged, mTableWidget, &QgsTableEditorWidget::setSelectionBackgroundColor );

connect( mFormattingWidget, &QgsTableEditorFormattingWidget::horizontalAlignmentChanged, mTableWidget, &QgsTableEditorWidget::setSelectionHorizontalAlignment );
@@ -98,7 +97,6 @@ QgsTableEditorDialog::QgsTableEditorDialog( QWidget *parent )

connect( mTableWidget, &QgsTableEditorWidget::activeCellChanged, this, [ = ]
{
mFormattingWidget->setForegroundColor( mTableWidget->selectionForegroundColor() );
mFormattingWidget->setBackgroundColor( mTableWidget->selectionBackgroundColor() );
mFormattingWidget->setNumericFormat( mTableWidget->selectionNumericFormat(), mTableWidget->hasMixedSelectionNumericFormat() );
mFormattingWidget->setRowHeight( mTableWidget->selectionRowHeight() );
@@ -30,10 +30,6 @@ QgsTableEditorFormattingWidget::QgsTableEditorFormattingWidget( QWidget *parent
mFontButton->setShowNullFormat( true );
mFontButton->setNoFormatString( tr( "Clear Formatting" ) );

mTextColorButton->setAllowOpacity( true );
mTextColorButton->setColorDialogTitle( tr( "Text Color" ) );
mTextColorButton->setDefaultColor( QColor( 0, 0, 0 ) );
mTextColorButton->setShowNull( true );
mBackgroundColorButton->setAllowOpacity( true );
mBackgroundColorButton->setColorDialogTitle( tr( "Text Color" ) );
mBackgroundColorButton->setDefaultColor( QColor( 255, 255, 255 ) );
@@ -45,16 +41,6 @@ QgsTableEditorFormattingWidget::QgsTableEditorFormattingWidget( QWidget *parent
mRowHeightSpinBox->setClearValue( 0, tr( "Automatic" ) );
mColumnWidthSpinBox->setClearValue( 0, tr( "Automatic" ) );

connect( mTextColorButton, &QgsColorButton::colorChanged, this, [ = ]
{
if ( !mBlockSignals )
emit foregroundColorChanged( mTextColorButton->color() );
} );
connect( mTextColorButton, &QgsColorButton::cleared, this, [ = ]
{
if ( !mBlockSignals )
emit foregroundColorChanged( QColor() );
} );
connect( mBackgroundColorButton, &QgsColorButton::colorChanged, this, [ = ]
{
if ( !mBlockSignals )
@@ -161,13 +147,6 @@ QgsTextFormat QgsTableEditorFormattingWidget::textFormat() const
return mFontButton->textFormat();
}

void QgsTableEditorFormattingWidget::setForegroundColor( const QColor &color )
{
mBlockSignals++;
mTextColorButton->setColor( color );
mBlockSignals--;
}

void QgsTableEditorFormattingWidget::setBackgroundColor( const QColor &color )
{
mBlockSignals++;
@@ -67,14 +67,6 @@ class GUI_EXPORT QgsTableEditorFormattingWidget : public QgsPanelWidget, public
*/
QgsTextFormat textFormat() const;

/**
* Sets the cell foreground \a color to show in the widget.
*
* \see foregroundColorChanged()
* \see setBackgroundColor()
*/
void setForegroundColor( const QColor &color );

/**
* Sets the cell background \a color to show in the widget.
*
@@ -154,13 +146,6 @@ class GUI_EXPORT QgsTableEditorFormattingWidget : public QgsPanelWidget, public

signals:

/**
* Emitted whenever the cell foreground \a color is changed in the widget.
*
* \see setForegroundColor()
*/
void foregroundColorChanged( const QColor &color );

/**
* Emitted whenever the cell background \a color is changed in the widget.
*
@@ -324,7 +324,7 @@ void QgsTableEditorWidget::setTableContents( const QgsTableContents &contents )
item->setData( CellContent, col.content() ); // can't use EditRole, because Qt. (https://bugreports.qt.io/browse/QTBUG-11549)
item->setData( Qt::BackgroundRole, col.backgroundColor().isValid() ? col.backgroundColor() : QColor( 255, 255, 255 ) );
item->setData( PresetBackgroundColorRole, col.backgroundColor().isValid() ? col.backgroundColor() : QVariant() );
item->setData( Qt::ForegroundRole, col.foregroundColor().isValid() ? col.foregroundColor() : QVariant() );
item->setData( Qt::ForegroundRole, col.textFormat().isValid() ? col.textFormat().color() : QVariant() );
item->setData( TextFormat, QVariant::fromValue( col.textFormat() ) );
item->setData( HorizontalAlignment, static_cast< int >( col.horizontalAlignment() ) );
item->setData( VerticalAlignment, static_cast< int >( col.verticalAlignment() ) );
@@ -372,7 +372,6 @@ QgsTableContents QgsTableEditorWidget::tableContents() const
{
cell.setContent( i->data( CellProperty ).value< QgsProperty >().isActive() ? i->data( CellProperty ) : i->data( CellContent ) );
cell.setBackgroundColor( i->data( PresetBackgroundColorRole ).value< QColor >() );
cell.setForegroundColor( i->data( Qt::ForegroundRole ).value< QColor >() );
cell.setTextFormat( i->data( TextFormat ).value< QgsTextFormat >() );
cell.setHorizontalAlignment( static_cast< Qt::Alignment >( i->data( HorizontalAlignment ).toInt() ) );
cell.setVerticalAlignment( static_cast< Qt::Alignment >( i->data( VerticalAlignment ).toInt() ) );
@@ -494,25 +493,8 @@ bool QgsTableEditorWidget::hasMixedSelectionNumericFormat()

QColor QgsTableEditorWidget::selectionForegroundColor()
{
QColor c;
bool first = true;
const QModelIndexList selection = selectedIndexes();
for ( const QModelIndex &index : selection )
{
QColor indexColor = model()->data( index, Qt::ForegroundRole ).isValid() ? model()->data( index, Qt::ForegroundRole ).value< QColor >() : QColor();
if ( first )
{
c = indexColor;
first = false;
}
else if ( indexColor == c )
continue;
else
{
return QColor();
}
}
return c;
const QgsTextFormat f = selectionTextFormat();
return f.isValid() ? f.color() : QColor();
}

QColor QgsTableEditorWidget::selectionBackgroundColor()
@@ -963,13 +945,19 @@ void QgsTableEditorWidget::setSelectionForegroundColor( const QColor &color )
if ( i->data( Qt::ForegroundRole ).value< QColor >() != color )
{
i->setData( Qt::ForegroundRole, color.isValid() ? color : QVariant() );
QgsTextFormat f = i->data( TextFormat ).value< QgsTextFormat >();
f.setColor( color );
i->setData( TextFormat, QVariant::fromValue( f ) );
changed = true;
}
}
else
{
QTableWidgetItem *newItem = new QTableWidgetItem();
newItem->setData( Qt::ForegroundRole, color.isValid() ? color : QVariant() );
QgsTextFormat f;
f.setColor( color );
newItem->setData( TextFormat, QVariant::fromValue( f ) );
setItem( index.row(), index.column(), newItem );
changed = true;
}
@@ -1138,12 +1126,14 @@ void QgsTableEditorWidget::setSelectionTextFormat( const QgsTextFormat &format )
if ( QTableWidgetItem *i = item( index.row(), index.column() ) )
{
i->setData( TextFormat, QVariant::fromValue( format ) );
i->setData( Qt::ForegroundRole, format.color() );
changed = true;
}
else
{
QTableWidgetItem *newItem = new QTableWidgetItem();
newItem->setData( TextFormat, QVariant::fromValue( format ) );
newItem->setData( Qt::ForegroundRole, format.color() );
setItem( index.row(), index.column(), newItem );
changed = true;
}
@@ -169,8 +169,10 @@ class GUI_EXPORT QgsTableEditorWidget : public QTableWidget
*
* \see setSelectionForegroundColor()
* \see selectionBackgroundColor()
*
* \deprecated use selectionTextFormat() instead.
*/
QColor selectionForegroundColor();
Q_DECL_DEPRECATED QColor selectionForegroundColor() SIP_DEPRECATED;

/**
* Returns the background color for the currently selected cells.
@@ -364,8 +366,10 @@ class GUI_EXPORT QgsTableEditorWidget : public QTableWidget
*
* \see selectionForegroundColor()
* \see setSelectionBackgroundColor()
*
* \deprecated Use setSelectionTextFormat() instead.
*/
void setSelectionForegroundColor( const QColor &color );
Q_DECL_DEPRECATED void setSelectionForegroundColor( const QColor &color ) SIP_DEPRECATED;

/**
* Sets the background color for the currently selected cells.

0 comments on commit 8dd75cc

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