19#include "moc_qgslayoutmanualtablewidget.cpp" 
   32QPointer<QgsTableEditorDialog> QgsLayoutManualTableWidget::sEditorDialog = 
nullptr;
 
   41  connect( mSetContentsButton, &QPushButton::clicked, 
this, &QgsLayoutManualTableWidget::setTableContents );
 
   42  connect( mMarginSpinBox, 
static_cast<void ( QDoubleSpinBox::* )( 
double )
>( &QDoubleSpinBox::valueChanged ), 
this, &QgsLayoutManualTableWidget::mMarginSpinBox_valueChanged );
 
   43  connect( mGridStrokeWidthSpinBox, 
static_cast<void ( QDoubleSpinBox::* )( 
double )
>( &QDoubleSpinBox::valueChanged ), 
this, &QgsLayoutManualTableWidget::mGridStrokeWidthSpinBox_valueChanged );
 
   45  connect( mBackgroundColorButton, &
QgsColorButton::colorChanged, 
this, &QgsLayoutManualTableWidget::mBackgroundColorButton_colorChanged );
 
   46  connect( mDrawHorizontalGrid, &QCheckBox::toggled, 
this, &QgsLayoutManualTableWidget::mDrawHorizontalGrid_toggled );
 
   47  connect( mDrawVerticalGrid, &QCheckBox::toggled, 
this, &QgsLayoutManualTableWidget::mDrawVerticalGrid_toggled );
 
   48  connect( mShowGridGroupCheckBox, &QgsCollapsibleGroupBoxBasic::toggled, 
this, &QgsLayoutManualTableWidget::mShowGridGroupCheckBox_toggled );
 
   49  connect( mHeaderHAlignmentComboBox, 
static_cast<void ( QComboBox::* )( 
int )
>( &QComboBox::currentIndexChanged ), 
this, &QgsLayoutManualTableWidget::mHeaderHAlignmentComboBox_currentIndexChanged );
 
   50  connect( mHeaderModeComboBox, 
static_cast<void ( QComboBox::* )( 
int )
>( &QComboBox::currentIndexChanged ), 
this, &QgsLayoutManualTableWidget::mHeaderModeComboBox_currentIndexChanged );
 
   51  connect( mAddFramePushButton, &QPushButton::clicked, 
this, &QgsLayoutManualTableWidget::mAddFramePushButton_clicked );
 
   52  connect( mResizeModeComboBox, 
static_cast<void ( QComboBox::* )( 
int )
>( &QComboBox::currentIndexChanged ), 
this, &QgsLayoutManualTableWidget::mResizeModeComboBox_currentIndexChanged );
 
   53  connect( mDrawEmptyCheckBox, &QCheckBox::toggled, 
this, &QgsLayoutManualTableWidget::mDrawEmptyCheckBox_toggled );
 
   54  connect( mEmptyFrameCheckBox, &QCheckBox::toggled, 
this, &QgsLayoutManualTableWidget::mEmptyFrameCheckBox_toggled );
 
   55  connect( mHideEmptyBgCheckBox, &QCheckBox::toggled, 
this, &QgsLayoutManualTableWidget::mHideEmptyBgCheckBox_toggled );
 
   56  connect( mWrapBehaviorComboBox, 
static_cast<void ( QComboBox::* )( 
int )
>( &QComboBox::currentIndexChanged ), 
this, &QgsLayoutManualTableWidget::mWrapBehaviorComboBox_currentIndexChanged );
 
   57  connect( mAdvancedCustomizationButton, &QPushButton::clicked, 
this, &QgsLayoutManualTableWidget::mAdvancedCustomizationButton_clicked );
 
   63  mContentFontToolButton->registerExpressionContextGenerator( 
this );
 
   64  mHeaderFontToolButton->registerExpressionContextGenerator( 
this );
 
   66  blockAllSignals( 
true );
 
   84  mGridColorButton->setColorDialogTitle( tr( 
"Select Grid Color" ) );
 
   85  mGridColorButton->setAllowOpacity( 
true );
 
   86  mGridColorButton->setContext( QStringLiteral( 
"composer" ) );
 
   87  mGridColorButton->setDefaultColor( Qt::black );
 
   88  mBackgroundColorButton->setColorDialogTitle( tr( 
"Select Background Color" ) );
 
   89  mBackgroundColorButton->setAllowOpacity( 
true );
 
   90  mBackgroundColorButton->setContext( QStringLiteral( 
"composer" ) );
 
   91  mBackgroundColorButton->setShowNoColor( 
true );
 
   92  mBackgroundColorButton->setNoColorString( tr( 
"No Background" ) );
 
  106    mainLayout->addWidget( mItemPropertiesWidget );
 
  109  connect( mHeaderFontToolButton, &
QgsFontButton::changed, 
this, &QgsLayoutManualTableWidget::headerFontChanged );
 
  110  connect( mContentFontToolButton, &
QgsFontButton::changed, 
this, &QgsLayoutManualTableWidget::contentFontChanged );
 
 
  115  if ( mItemPropertiesWidget )
 
 
  125    context = mFrame->createExpressionContext();
 
  127    context = mTable->createExpressionContext();
 
  129  auto cellScope = std::make_unique<QgsExpressionContextScope>();
 
  130  cellScope->setVariable( QStringLiteral( 
"row_number" ), 1, 
true );
 
  131  cellScope->setVariable( QStringLiteral( 
"column_number" ), 1, 
true );
 
 
  156  if ( sEditorDialog && sEditorDialog->table() != mTable )
 
  158    sEditorDialog->close();
 
  161  mTable = qobject_cast<QgsLayoutItemManualTable *>( multiFrame );
 
  163  mItemPropertiesWidget->
setItem( frame );
 
 
  186    if ( sEditorDialog->table() == table )
 
  189      sEditorDialog->show();
 
  190      sEditorDialog->raise();
 
  193        sEditorDialog->setWindowState( parent->windowState() & ~Qt::WindowMinimized );
 
  195      sEditorDialog->activateWindow();
 
  199    sEditorDialog->close();
 
  203  sEditorDialog->setTable( table );
 
  205  connect( frame, &QgsLayoutFrame::destroyed, sEditorDialog, &QMainWindow::close );
 
  206  auto updateName = [frame] { sEditorDialog->setWindowTitle( QString( 
"%1 - %2 " ).arg( tr( 
"Table Designer" ) ).arg( frame->
displayName() ) ); };
 
  211    connect( parent, &QWidget::destroyed, sEditorDialog, &QMainWindow::close );
 
  217    const QVariantList headerText = sEditorDialog->tableHeaders();
 
  218    if ( sEditorDialog->includeTableHeader() )
 
  221      for ( 
const QVariant &h : headerText )
 
  229    QList<double> rowHeights;
 
  230    rowHeights.reserve( rowCount );
 
  231    for ( 
int row = 0; row < rowCount; ++row )
 
  233      rowHeights << sEditorDialog->tableRowHeight( row );
 
  239      const int columnCount = table->
tableContents().at( 0 ).size();
 
  240      QList<double> columnWidths;
 
  241      columnWidths.reserve( columnCount );
 
  242      for ( 
int col = 0; col < columnCount; ++col )
 
  244        columnWidths << sEditorDialog->tableColumnWidth( col );
 
  257  sEditorDialog->show();
 
 
  260void QgsLayoutManualTableWidget::setTableContents()
 
  265void QgsLayoutManualTableWidget::mMarginSpinBox_valueChanged( 
double d )
 
  273  mTable->setCellMargin( d );
 
  274  mTable->endCommand();
 
  277void QgsLayoutManualTableWidget::contentFontChanged()
 
  284  mTable->beginCommand( tr( 
"Change Table Font" ) );
 
  285  mTable->setContentTextFormat( mContentFontToolButton->textFormat() );
 
  286  mTable->endCommand();
 
  289void QgsLayoutManualTableWidget::mGridStrokeWidthSpinBox_valueChanged( 
double d )
 
  297  mTable->setGridStrokeWidth( d );
 
  298  mTable->endCommand();
 
  301void QgsLayoutManualTableWidget::mGridColorButton_colorChanged( 
const QColor &newColor )
 
  309  mTable->setGridColor( newColor );
 
  310  mTable->endCommand();
 
  313void QgsLayoutManualTableWidget::mDrawHorizontalGrid_toggled( 
bool state )
 
  320  mTable->beginCommand( tr( 
"Toggle Table Grid" ) );
 
  321  mTable->setHorizontalGrid( state );
 
  322  mTable->endCommand();
 
  325void QgsLayoutManualTableWidget::mDrawVerticalGrid_toggled( 
bool state )
 
  332  mTable->beginCommand( tr( 
"Toggled Table Grid" ) );
 
  333  mTable->setVerticalGrid( state );
 
  334  mTable->endCommand();
 
  337void QgsLayoutManualTableWidget::mShowGridGroupCheckBox_toggled( 
bool state )
 
  344  mTable->beginCommand( tr( 
"Toggle Table Grid" ) );
 
  345  mTable->setShowGrid( state );
 
  346  mTable->endCommand();
 
  349void QgsLayoutManualTableWidget::mHeaderHAlignmentComboBox_currentIndexChanged( 
int )
 
  356  mTable->beginCommand( tr( 
"Change Table Alignment" ) );
 
  358  mTable->endCommand();
 
  361void QgsLayoutManualTableWidget::mHeaderModeComboBox_currentIndexChanged( 
int )
 
  368  mTable->beginCommand( tr( 
"Change Table Header Mode" ) );
 
  370  mTable->endCommand();
 
  373void QgsLayoutManualTableWidget::mBackgroundColorButton_colorChanged( 
const QColor &newColor )
 
  381  mTable->setBackgroundColor( newColor );
 
  382  mTable->endCommand();
 
  385void QgsLayoutManualTableWidget::headerFontChanged()
 
  390  mTable->beginCommand( tr( 
"Change Table Font" ) );
 
  391  mTable->setHeaderTextFormat( mHeaderFontToolButton->textFormat() );
 
  392  mTable->endCommand();
 
  395void QgsLayoutManualTableWidget::updateGuiElements()
 
  397  if ( !mTable || !mFrame )
 
  402  blockAllSignals( 
true );
 
  404  mMarginSpinBox->setValue( mTable->cellMargin() );
 
  405  mGridStrokeWidthSpinBox->setValue( mTable->gridStrokeWidth() );
 
  406  mGridColorButton->setColor( mTable->gridColor() );
 
  407  mDrawHorizontalGrid->setChecked( mTable->horizontalGrid() );
 
  408  mDrawVerticalGrid->setChecked( mTable->verticalGrid() );
 
  409  if ( mTable->showGrid() )
 
  411    mShowGridGroupCheckBox->setChecked( 
true );
 
  415    mShowGridGroupCheckBox->setChecked( 
false );
 
  417  mBackgroundColorButton->setColor( mTable->backgroundColor() );
 
  419  mHeaderFontToolButton->setTextFormat( mTable->headerTextFormat() );
 
  420  mContentFontToolButton->setTextFormat( mTable->contentTextFormat() );
 
  422  mDrawEmptyCheckBox->setChecked( mTable->showEmptyRows() );
 
  423  mWrapBehaviorComboBox->setCurrentIndex( mWrapBehaviorComboBox->findData( mTable->wrapBehavior() ) );
 
  425  mResizeModeComboBox->setCurrentIndex( mResizeModeComboBox->findData( mTable->resizeMode() ) );
 
  428  mHeaderHAlignmentComboBox->setCurrentIndex( mHeaderHAlignmentComboBox->findData( mTable->headerHAlignment() ) );
 
  429  mHeaderModeComboBox->setCurrentIndex( mHeaderModeComboBox->findData( mTable->headerMode() ) );
 
  431  mEmptyFrameCheckBox->setChecked( mFrame->hidePageIfEmpty() );
 
  432  mHideEmptyBgCheckBox->setChecked( mFrame->hideBackgroundIfEmpty() );
 
  434  blockAllSignals( 
false );
 
  437void QgsLayoutManualTableWidget::blockAllSignals( 
bool b )
 
  439  mMarginSpinBox->blockSignals( b );
 
  440  mGridColorButton->blockSignals( b );
 
  441  mGridStrokeWidthSpinBox->blockSignals( b );
 
  442  mBackgroundColorButton->blockSignals( b );
 
  443  mDrawHorizontalGrid->blockSignals( b );
 
  444  mDrawVerticalGrid->blockSignals( b );
 
  445  mShowGridGroupCheckBox->blockSignals( b );
 
  446  mResizeModeComboBox->blockSignals( b );
 
  447  mEmptyFrameCheckBox->blockSignals( b );
 
  448  mHideEmptyBgCheckBox->blockSignals( b );
 
  449  mDrawEmptyCheckBox->blockSignals( b );
 
  450  mWrapBehaviorComboBox->blockSignals( b );
 
  451  mContentFontToolButton->blockSignals( b );
 
  452  mHeaderHAlignmentComboBox->blockSignals( b );
 
  453  mHeaderModeComboBox->blockSignals( b );
 
  454  mHeaderFontToolButton->blockSignals( b );
 
  457void QgsLayoutManualTableWidget::mEmptyFrameCheckBox_toggled( 
bool checked )
 
  464  mFrame->beginCommand( tr( 
"Toggle Empty Frame Mode" ) );
 
  465  mFrame->setHidePageIfEmpty( checked );
 
  466  mFrame->endCommand();
 
  469void QgsLayoutManualTableWidget::mHideEmptyBgCheckBox_toggled( 
bool checked )
 
  476  mFrame->beginCommand( tr( 
"Toggle Background Display" ) );
 
  477  mFrame->setHideBackgroundIfEmpty( checked );
 
  478  mFrame->endCommand();
 
  481void QgsLayoutManualTableWidget::mAddFramePushButton_clicked()
 
  483  if ( !mTable || !mFrame )
 
  489  QPointF pos = mFrame->pos();
 
  491  pos.ry() += mFrame->rect().height() + 10;
 
  493  QgsLayoutFrame *newFrame = mTable->createNewFrame( mFrame, pos, mFrame->rect().size() );
 
  494  mTable->recalculateFrameSizes();
 
  497  if ( 
QgsLayout *layout = mTable->layout() )
 
  499    layout->setSelectedItem( newFrame );
 
  503void QgsLayoutManualTableWidget::mResizeModeComboBox_currentIndexChanged( 
int index )
 
  510  mTable->beginCommand( tr( 
"Change Resize Mode" ) );
 
  512  mTable->endCommand();
 
  517void QgsLayoutManualTableWidget::mWrapBehaviorComboBox_currentIndexChanged( 
int index )
 
  524  mTable->beginCommand( tr( 
"Change Table Wrap Mode" ) );
 
  526  mTable->endCommand();
 
  529void QgsLayoutManualTableWidget::mAdvancedCustomizationButton_clicked()
 
  541void QgsLayoutManualTableWidget::mDrawEmptyCheckBox_toggled( 
bool checked )
 
  548  mTable->beginCommand( tr( 
"Change Show Empty Rows" ) );
 
  549  mTable->setShowEmptyRows( checked );
 
  550  mTable->endCommand();
 
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
 
void appendScope(QgsExpressionContextScope *scope)
Appends a scope to the end of the context.
 
void setHighlightedVariables(const QStringList &variableNames)
Sets the list of variable names within the context intended to be highlighted to the user.
 
Base class for frame items, which form a layout multiframe item.
 
QgsLayoutMultiFrame * multiFrame() const
Returns the parent multiframe for the frame.
 
QString displayName() const override
Gets item display name.
 
A layout table subclass that displays manually entered (and formatted) content.
 
void setColumnWidths(const QList< double > &widths)
Sets the list of column widths (in millimeters) to use when rendering the table.
 
void setIncludeTableHeader(bool included)
Sets whether the table includes a header row.
 
void setHeaders(const QgsLayoutTableColumns &headers)
Replaces the headers in the table with a specified list of QgsLayoutTableColumns.
 
void setTableContents(const QgsTableContents &contents)
Sets the contents of the table.
 
void setRowHeights(const QList< double > &heights)
Sets the list of row heights (in millimeters) to use when rendering the table.
 
QgsTableContents tableContents() const
Returns the contents of the table.
 
@ LayoutManualTable
Manual (fixed) table.
 
Base class for graphical items within a QgsLayout.
 
Abstract base class for layout items with the ability to distribute the content to several frames (Qg...
 
virtual int type() const =0
Returns unique multiframe type id.
 
ResizeMode
Specifies the behavior for creating new frames to fit the multiframe's content.
 
@ UseExistingFrames
Don't automatically create new frames, just use existing frames.
 
@ ExtendToNextPage
Creates new full page frames on the following page(s) until the entire multiframe content is visible.
 
void endCommand()
Completes the current item command and push it onto the layout's undo stack.
 
void beginCommand(const QString &commandText, UndoCommand command=UndoNone)
Starts new undo command for this item.
 
@ UndoTableBackgroundColor
Table background color.
 
@ UndoTableGridStrokeWidth
Table grid stroke width.
 
@ UndoTableGridColor
Table grid color.
 
@ UndoTableMargin
Table margins.
 
void changed()
Emitted when the object's properties change.
 
A dialog for customization of the cell background colors for a QgsLayoutTable.
 
Stores properties of a column for a QgsLayoutTable.
 
HeaderMode
Controls where headers are shown in the table.
 
@ FirstFrame
Header shown on first frame only.
 
@ AllFrames
Headers shown on all frames.
 
@ NoHeaders
No headers shown for table.
 
WrapBehavior
Controls how long strings in the table are handled.
 
@ WrapText
Text which doesn't fit inside the cell is wrapped. Note that this only applies to text in columns wit...
 
@ TruncateText
Text which doesn't fit inside the cell is truncated.
 
HeaderHAlignment
Controls how headers are horizontally aligned in a table.
 
@ HeaderRight
Align headers right.
 
@ HeaderLeft
Align headers left.
 
@ HeaderCenter
Align headers to center.
 
@ FollowColumn
Header uses the same alignment as the column.
 
Base class for layouts, which can contain items such as maps, labels, scalebars, etc.
 
Interface for master layout type objects, such as print layouts and reports.
 
A reusable window for editing simple spreadsheet-style tables.
 
void includeHeaderChanged(bool included)
Emitted whenever the "include table header" setting is changed.
 
void tableChanged()
Emitted whenever the table contents are changed.
 
QVector< QgsLayoutTableColumn > QgsLayoutTableColumns
List of column definitions for a QgsLayoutTable.