Skip to content
Permalink
Browse files

Add table row height/column width handling to table editor

  • Loading branch information
nyalldawson committed Jan 13, 2020
1 parent 8de0e76 commit 781712ffbf15a61530055bfb01d12fdac81feef6
@@ -42,6 +42,42 @@ Sets the ``contents`` to show in the editor widget.
Returns the current contents of the editor widget table.

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

double tableRowHeight( int row );
%Docstring
Returns the configured row height for the specified ``row``, or 0 if an automatic height
should be used for the row.

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

double tableColumnWidth( int column );
%Docstring
Returns the configured column width for the specified ``column``, or 0 if an automatic width
should be used for the column.

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

void setTableRowHeight( int row, double height );
%Docstring
Sets the configured row ``height`` for the specified ``row``. Set ``height`` to 0
if an automatic height should be used for the row.

This should be called after a call to setTableContents().

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

void setTableColumnWidth( int column, double width );
%Docstring
Sets the configured column ``width`` for the specified ``column``. Set ``width`` to 0
if an automatic width should be used for the column.

This should be called after a call to setTableContents().

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

signals:
@@ -96,6 +96,54 @@ invalid color will be returned.
.. seealso:: :py:func:`setSelectionBackgroundColor`

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

double selectionRowHeight();
%Docstring
Returns the height (in millimeters) of the rows associated with the current selection,
or 0 if an automatic row height is desired, or -1 if the selection has mixed row heights.

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

double selectionColumnWidth();
%Docstring
Returns the width (in millimeters) of the columns associated with the current selection,
or 0 if an automatic column width is desired.

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

double tableRowHeight( int row );
%Docstring
Returns the configured row height for the specified ``row``, or 0 if an automatic height
should be used for the row.
%End

double tableColumnWidth( int column );
%Docstring
Returns the configured column width for the specified ``column``, or 0 if an automatic width
should be used for the column.
%End

void setTableRowHeight( int row, double height );
%Docstring
Sets the configured row ``height`` for the specified ``row``. Set ``height`` to 0
if an automatic height should be used for the row.

This should be called after a call to setTableContents().

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

void setTableColumnWidth( int column, double width );
%Docstring
Sets the configured column ``width`` for the specified ``column``. Set ``width`` to 0
if an automatic width should be used for the column.

This should be called after a call to setTableContents().

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

public slots:
@@ -179,6 +227,20 @@ Sets the background color for the currently selected cells.
.. seealso:: :py:func:`selectionBackgroundColor`

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

void setSelectionRowHeight( double height );
%Docstring
Sets the row ``height`` (in millimeters) for the currently selected rows, or 0 for automatic row height.

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

void setSelectionColumnWidth( double height );
%Docstring
Sets the column ``width`` (in millimeters) for the currently selected columns, or 0 for automatic column width.

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

protected:
@@ -88,12 +88,16 @@ QgsTableEditorDialog::QgsTableEditorDialog( QWidget *parent )
{
mTableWidget->setSelectionNumericFormat( mFormattingWidget->numericFormat() );
} );
connect( mFormattingWidget, &QgsTableEditorFormattingWidget::rowHeightChanged, mTableWidget, &QgsTableEditorWidget::setSelectionRowHeight );
connect( mFormattingWidget, &QgsTableEditorFormattingWidget::columnWidthChanged, mTableWidget, &QgsTableEditorWidget::setSelectionColumnWidth );

connect( mTableWidget, &QgsTableEditorWidget::activeCellChanged, this, [ = ]
{
mFormattingWidget->setForegroundColor( mTableWidget->selectionForegroundColor() );
mFormattingWidget->setBackgroundColor( mTableWidget->selectionBackgroundColor() );
mFormattingWidget->setNumericFormat( mTableWidget->selectionNumericFormat(), mTableWidget->hasMixedSelectionNumericFormat() );
mFormattingWidget->setRowHeight( mTableWidget->selectionRowHeight() );
mFormattingWidget->setColumnWidth( mTableWidget->selectionColumnWidth() );
} );

addDockWidget( Qt::RightDockWidgetArea, mPropertiesDock );
@@ -123,4 +127,24 @@ QgsTableContents QgsTableEditorDialog::tableContents() const
return mTableWidget->tableContents();
}

double QgsTableEditorDialog::tableRowHeight( int row )
{
return mTableWidget->tableRowHeight( row );
}

double QgsTableEditorDialog::tableColumnWidth( int column )
{
return mTableWidget->tableColumnWidth( column );
}

void QgsTableEditorDialog::setTableRowHeight( int row, double height )
{
mTableWidget->setTableRowHeight( row, height );
}

void QgsTableEditorDialog::setTableColumnWidth( int column, double width )
{
mTableWidget->setTableColumnWidth( column, width );
}

#include "qgstableeditordialog.h"
@@ -61,6 +61,42 @@ class GUI_EXPORT QgsTableEditorDialog : public QMainWindow, private Ui::QgsTable
*/
QgsTableContents tableContents() const;

/**
* Returns the configured row height for the specified \a row, or 0 if an automatic height
* should be used for the row.
*
* \see setTableRowHeight()
*/
double tableRowHeight( int row );

/**
* Returns the configured column width for the specified \a column, or 0 if an automatic width
* should be used for the column.
*
* \see setTableColumnWidth()
*/
double tableColumnWidth( int column );

/**
* Sets the configured row \a height for the specified \a row. Set \a height to 0
* if an automatic height should be used for the row.
*
* This should be called after a call to setTableContents().
*
* \see tableRowHeight()
*/
void setTableRowHeight( int row, double height );

/**
* Sets the configured column \a width for the specified \a column. Set \a width to 0
* if an automatic width should be used for the column.
*
* This should be called after a call to setTableContents().
*
* \see tableColumnWidth()
*/
void setTableColumnWidth( int column, double width );

signals:

/**
@@ -16,6 +16,7 @@
#include "qgstableeditorformattingwidget.h"
#include "qgsnumericformatselectorwidget.h"
#include "qgsnumericformat.h"
#include "qgis.h"

QgsTableEditorFormattingWidget::QgsTableEditorFormattingWidget( QWidget *parent )
: QgsPanelWidget( parent )
@@ -33,6 +34,10 @@ QgsTableEditorFormattingWidget::QgsTableEditorFormattingWidget( QWidget *parent
mBackgroundColorButton->setColorDialogTitle( tr( "Text Color" ) );
mBackgroundColorButton->setDefaultColor( QColor( 255, 255, 255 ) );
mBackgroundColorButton->setShowNull( true );

mRowHeightSpinBox->setClearValue( 0, tr( "Automatic" ) );
mColumnWidthSpinBox->setClearValue( 0, tr( "Automatic" ) );

connect( mTextColorButton, &QgsColorButton::colorChanged, this, [ = ]
{
if ( !mBlockSignals )
@@ -66,6 +71,29 @@ QgsTableEditorFormattingWidget::QgsTableEditorFormattingWidget( QWidget *parent
} );
openPanel( widget );
} );

connect( mRowHeightSpinBox, qgis::overload<double>::of( &QDoubleSpinBox::valueChanged ), this, [ = ]( double height )
{
if ( !mBlockSignals )
{
emit rowHeightChanged( height );

mBlockSignals++;
mRowHeightSpinBox->setClearValue( 0, tr( "Automatic" ) );
mBlockSignals--;
}
} );
connect( mColumnWidthSpinBox, qgis::overload<double>::of( &QDoubleSpinBox::valueChanged ), this, [ = ]( double width )
{
if ( !mBlockSignals )
{
emit columnWidthChanged( width );

mBlockSignals++;
mColumnWidthSpinBox->setClearValue( 0, tr( "Automatic" ) );
mBlockSignals--;
}
} );
}

QgsNumericFormat *QgsTableEditorFormattingWidget::numericFormat()
@@ -78,25 +106,47 @@ QgsNumericFormat *QgsTableEditorFormattingWidget::numericFormat()

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

void QgsTableEditorFormattingWidget::setBackgroundColor( const QColor &color )
{
mBlockSignals = true;
mBlockSignals++;
mBackgroundColorButton->setColor( color );
mBlockSignals = false;
mBlockSignals--;
}

void QgsTableEditorFormattingWidget::setNumericFormat( QgsNumericFormat *format, bool isMixedFormat )
{
mNumericFormat.reset( format ? format->clone() : nullptr );
mBlockSignals = true;
mBlockSignals++;
mFormatNumbersCheckBox->setTristate( isMixedFormat );
mFormatNumbersCheckBox->setCheckState( isMixedFormat ? Qt::PartiallyChecked : ( mNumericFormat.get() ? Qt::Checked : Qt::Unchecked ) );
mBlockSignals = false;
mBlockSignals--;
}

void QgsTableEditorFormattingWidget::setRowHeight( double height )
{
mBlockSignals++;
if ( height < 0 )
mRowHeightSpinBox->setClearValue( 0, tr( "Mixed" ) );
else
mRowHeightSpinBox->setClearValue( 0, tr( "Automatic" ) );
mRowHeightSpinBox->setValue( height < 0 ? 0 : height );
mBlockSignals--;
}

void QgsTableEditorFormattingWidget::setColumnWidth( double width )
{
mBlockSignals++;
if ( width < 0 )
mColumnWidthSpinBox->setClearValue( 0, tr( "Mixed" ) );
else
mColumnWidthSpinBox->setClearValue( 0, tr( "Automatic" ) );
mColumnWidthSpinBox->setValue( width < 0 ? 0 : width );
mBlockSignals--;
}

QgsTableEditorFormattingWidget::~QgsTableEditorFormattingWidget() = default;
@@ -82,6 +82,22 @@ class GUI_EXPORT QgsTableEditorFormattingWidget : public QgsPanelWidget, private
*/
void setNumericFormat( QgsNumericFormat *format, bool isMixedFormat );

/**
* Sets the row \a height to show in the widget, or 0 for automatic height.
*
* \see rowHeightChanged()
* \see setColumnWidth()
*/
void setRowHeight( double height );

/**
* Sets the column \a width to show in the widget, or 0 for automatic width.
*
* \see columnWidthChanged()
* \see setRowHeight()
*/
void setColumnWidth( double width );

signals:

/**
@@ -103,10 +119,20 @@ class GUI_EXPORT QgsTableEditorFormattingWidget : public QgsPanelWidget, private
*/
void numberFormatChanged();

/**
* Emitted whenever the row \a height shown in the widget is changed.
*/
void rowHeightChanged( double height );

/**
* Emitted whenever the column \a width shown in the widget is changed.
*/
void columnWidthChanged( double width );

private:

std::unique_ptr< QgsNumericFormat > mNumericFormat;
bool mBlockSignals = false;
int mBlockSignals = 0;

};

0 comments on commit 781712f

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