Skip to content

Commit

Permalink
Improve api and UX for handling cell text formatting in manual tables,
Browse files Browse the repository at this point in the history
by removing the checkbox for overridding text format and using the
"not set" state from the font button instead
  • Loading branch information
nyalldawson committed Jul 14, 2020
1 parent cdc9126 commit 761f594
Show file tree
Hide file tree
Showing 14 changed files with 51 additions and 221 deletions.
22 changes: 0 additions & 22 deletions python/core/auto_generated/qgstablecell.sip.in
Expand Up @@ -103,28 +103,6 @@ Sets the cell's text ``format``.

.. seealso:: :py:func:`textFormat`

.. versionadded:: 3.16
%End

bool hasTextFormat() const;
%Docstring
Returns ``True`` if the cell has a specific text format which should be applied.

.. seealso:: :py:func:`textFormat`

.. seealso:: :py:func:`setHasTextFormat`

.. versionadded:: 3.16
%End

void setHasTextFormat( bool hasTextFormat );
%Docstring
Sets whether the cell has a specific text format which should be applied.

.. seealso:: :py:func:`setTextFormat`

.. seealso:: :py:func:`hasTextFormat`

.. versionadded:: 3.16
%End

Expand Down
Expand Up @@ -74,13 +74,6 @@ will be returned.
Returns ``True`` if the current selection has a mix of numeric formats.

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

bool hasMixedSelectionHasTextFormat();
%Docstring
Returns ``True`` if the current selection has a mix of text format override state.

.. versionadded:: 3.16
%End

QColor selectionForegroundColor();
Expand Down Expand Up @@ -131,12 +124,7 @@ the selected cells have a mix of different vertical alignments.
%Docstring
Returns the text format for the currently selected cells.

.. versionadded:: 3.16
%End

bool selectionHasTextFormat();
%Docstring
Returns whether the currently selected cells have the text format override option set.
Returns an invalid QgsTextFormat if the selection has mixed text format.

.. versionadded:: 3.16
%End
Expand Down Expand Up @@ -324,13 +312,6 @@ Sets the vertical alignment for the currently selected cells.
%Docstring
Sets the text ``format`` for the selected cells.

.. versionadded:: 3.16
%End

void setSelectionHasTextFormat( bool hasFormat );
%Docstring
Sets whether the selected cells have the text format override option set.

.. versionadded:: 3.16
%End

Expand Down
2 changes: 1 addition & 1 deletion src/core/layout/qgslayoutitemmanualtable.cpp
Expand Up @@ -312,7 +312,7 @@ QgsTextFormat QgsLayoutItemManualTable::textFormatForHeader( int column ) const

QgsTextFormat QgsLayoutItemManualTable::textFormatForCell( int row, int column ) const
{
if ( mContents.value( row ).value( column ).hasTextFormat() )
if ( mContents.value( row ).value( column ).textFormat().isValid() )
return mContents.value( row ).value( column ).textFormat();

return QgsLayoutTable::textFormatForCell( row, column );
Expand Down
19 changes: 11 additions & 8 deletions src/core/qgstablecell.cpp
Expand Up @@ -27,7 +27,6 @@ QgsTableCell::QgsTableCell( const QgsTableCell &other )
: mContent( other.mContent )
, mBackgroundColor( other.mBackgroundColor )
, mForegroundColor( other.mForegroundColor )
, mHasTextFormat( other.mHasTextFormat )
, mTextFormat( other.mTextFormat )
, mFormat( other.mFormat ? other.mFormat->clone() : nullptr )
, mHAlign( other.mHAlign )
Expand All @@ -41,7 +40,6 @@ QgsTableCell &QgsTableCell::operator=( const QgsTableCell &other )
mContent = other.mContent;
mBackgroundColor = other.mBackgroundColor;
mForegroundColor = other.mForegroundColor;
mHasTextFormat = other.mHasTextFormat;
mTextFormat = other.mTextFormat;
mFormat.reset( other.mFormat ? other.mFormat->clone() : nullptr );
mHAlign = other.mHAlign;
Expand Down Expand Up @@ -71,11 +69,13 @@ QVariantMap QgsTableCell::properties( const QgsReadWriteContext &context ) const
res.insert( QStringLiteral( "format" ), mFormat->configuration( context ) );
}

res.insert( QStringLiteral( "has_text_format" ), mHasTextFormat );
QDomDocument textDoc;
QDomElement textElem = mTextFormat.writeXml( textDoc, context );
textDoc.appendChild( textElem );
res.insert( QStringLiteral( "text_format" ), textDoc.toString() );
if ( mTextFormat.isValid() )
{
QDomDocument textDoc;
QDomElement textElem = mTextFormat.writeXml( textDoc, context );
textDoc.appendChild( textElem );
res.insert( QStringLiteral( "text_format" ), textDoc.toString() );
}

res.insert( QStringLiteral( "halign" ), static_cast< int >( mHAlign ) );
res.insert( QStringLiteral( "valign" ), static_cast< int >( mVAlign ) );
Expand All @@ -98,7 +98,10 @@ void QgsTableCell::setProperties( const QVariantMap &properties, const QgsReadWr
elem = doc.documentElement();
mTextFormat.readXml( elem, context );
}
mHasTextFormat = properties.value( QStringLiteral( "has_text_format" ) ).toBool();
else
{
mTextFormat = QgsTextFormat();
}

if ( properties.contains( QStringLiteral( "format_type" ) ) )
{
Expand Down
19 changes: 0 additions & 19 deletions src/core/qgstablecell.h
Expand Up @@ -115,24 +115,6 @@ class CORE_EXPORT QgsTableCell
*/
void setTextFormat( const QgsTextFormat &format ) { mTextFormat = format; }

/**
* Returns TRUE if the cell has a specific text format which should be applied.
*
* \see textFormat()
* \see setHasTextFormat()
* \since QGIS 3.16
*/
bool hasTextFormat() const { return mHasTextFormat; }

/**
* Sets whether the cell has a specific text format which should be applied.
*
* \see setTextFormat()
* \see hasTextFormat()
* \since QGIS 3.16
*/
void setHasTextFormat( bool hasTextFormat ) { mHasTextFormat = hasTextFormat; }

/**
* Returns the numeric format used for numbers in the cell, or NULLPTR if no format is set.
*
Expand Down Expand Up @@ -213,7 +195,6 @@ class CORE_EXPORT QgsTableCell
QVariant mContent;
QColor mBackgroundColor;
QColor mForegroundColor;
bool mHasTextFormat = false;
QgsTextFormat mTextFormat;
std::unique_ptr< QgsNumericFormat > mFormat;

Expand Down
2 changes: 1 addition & 1 deletion src/core/textrenderer/qgstextformat.cpp
Expand Up @@ -63,7 +63,7 @@ bool QgsTextFormat::operator==( const QgsTextFormat &other ) const
{
if ( d->isValid != other.isValid()
|| d->textFont != other.font()
|| d->textNamedStyle != other.namedStyle()
|| namedStyle() != other.namedStyle()
|| d->fontSizeUnits != other.sizeUnit()
|| d->fontSizeMapUnitScale != other.sizeMapUnitScale()
|| d->fontSize != other.size()
Expand Down
6 changes: 1 addition & 5 deletions src/gui/tableeditor/qgstableeditordialog.cpp
Expand Up @@ -86,10 +86,6 @@ QgsTableEditorDialog::QgsTableEditorDialog( QWidget *parent )
{
mTableWidget->setSelectionTextFormat( mFormattingWidget->textFormat() );
} );
connect( mFormattingWidget, &QgsTableEditorFormattingWidget::hasTextFormatChanged, this, [ = ]
{
mTableWidget->setSelectionHasTextFormat( mFormattingWidget->textFormatSet() );
} );

connect( mFormattingWidget, &QgsTableEditorFormattingWidget::numberFormatChanged, this, [ = ]
{
Expand All @@ -105,7 +101,7 @@ QgsTableEditorDialog::QgsTableEditorDialog( QWidget *parent )
mFormattingWidget->setNumericFormat( mTableWidget->selectionNumericFormat(), mTableWidget->hasMixedSelectionNumericFormat() );
mFormattingWidget->setRowHeight( mTableWidget->selectionRowHeight() );
mFormattingWidget->setColumnWidth( mTableWidget->selectionColumnWidth() );
mFormattingWidget->setTextFormat( mTableWidget->selectionTextFormat(), mTableWidget->selectionHasTextFormat(), mTableWidget->hasMixedSelectionHasTextFormat() );
mFormattingWidget->setTextFormat( mTableWidget->selectionTextFormat() );
mFormattingWidget->setHorizontalAlignment( mTableWidget->selectionHorizontalAlignment() );
mFormattingWidget->setVerticalAlignment( mTableWidget->selectionVerticalAlignment() );

Expand Down
22 changes: 4 additions & 18 deletions src/gui/tableeditor/qgstableeditorformattingwidget.cpp
Expand Up @@ -25,7 +25,9 @@ QgsTableEditorFormattingWidget::QgsTableEditorFormattingWidget( QWidget *parent
setPanelTitle( tr( "Formatting" ) );

mFormatNumbersCheckBox->setTristate( false );
mTextFormatCheckBox->setTristate( false );

mFontButton->setShowNullFormat( true );
mFontButton->setNoFormatString( tr( "Clear Formatting" ) );

mTextColorButton->setAllowOpacity( true );
mTextColorButton->setColorDialogTitle( tr( "Text Color" ) );
Expand Down Expand Up @@ -72,15 +74,6 @@ QgsTableEditorFormattingWidget::QgsTableEditorFormattingWidget( QWidget *parent
emit numberFormatChanged();
} );

connect( mTextFormatCheckBox, &QCheckBox::stateChanged, this, [ = ]( int state )
{
mFontButton->setEnabled( state == Qt::Checked );
if ( state != Qt::PartiallyChecked )
mTextFormatCheckBox->setTristate( false );
if ( !mBlockSignals )
emit hasTextFormatChanged();
} );

connect( mFontButton, &QgsFontButton::changed, this, [ = ]
{
if ( !mBlockSignals )
Expand Down Expand Up @@ -154,11 +147,6 @@ QgsTextFormat QgsTableEditorFormattingWidget::textFormat() const
return mFontButton->textFormat();
}

bool QgsTableEditorFormattingWidget::textFormatSet() const
{
return mTextFormatCheckBox->checkState() == Qt::Checked;
}

void QgsTableEditorFormattingWidget::setForegroundColor( const QColor &color )
{
mBlockSignals++;
Expand All @@ -182,11 +170,9 @@ void QgsTableEditorFormattingWidget::setNumericFormat( QgsNumericFormat *format,
mBlockSignals--;
}

void QgsTableEditorFormattingWidget::setTextFormat( const QgsTextFormat &format, bool isSet, bool isMixedFormat )
void QgsTableEditorFormattingWidget::setTextFormat( const QgsTextFormat &format )
{
mBlockSignals++;
mTextFormatCheckBox->setTristate( isMixedFormat );
mTextFormatCheckBox->setCheckState( isMixedFormat ? Qt::PartiallyChecked : ( isSet ? Qt::Checked : Qt::Unchecked ) );
mFontButton->setTextFormat( format );
mBlockSignals--;
}
Expand Down
20 changes: 1 addition & 19 deletions src/gui/tableeditor/qgstableeditorformattingwidget.h
Expand Up @@ -61,19 +61,10 @@ class GUI_EXPORT QgsTableEditorFormattingWidget : public QgsPanelWidget, private
* Returns the current text format shown in the widget.
*
* \see setTextFormat()
* \see textFormatSet()
* \since QGIS 3.16
*/
QgsTextFormat textFormat() const;

/**
* Returns TRUE if a text format is set in the widget.
*
* \see textFormat()
* \since QGIS 3.16
*/
bool textFormatSet() const;

/**
* Sets the cell foreground \a color to show in the widget.
*
Expand Down Expand Up @@ -102,12 +93,10 @@ class GUI_EXPORT QgsTableEditorFormattingWidget : public QgsPanelWidget, private
/**
* Sets the text \a format to show in the widget.
*
* if \a isMixedFormat is TRUE then the widget will be set to indicate a "mixed format" setting.
*
* \see textFormat()
* \since QGIS 3.16
*/
void setTextFormat( const QgsTextFormat &format, bool isSet, bool isMixedFormat );
void setTextFormat( const QgsTextFormat &format );

/**
* Sets the row \a height to show in the widget, or 0 for automatic height.
Expand Down Expand Up @@ -173,13 +162,6 @@ class GUI_EXPORT QgsTableEditorFormattingWidget : public QgsPanelWidget, private
*/
void textFormatChanged();

/**
* Emitted whenever the apply text format option in the widget is changed.
*
* \since QGIS 3.16
*/
void hasTextFormatChanged();

/**
* Emitted whenever the row \a height shown in the widget is changed.
*/
Expand Down

0 comments on commit 761f594

Please sign in to comment.