Skip to content
Permalink
Browse files

Improve api and UX for handling cell text formatting in manual tables,

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 761f594cca3f120ef2a58cb8f42573a9531467a9
@@ -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

@@ -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();
@@ -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
@@ -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

@@ -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 );
@@ -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 )
@@ -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;
@@ -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 ) );
@@ -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" ) ) )
{
@@ -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.
*
@@ -213,7 +195,6 @@ class CORE_EXPORT QgsTableCell
QVariant mContent;
QColor mBackgroundColor;
QColor mForegroundColor;
bool mHasTextFormat = false;
QgsTextFormat mTextFormat;
std::unique_ptr< QgsNumericFormat > mFormat;

@@ -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()
@@ -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, [ = ]
{
@@ -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() );

@@ -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" ) );
@@ -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 )
@@ -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++;
@@ -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--;
}
@@ -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.
*
@@ -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.
@@ -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.
*/

0 comments on commit 761f594

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