19#include "moc_qgslayoutmanualtablewidget.cpp"
38 connect( mSetContentsButton, &QPushButton::clicked,
this, &QgsLayoutManualTableWidget::setTableContents );
39 connect( mMarginSpinBox,
static_cast < void ( QDoubleSpinBox::* )(
double )
> ( &QDoubleSpinBox::valueChanged ),
this, &QgsLayoutManualTableWidget::mMarginSpinBox_valueChanged );
40 connect( mGridStrokeWidthSpinBox,
static_cast < void ( QDoubleSpinBox::* )(
double )
> ( &QDoubleSpinBox::valueChanged ),
this, &QgsLayoutManualTableWidget::mGridStrokeWidthSpinBox_valueChanged );
42 connect( mBackgroundColorButton, &
QgsColorButton::colorChanged,
this, &QgsLayoutManualTableWidget::mBackgroundColorButton_colorChanged );
43 connect( mDrawHorizontalGrid, &QCheckBox::toggled,
this, &QgsLayoutManualTableWidget::mDrawHorizontalGrid_toggled );
44 connect( mDrawVerticalGrid, &QCheckBox::toggled,
this, &QgsLayoutManualTableWidget::mDrawVerticalGrid_toggled );
45 connect( mShowGridGroupCheckBox, &QgsCollapsibleGroupBoxBasic::toggled,
this, &QgsLayoutManualTableWidget::mShowGridGroupCheckBox_toggled );
46 connect( mHeaderHAlignmentComboBox,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, &QgsLayoutManualTableWidget::mHeaderHAlignmentComboBox_currentIndexChanged );
47 connect( mHeaderModeComboBox,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, &QgsLayoutManualTableWidget::mHeaderModeComboBox_currentIndexChanged );
48 connect( mAddFramePushButton, &QPushButton::clicked,
this, &QgsLayoutManualTableWidget::mAddFramePushButton_clicked );
49 connect( mResizeModeComboBox,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, &QgsLayoutManualTableWidget::mResizeModeComboBox_currentIndexChanged );
50 connect( mDrawEmptyCheckBox, &QCheckBox::toggled,
this, &QgsLayoutManualTableWidget::mDrawEmptyCheckBox_toggled );
51 connect( mEmptyFrameCheckBox, &QCheckBox::toggled,
this, &QgsLayoutManualTableWidget::mEmptyFrameCheckBox_toggled );
52 connect( mHideEmptyBgCheckBox, &QCheckBox::toggled,
this, &QgsLayoutManualTableWidget::mHideEmptyBgCheckBox_toggled );
53 connect( mWrapBehaviorComboBox,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, &QgsLayoutManualTableWidget::mWrapBehaviorComboBox_currentIndexChanged );
54 connect( mAdvancedCustomizationButton, &QPushButton::clicked,
this, &QgsLayoutManualTableWidget::mAdvancedCustomizationButton_clicked );
60 mContentFontToolButton->registerExpressionContextGenerator(
this );
61 mHeaderFontToolButton->registerExpressionContextGenerator(
this );
63 blockAllSignals(
true );
81 mGridColorButton->setColorDialogTitle( tr(
"Select Grid Color" ) );
82 mGridColorButton->setAllowOpacity(
true );
83 mGridColorButton->setContext( QStringLiteral(
"composer" ) );
84 mGridColorButton->setDefaultColor( Qt::black );
85 mBackgroundColorButton->setColorDialogTitle( tr(
"Select Background Color" ) );
86 mBackgroundColorButton->setAllowOpacity(
true );
87 mBackgroundColorButton->setContext( QStringLiteral(
"composer" ) );
88 mBackgroundColorButton->setShowNoColor(
true );
89 mBackgroundColorButton->setNoColorString( tr(
"No Background" ) );
103 mainLayout->addWidget( mItemPropertiesWidget );
106 connect( mHeaderFontToolButton, &
QgsFontButton::changed,
this, &QgsLayoutManualTableWidget::headerFontChanged );
107 connect( mContentFontToolButton, &
QgsFontButton::changed,
this, &QgsLayoutManualTableWidget::contentFontChanged );
112 if ( mItemPropertiesWidget )
122 context = mFrame->createExpressionContext();
124 context = mTable->createExpressionContext();
126 std::unique_ptr< QgsExpressionContextScope > cellScope = std::make_unique< QgsExpressionContextScope >();
127 cellScope->setVariable( QStringLiteral(
"row_number" ), 1,
true );
128 cellScope->setVariable( QStringLiteral(
"column_number" ), 1,
true );
132 QStringLiteral(
"column_number" )} );
156 mEditorDialog->close();
159 mTable = qobject_cast< QgsLayoutItemManualTable * >( multiFrame );
161 mItemPropertiesWidget->
setItem( frame );
173void QgsLayoutManualTableWidget::setTableContents()
183 mEditorDialog->show();
184 mEditorDialog->raise();
185 mEditorDialog->setWindowState( windowState() & ~Qt::WindowMinimized );
186 mEditorDialog->activateWindow();
191 if (
QgsLayout *layout = mTable->layout() )
193 mEditorDialog->setLayer( layout->reportContext().layer() );
195 mEditorDialog->registerExpressionContextGenerator( mTable );
196 connect(
this, &QWidget::destroyed, mEditorDialog, &QMainWindow::close );
198 mEditorDialog->setIncludeTableHeader( mTable->includeTableHeader() );
199 mEditorDialog->setTableContents( mTable->tableContents() );
202 const QList< double > rowHeights = mTable->rowHeights();
203 for (
const double height : rowHeights )
205 mEditorDialog->setTableRowHeight( row, height );
209 const QList< double > columnWidths = mTable->columnWidths();
210 QVariantList headers;
211 headers.reserve( columnWidths.size() );
212 for (
const double width : columnWidths )
214 mEditorDialog->setTableColumnWidth( col, width );
215 headers << ( col < mTable->headers().count() ? mTable->headers().value( col ).heading() : QVariant() );
218 mEditorDialog->setTableHeaders( headers );
224 mTable->beginCommand( tr(
"Change Table Contents" ) );
225 mTable->setTableContents( mEditorDialog->tableContents() );
227 const QVariantList headerText = mEditorDialog->tableHeaders();
228 if ( mEditorDialog->includeTableHeader() )
231 for (
const QVariant &h : headerText )
235 mTable->setHeaders( headers );
238 const int rowCount = mTable->tableContents().size();
239 QList< double > rowHeights;
240 rowHeights.reserve( rowCount );
241 for (
int row = 0; row < rowCount; ++row )
243 rowHeights << mEditorDialog->tableRowHeight( row );
245 mTable->setRowHeights( rowHeights );
247 if ( !mTable->tableContents().empty() )
249 const int columnCount = mTable->tableContents().at( 0 ).size();
250 QList< double > columnWidths;
251 columnWidths.reserve( columnCount );
252 for (
int col = 0; col < columnCount; ++col )
254 columnWidths << mEditorDialog->tableColumnWidth( col );
256 mTable->setColumnWidths( columnWidths );
259 mTable->endCommand();
267 mTable->beginCommand( tr(
"Change Table Header" ) );
268 mTable->setIncludeTableHeader( included );
269 mTable->endCommand();
272 mEditorDialog->show();
276void QgsLayoutManualTableWidget::mMarginSpinBox_valueChanged(
double d )
284 mTable->setCellMargin( d );
285 mTable->endCommand();
288void QgsLayoutManualTableWidget::contentFontChanged()
295 mTable->beginCommand( tr(
"Change Table Font" ) );
296 mTable->setContentTextFormat( mContentFontToolButton->textFormat() );
297 mTable->endCommand();
300void QgsLayoutManualTableWidget::mGridStrokeWidthSpinBox_valueChanged(
double d )
308 mTable->setGridStrokeWidth( d );
309 mTable->endCommand();
312void QgsLayoutManualTableWidget::mGridColorButton_colorChanged(
const QColor &newColor )
320 mTable->setGridColor( newColor );
321 mTable->endCommand();
324void QgsLayoutManualTableWidget::mDrawHorizontalGrid_toggled(
bool state )
331 mTable->beginCommand( tr(
"Toggle Table Grid" ) );
332 mTable->setHorizontalGrid( state );
333 mTable->endCommand();
336void QgsLayoutManualTableWidget::mDrawVerticalGrid_toggled(
bool state )
343 mTable->beginCommand( tr(
"Toggled Table Grid" ) );
344 mTable->setVerticalGrid( state );
345 mTable->endCommand();
348void QgsLayoutManualTableWidget::mShowGridGroupCheckBox_toggled(
bool state )
355 mTable->beginCommand( tr(
"Toggle Table Grid" ) );
356 mTable->setShowGrid( state );
357 mTable->endCommand();
360void QgsLayoutManualTableWidget::mHeaderHAlignmentComboBox_currentIndexChanged(
int )
367 mTable->beginCommand( tr(
"Change Table Alignment" ) );
369 mTable->endCommand();
372void QgsLayoutManualTableWidget::mHeaderModeComboBox_currentIndexChanged(
int )
379 mTable->beginCommand( tr(
"Change Table Header Mode" ) );
381 mTable->endCommand();
384void QgsLayoutManualTableWidget::mBackgroundColorButton_colorChanged(
const QColor &newColor )
392 mTable->setBackgroundColor( newColor );
393 mTable->endCommand();
396void QgsLayoutManualTableWidget::headerFontChanged()
401 mTable->beginCommand( tr(
"Change Table Font" ) );
402 mTable->setHeaderTextFormat( mHeaderFontToolButton->textFormat() );
403 mTable->endCommand();
406void QgsLayoutManualTableWidget::updateGuiElements()
408 if ( !mTable || !mFrame )
413 blockAllSignals(
true );
415 mMarginSpinBox->setValue( mTable->cellMargin() );
416 mGridStrokeWidthSpinBox->setValue( mTable->gridStrokeWidth() );
417 mGridColorButton->setColor( mTable->gridColor() );
418 mDrawHorizontalGrid->setChecked( mTable->horizontalGrid() );
419 mDrawVerticalGrid->setChecked( mTable->verticalGrid() );
420 if ( mTable->showGrid() )
422 mShowGridGroupCheckBox->setChecked(
true );
426 mShowGridGroupCheckBox->setChecked(
false );
428 mBackgroundColorButton->setColor( mTable->backgroundColor() );
430 mHeaderFontToolButton->setTextFormat( mTable->headerTextFormat() );
431 mContentFontToolButton->setTextFormat( mTable->contentTextFormat() );
433 mDrawEmptyCheckBox->setChecked( mTable->showEmptyRows() );
434 mWrapBehaviorComboBox->setCurrentIndex( mWrapBehaviorComboBox->findData( mTable->wrapBehavior() ) );
436 mResizeModeComboBox->setCurrentIndex( mResizeModeComboBox->findData( mTable->resizeMode() ) );
439 mHeaderHAlignmentComboBox->setCurrentIndex( mHeaderHAlignmentComboBox->findData( mTable->headerHAlignment() ) );
440 mHeaderModeComboBox->setCurrentIndex( mHeaderModeComboBox->findData( mTable->headerMode() ) );
442 mEmptyFrameCheckBox->setChecked( mFrame->hidePageIfEmpty() );
443 mHideEmptyBgCheckBox->setChecked( mFrame->hideBackgroundIfEmpty() );
445 blockAllSignals(
false );
448void QgsLayoutManualTableWidget::blockAllSignals(
bool b )
450 mMarginSpinBox->blockSignals( b );
451 mGridColorButton->blockSignals( b );
452 mGridStrokeWidthSpinBox->blockSignals( b );
453 mBackgroundColorButton->blockSignals( b );
454 mDrawHorizontalGrid->blockSignals( b );
455 mDrawVerticalGrid->blockSignals( b );
456 mShowGridGroupCheckBox->blockSignals( b );
457 mResizeModeComboBox->blockSignals( b );
458 mEmptyFrameCheckBox->blockSignals( b );
459 mHideEmptyBgCheckBox->blockSignals( b );
460 mDrawEmptyCheckBox->blockSignals( b );
461 mWrapBehaviorComboBox->blockSignals( b );
462 mContentFontToolButton->blockSignals( b );
463 mHeaderHAlignmentComboBox->blockSignals( b );
464 mHeaderModeComboBox->blockSignals( b );
465 mHeaderFontToolButton->blockSignals( b );
468void QgsLayoutManualTableWidget::mEmptyFrameCheckBox_toggled(
bool checked )
475 mFrame->beginCommand( tr(
"Toggle Empty Frame Mode" ) );
476 mFrame->setHidePageIfEmpty( checked );
477 mFrame->endCommand();
480void QgsLayoutManualTableWidget::mHideEmptyBgCheckBox_toggled(
bool checked )
487 mFrame->beginCommand( tr(
"Toggle Background Display" ) );
488 mFrame->setHideBackgroundIfEmpty( checked );
489 mFrame->endCommand();
492void QgsLayoutManualTableWidget::mAddFramePushButton_clicked()
494 if ( !mTable || !mFrame )
500 QPointF pos = mFrame->pos();
502 pos.ry() += mFrame->rect().height() + 10;
504 QgsLayoutFrame *newFrame = mTable->createNewFrame( mFrame, pos, mFrame->rect().size() );
505 mTable->recalculateFrameSizes();
508 if (
QgsLayout *layout = mTable->layout() )
510 layout->setSelectedItem( newFrame );
514void QgsLayoutManualTableWidget::mResizeModeComboBox_currentIndexChanged(
int index )
521 mTable->beginCommand( tr(
"Change Resize Mode" ) );
523 mTable->endCommand();
528void QgsLayoutManualTableWidget::mWrapBehaviorComboBox_currentIndexChanged(
int index )
535 mTable->beginCommand( tr(
"Change Table Wrap Mode" ) );
537 mTable->endCommand();
540void QgsLayoutManualTableWidget::mAdvancedCustomizationButton_clicked()
552void QgsLayoutManualTableWidget::mDrawEmptyCheckBox_toggled(
bool checked )
559 mTable->beginCommand( tr(
"Change Show Empty Rows" ) );
560 mTable->setShowEmptyRows( checked );
561 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.