37 connect( mSetContentsButton, &QPushButton::clicked,
this, &QgsLayoutManualTableWidget::setTableContents );
38 connect( mMarginSpinBox,
static_cast < void ( QDoubleSpinBox::* )(
double )
> ( &QDoubleSpinBox::valueChanged ),
this, &QgsLayoutManualTableWidget::mMarginSpinBox_valueChanged );
39 connect( mGridStrokeWidthSpinBox,
static_cast < void ( QDoubleSpinBox::* )(
double )
> ( &QDoubleSpinBox::valueChanged ),
this, &QgsLayoutManualTableWidget::mGridStrokeWidthSpinBox_valueChanged );
41 connect( mBackgroundColorButton, &
QgsColorButton::colorChanged,
this, &QgsLayoutManualTableWidget::mBackgroundColorButton_colorChanged );
42 connect( mDrawHorizontalGrid, &QCheckBox::toggled,
this, &QgsLayoutManualTableWidget::mDrawHorizontalGrid_toggled );
43 connect( mDrawVerticalGrid, &QCheckBox::toggled,
this, &QgsLayoutManualTableWidget::mDrawVerticalGrid_toggled );
44 connect( mShowGridGroupCheckBox, &QgsCollapsibleGroupBoxBasic::toggled,
this, &QgsLayoutManualTableWidget::mShowGridGroupCheckBox_toggled );
45 connect( mHeaderHAlignmentComboBox,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, &QgsLayoutManualTableWidget::mHeaderHAlignmentComboBox_currentIndexChanged );
46 connect( mHeaderModeComboBox,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, &QgsLayoutManualTableWidget::mHeaderModeComboBox_currentIndexChanged );
47 connect( mAddFramePushButton, &QPushButton::clicked,
this, &QgsLayoutManualTableWidget::mAddFramePushButton_clicked );
48 connect( mResizeModeComboBox,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, &QgsLayoutManualTableWidget::mResizeModeComboBox_currentIndexChanged );
49 connect( mDrawEmptyCheckBox, &QCheckBox::toggled,
this, &QgsLayoutManualTableWidget::mDrawEmptyCheckBox_toggled );
50 connect( mEmptyFrameCheckBox, &QCheckBox::toggled,
this, &QgsLayoutManualTableWidget::mEmptyFrameCheckBox_toggled );
51 connect( mHideEmptyBgCheckBox, &QCheckBox::toggled,
this, &QgsLayoutManualTableWidget::mHideEmptyBgCheckBox_toggled );
52 connect( mWrapBehaviorComboBox,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, &QgsLayoutManualTableWidget::mWrapBehaviorComboBox_currentIndexChanged );
53 connect( mAdvancedCustomizationButton, &QPushButton::clicked,
this, &QgsLayoutManualTableWidget::mAdvancedCustomizationButton_clicked );
59 mContentFontToolButton->registerExpressionContextGenerator(
this );
60 mHeaderFontToolButton->registerExpressionContextGenerator(
this );
62 blockAllSignals(
true );
80 mGridColorButton->setColorDialogTitle( tr(
"Select Grid Color" ) );
81 mGridColorButton->setAllowOpacity(
true );
82 mGridColorButton->setContext( QStringLiteral(
"composer" ) );
83 mGridColorButton->setDefaultColor( Qt::black );
84 mBackgroundColorButton->setColorDialogTitle( tr(
"Select Background Color" ) );
85 mBackgroundColorButton->setAllowOpacity(
true );
86 mBackgroundColorButton->setContext( QStringLiteral(
"composer" ) );
87 mBackgroundColorButton->setShowNoColor(
true );
88 mBackgroundColorButton->setNoColorString( tr(
"No Background" ) );
102 mainLayout->addWidget( mItemPropertiesWidget );
105 connect( mHeaderFontToolButton, &
QgsFontButton::changed,
this, &QgsLayoutManualTableWidget::headerFontChanged );
106 connect( mContentFontToolButton, &
QgsFontButton::changed,
this, &QgsLayoutManualTableWidget::contentFontChanged );
111 if ( mItemPropertiesWidget )
121 context = mFrame->createExpressionContext();
123 context = mTable->createExpressionContext();
125 std::unique_ptr< QgsExpressionContextScope > cellScope = std::make_unique< QgsExpressionContextScope >();
126 cellScope->setVariable( QStringLiteral(
"row_number" ), 1,
true );
127 cellScope->setVariable( QStringLiteral(
"column_number" ), 1,
true );
131 QStringLiteral(
"column_number" )} );
155 mEditorDialog->close();
158 mTable = qobject_cast< QgsLayoutItemManualTable * >( multiFrame );
160 mItemPropertiesWidget->
setItem( frame );
172void QgsLayoutManualTableWidget::setTableContents()
182 mEditorDialog->show();
183 mEditorDialog->raise();
184 mEditorDialog->setWindowState( windowState() & ~Qt::WindowMinimized );
185 mEditorDialog->activateWindow();
190 if (
QgsLayout *layout = mTable->layout() )
192 mEditorDialog->setLayer( layout->reportContext().layer() );
194 mEditorDialog->registerExpressionContextGenerator( mTable );
195 connect(
this, &QWidget::destroyed, mEditorDialog, &QMainWindow::close );
197 mEditorDialog->setIncludeTableHeader( mTable->includeTableHeader() );
198 mEditorDialog->setTableContents( mTable->tableContents() );
201 const QList< double > rowHeights = mTable->rowHeights();
202 for (
const double height : rowHeights )
204 mEditorDialog->setTableRowHeight( row, height );
208 const QList< double > columnWidths = mTable->columnWidths();
209 QVariantList headers;
210 headers.reserve( columnWidths.size() );
211 for (
const double width : columnWidths )
213 mEditorDialog->setTableColumnWidth( col, width );
214 headers << ( col < mTable->headers().count() ? mTable->headers().value( col ).heading() : QVariant() );
217 mEditorDialog->setTableHeaders( headers );
223 mTable->beginCommand( tr(
"Change Table Contents" ) );
224 mTable->setTableContents( mEditorDialog->tableContents() );
226 const QVariantList headerText = mEditorDialog->tableHeaders();
227 if ( mEditorDialog->includeTableHeader() )
230 for (
const QVariant &h : headerText )
234 mTable->setHeaders( headers );
237 const int rowCount = mTable->tableContents().size();
238 QList< double > rowHeights;
239 rowHeights.reserve( rowCount );
240 for (
int row = 0; row < rowCount; ++row )
242 rowHeights << mEditorDialog->tableRowHeight( row );
244 mTable->setRowHeights( rowHeights );
246 if ( !mTable->tableContents().empty() )
248 const int columnCount = mTable->tableContents().at( 0 ).size();
249 QList< double > columnWidths;
250 columnWidths.reserve( columnCount );
251 for (
int col = 0; col < columnCount; ++col )
253 columnWidths << mEditorDialog->tableColumnWidth( col );
255 mTable->setColumnWidths( columnWidths );
258 mTable->endCommand();
266 mTable->beginCommand( tr(
"Change Table Header" ) );
267 mTable->setIncludeTableHeader( included );
268 mTable->endCommand();
271 mEditorDialog->show();
275void QgsLayoutManualTableWidget::mMarginSpinBox_valueChanged(
double d )
283 mTable->setCellMargin( d );
284 mTable->endCommand();
287void QgsLayoutManualTableWidget::contentFontChanged()
294 mTable->beginCommand( tr(
"Change Table Font" ) );
295 mTable->setContentTextFormat( mContentFontToolButton->textFormat() );
296 mTable->endCommand();
299void QgsLayoutManualTableWidget::mGridStrokeWidthSpinBox_valueChanged(
double d )
307 mTable->setGridStrokeWidth( d );
308 mTable->endCommand();
311void QgsLayoutManualTableWidget::mGridColorButton_colorChanged(
const QColor &newColor )
319 mTable->setGridColor( newColor );
320 mTable->endCommand();
323void QgsLayoutManualTableWidget::mDrawHorizontalGrid_toggled(
bool state )
330 mTable->beginCommand( tr(
"Toggle Table Grid" ) );
331 mTable->setHorizontalGrid( state );
332 mTable->endCommand();
335void QgsLayoutManualTableWidget::mDrawVerticalGrid_toggled(
bool state )
342 mTable->beginCommand( tr(
"Toggled Table Grid" ) );
343 mTable->setVerticalGrid( state );
344 mTable->endCommand();
347void QgsLayoutManualTableWidget::mShowGridGroupCheckBox_toggled(
bool state )
354 mTable->beginCommand( tr(
"Toggle Table Grid" ) );
355 mTable->setShowGrid( state );
356 mTable->endCommand();
359void QgsLayoutManualTableWidget::mHeaderHAlignmentComboBox_currentIndexChanged(
int )
366 mTable->beginCommand( tr(
"Change Table Alignment" ) );
368 mTable->endCommand();
371void QgsLayoutManualTableWidget::mHeaderModeComboBox_currentIndexChanged(
int )
378 mTable->beginCommand( tr(
"Change Table Header Mode" ) );
380 mTable->endCommand();
383void QgsLayoutManualTableWidget::mBackgroundColorButton_colorChanged(
const QColor &newColor )
391 mTable->setBackgroundColor( newColor );
392 mTable->endCommand();
395void QgsLayoutManualTableWidget::headerFontChanged()
400 mTable->beginCommand( tr(
"Change Table Font" ) );
401 mTable->setHeaderTextFormat( mHeaderFontToolButton->textFormat() );
402 mTable->endCommand();
405void QgsLayoutManualTableWidget::updateGuiElements()
407 if ( !mTable || !mFrame )
412 blockAllSignals(
true );
414 mMarginSpinBox->setValue( mTable->cellMargin() );
415 mGridStrokeWidthSpinBox->setValue( mTable->gridStrokeWidth() );
416 mGridColorButton->setColor( mTable->gridColor() );
417 mDrawHorizontalGrid->setChecked( mTable->horizontalGrid() );
418 mDrawVerticalGrid->setChecked( mTable->verticalGrid() );
419 if ( mTable->showGrid() )
421 mShowGridGroupCheckBox->setChecked(
true );
425 mShowGridGroupCheckBox->setChecked(
false );
427 mBackgroundColorButton->setColor( mTable->backgroundColor() );
429 mHeaderFontToolButton->setTextFormat( mTable->headerTextFormat() );
430 mContentFontToolButton->setTextFormat( mTable->contentTextFormat() );
432 mDrawEmptyCheckBox->setChecked( mTable->showEmptyRows() );
433 mWrapBehaviorComboBox->setCurrentIndex( mWrapBehaviorComboBox->findData( mTable->wrapBehavior() ) );
435 mResizeModeComboBox->setCurrentIndex( mResizeModeComboBox->findData( mTable->resizeMode() ) );
438 mHeaderHAlignmentComboBox->setCurrentIndex( mHeaderHAlignmentComboBox->findData( mTable->headerHAlignment() ) );
439 mHeaderModeComboBox->setCurrentIndex( mHeaderModeComboBox->findData( mTable->headerMode() ) );
441 mEmptyFrameCheckBox->setChecked( mFrame->hidePageIfEmpty() );
442 mHideEmptyBgCheckBox->setChecked( mFrame->hideBackgroundIfEmpty() );
444 blockAllSignals(
false );
447void QgsLayoutManualTableWidget::blockAllSignals(
bool b )
449 mMarginSpinBox->blockSignals( b );
450 mGridColorButton->blockSignals( b );
451 mGridStrokeWidthSpinBox->blockSignals( b );
452 mBackgroundColorButton->blockSignals( b );
453 mDrawHorizontalGrid->blockSignals( b );
454 mDrawVerticalGrid->blockSignals( b );
455 mShowGridGroupCheckBox->blockSignals( b );
456 mResizeModeComboBox->blockSignals( b );
457 mEmptyFrameCheckBox->blockSignals( b );
458 mHideEmptyBgCheckBox->blockSignals( b );
459 mDrawEmptyCheckBox->blockSignals( b );
460 mWrapBehaviorComboBox->blockSignals( b );
461 mContentFontToolButton->blockSignals( b );
462 mHeaderHAlignmentComboBox->blockSignals( b );
463 mHeaderModeComboBox->blockSignals( b );
464 mHeaderFontToolButton->blockSignals( b );
467void QgsLayoutManualTableWidget::mEmptyFrameCheckBox_toggled(
bool checked )
474 mFrame->beginCommand( tr(
"Toggle Empty Frame Mode" ) );
475 mFrame->setHidePageIfEmpty( checked );
476 mFrame->endCommand();
479void QgsLayoutManualTableWidget::mHideEmptyBgCheckBox_toggled(
bool checked )
486 mFrame->beginCommand( tr(
"Toggle Background Display" ) );
487 mFrame->setHideBackgroundIfEmpty( checked );
488 mFrame->endCommand();
491void QgsLayoutManualTableWidget::mAddFramePushButton_clicked()
493 if ( !mTable || !mFrame )
499 QPointF pos = mFrame->pos();
501 pos.ry() += mFrame->rect().height() + 10;
503 QgsLayoutFrame *newFrame = mTable->createNewFrame( mFrame, pos, mFrame->rect().size() );
504 mTable->recalculateFrameSizes();
507 if (
QgsLayout *layout = mTable->layout() )
509 layout->setSelectedItem( newFrame );
513void QgsLayoutManualTableWidget::mResizeModeComboBox_currentIndexChanged(
int index )
520 mTable->beginCommand( tr(
"Change Resize Mode" ) );
522 mTable->endCommand();
527void QgsLayoutManualTableWidget::mWrapBehaviorComboBox_currentIndexChanged(
int index )
534 mTable->beginCommand( tr(
"Change Table Wrap Mode" ) );
536 mTable->endCommand();
539void QgsLayoutManualTableWidget::mAdvancedCustomizationButton_clicked()
551void QgsLayoutManualTableWidget::mDrawEmptyCheckBox_toggled(
bool checked )
558 mTable->beginCommand( tr(
"Change Show Empty Rows" ) );
559 mTable->setShowEmptyRows( checked );
560 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.
A layout table subclass that displays manually entered (and formatted) content.
@ 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.
@ 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.