33#include "moc_qgslayoutmanualtablewidget.cpp"
35using namespace Qt::StringLiterals;
37QPointer<QgsTableEditorDialog> QgsLayoutManualTableWidget::sEditorDialog =
nullptr;
46 connect( mSetContentsButton, &QPushButton::clicked,
this, &QgsLayoutManualTableWidget::setTableContents );
47 connect( mMarginSpinBox,
static_cast<void ( QDoubleSpinBox::* )(
double )
>( &QDoubleSpinBox::valueChanged ),
this, &QgsLayoutManualTableWidget::mMarginSpinBox_valueChanged );
48 connect( mGridStrokeWidthSpinBox,
static_cast<void ( QDoubleSpinBox::* )(
double )
>( &QDoubleSpinBox::valueChanged ),
this, &QgsLayoutManualTableWidget::mGridStrokeWidthSpinBox_valueChanged );
50 connect( mBackgroundColorButton, &
QgsColorButton::colorChanged,
this, &QgsLayoutManualTableWidget::mBackgroundColorButton_colorChanged );
51 connect( mDrawHorizontalGrid, &QCheckBox::toggled,
this, &QgsLayoutManualTableWidget::mDrawHorizontalGrid_toggled );
52 connect( mDrawVerticalGrid, &QCheckBox::toggled,
this, &QgsLayoutManualTableWidget::mDrawVerticalGrid_toggled );
53 connect( mShowGridGroupCheckBox, &QgsCollapsibleGroupBoxBasic::toggled,
this, &QgsLayoutManualTableWidget::mShowGridGroupCheckBox_toggled );
54 connect( mHeaderHAlignmentComboBox,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, &QgsLayoutManualTableWidget::mHeaderHAlignmentComboBox_currentIndexChanged );
55 connect( mHeaderModeComboBox,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, &QgsLayoutManualTableWidget::mHeaderModeComboBox_currentIndexChanged );
56 connect( mAddFramePushButton, &QPushButton::clicked,
this, &QgsLayoutManualTableWidget::mAddFramePushButton_clicked );
57 connect( mResizeModeComboBox,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, &QgsLayoutManualTableWidget::mResizeModeComboBox_currentIndexChanged );
58 connect( mDrawEmptyCheckBox, &QCheckBox::toggled,
this, &QgsLayoutManualTableWidget::mDrawEmptyCheckBox_toggled );
59 connect( mEmptyFrameCheckBox, &QCheckBox::toggled,
this, &QgsLayoutManualTableWidget::mEmptyFrameCheckBox_toggled );
60 connect( mHideEmptyBgCheckBox, &QCheckBox::toggled,
this, &QgsLayoutManualTableWidget::mHideEmptyBgCheckBox_toggled );
61 connect( mWrapBehaviorComboBox,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, &QgsLayoutManualTableWidget::mWrapBehaviorComboBox_currentIndexChanged );
62 connect( mAdvancedCustomizationButton, &QPushButton::clicked,
this, &QgsLayoutManualTableWidget::mAdvancedCustomizationButton_clicked );
68 mContentFontToolButton->registerExpressionContextGenerator(
this );
69 mHeaderFontToolButton->registerExpressionContextGenerator(
this );
71 blockAllSignals(
true );
89 mGridColorButton->setColorDialogTitle( tr(
"Select Grid Color" ) );
90 mGridColorButton->setAllowOpacity(
true );
91 mGridColorButton->setContext( u
"composer"_s );
92 mGridColorButton->setDefaultColor( Qt::black );
93 mBackgroundColorButton->setColorDialogTitle( tr(
"Select Background Color" ) );
94 mBackgroundColorButton->setAllowOpacity(
true );
95 mBackgroundColorButton->setContext( u
"composer"_s );
96 mBackgroundColorButton->setShowNoColor(
true );
97 mBackgroundColorButton->setNoColorString( tr(
"No Background" ) );
111 mainLayout->addWidget( mItemPropertiesWidget );
114 connect( mHeaderFontToolButton, &
QgsFontButton::changed,
this, &QgsLayoutManualTableWidget::headerFontChanged );
115 connect( mContentFontToolButton, &
QgsFontButton::changed,
this, &QgsLayoutManualTableWidget::contentFontChanged );
120 if ( mItemPropertiesWidget )
121 mItemPropertiesWidget->setMasterLayout( masterLayout );
130 context = mFrame->createExpressionContext();
132 context = mTable->createExpressionContext();
134 auto cellScope = std::make_unique<QgsExpressionContextScope>();
135 cellScope->setVariable( u
"row_number"_s, 1,
true );
136 cellScope->setVariable( u
"column_number"_s, 1,
true );
161 if ( sEditorDialog && sEditorDialog->table() != mTable )
163 sEditorDialog->close();
166 mTable = qobject_cast<QgsLayoutItemManualTable *>( multiFrame );
168 mItemPropertiesWidget->setItem( frame );
191 if ( sEditorDialog->table() == table )
194 sEditorDialog->show();
195 sEditorDialog->raise();
198 sEditorDialog->setWindowState( parent->windowState() & ~Qt::WindowMinimized );
200 sEditorDialog->activateWindow();
204 sEditorDialog->close();
208 sEditorDialog->setTable( table );
210 connect( frame, &QgsLayoutFrame::destroyed, sEditorDialog, &QMainWindow::close );
211 auto updateName = [frame] { sEditorDialog->setWindowTitle( QString(
"%1 - %2 " ).arg( tr(
"Table Designer" ) ).arg( frame->
displayName() ) ); };
216 connect( parent, &QWidget::destroyed, sEditorDialog, &QMainWindow::close );
222 const QVariantList headerText = sEditorDialog->tableHeaders();
223 if ( sEditorDialog->includeTableHeader() )
226 for (
const QVariant &h : headerText )
234 QList<double> rowHeights;
235 rowHeights.reserve( rowCount );
236 for (
int row = 0; row < rowCount; ++row )
238 rowHeights << sEditorDialog->tableRowHeight( row );
244 const int columnCount = table->
tableContents().at( 0 ).size();
245 QList<double> columnWidths;
246 columnWidths.reserve( columnCount );
247 for (
int col = 0; col < columnCount; ++col )
249 columnWidths << sEditorDialog->tableColumnWidth( col );
262 sEditorDialog->show();
265void QgsLayoutManualTableWidget::setTableContents()
270void QgsLayoutManualTableWidget::mMarginSpinBox_valueChanged(
double d )
278 mTable->setCellMargin( d );
279 mTable->endCommand();
282void QgsLayoutManualTableWidget::contentFontChanged()
289 mTable->beginCommand( tr(
"Change Table Font" ) );
290 mTable->setContentTextFormat( mContentFontToolButton->textFormat() );
291 mTable->endCommand();
294void QgsLayoutManualTableWidget::mGridStrokeWidthSpinBox_valueChanged(
double d )
302 mTable->setGridStrokeWidth( d );
303 mTable->endCommand();
306void QgsLayoutManualTableWidget::mGridColorButton_colorChanged(
const QColor &newColor )
314 mTable->setGridColor( newColor );
315 mTable->endCommand();
318void QgsLayoutManualTableWidget::mDrawHorizontalGrid_toggled(
bool state )
325 mTable->beginCommand( tr(
"Toggle Table Grid" ) );
326 mTable->setHorizontalGrid( state );
327 mTable->endCommand();
330void QgsLayoutManualTableWidget::mDrawVerticalGrid_toggled(
bool state )
337 mTable->beginCommand( tr(
"Toggled Table Grid" ) );
338 mTable->setVerticalGrid( state );
339 mTable->endCommand();
342void QgsLayoutManualTableWidget::mShowGridGroupCheckBox_toggled(
bool state )
349 mTable->beginCommand( tr(
"Toggle Table Grid" ) );
350 mTable->setShowGrid( state );
351 mTable->endCommand();
354void QgsLayoutManualTableWidget::mHeaderHAlignmentComboBox_currentIndexChanged(
int )
361 mTable->beginCommand( tr(
"Change Table Alignment" ) );
363 mTable->endCommand();
366void QgsLayoutManualTableWidget::mHeaderModeComboBox_currentIndexChanged(
int )
373 mTable->beginCommand( tr(
"Change Table Header Mode" ) );
375 mTable->endCommand();
378void QgsLayoutManualTableWidget::mBackgroundColorButton_colorChanged(
const QColor &newColor )
386 mTable->setBackgroundColor( newColor );
387 mTable->endCommand();
390void QgsLayoutManualTableWidget::headerFontChanged()
395 mTable->beginCommand( tr(
"Change Table Font" ) );
396 mTable->setHeaderTextFormat( mHeaderFontToolButton->textFormat() );
397 mTable->endCommand();
400void QgsLayoutManualTableWidget::updateGuiElements()
402 if ( !mTable || !mFrame )
407 blockAllSignals(
true );
409 mMarginSpinBox->setValue( mTable->cellMargin() );
410 mGridStrokeWidthSpinBox->setValue( mTable->gridStrokeWidth() );
411 mGridColorButton->setColor( mTable->gridColor() );
412 mDrawHorizontalGrid->setChecked( mTable->horizontalGrid() );
413 mDrawVerticalGrid->setChecked( mTable->verticalGrid() );
414 if ( mTable->showGrid() )
416 mShowGridGroupCheckBox->setChecked(
true );
420 mShowGridGroupCheckBox->setChecked(
false );
422 mBackgroundColorButton->setColor( mTable->backgroundColor() );
424 mHeaderFontToolButton->setTextFormat( mTable->headerTextFormat() );
425 mContentFontToolButton->setTextFormat( mTable->contentTextFormat() );
427 mDrawEmptyCheckBox->setChecked( mTable->showEmptyRows() );
428 mWrapBehaviorComboBox->setCurrentIndex( mWrapBehaviorComboBox->findData( mTable->wrapBehavior() ) );
430 mResizeModeComboBox->setCurrentIndex( mResizeModeComboBox->findData( mTable->resizeMode() ) );
433 mHeaderHAlignmentComboBox->setCurrentIndex( mHeaderHAlignmentComboBox->findData( mTable->headerHAlignment() ) );
434 mHeaderModeComboBox->setCurrentIndex( mHeaderModeComboBox->findData( mTable->headerMode() ) );
436 mEmptyFrameCheckBox->setChecked( mFrame->hidePageIfEmpty() );
437 mHideEmptyBgCheckBox->setChecked( mFrame->hideBackgroundIfEmpty() );
439 blockAllSignals(
false );
442void QgsLayoutManualTableWidget::blockAllSignals(
bool b )
444 mMarginSpinBox->blockSignals( b );
445 mGridColorButton->blockSignals( b );
446 mGridStrokeWidthSpinBox->blockSignals( b );
447 mBackgroundColorButton->blockSignals( b );
448 mDrawHorizontalGrid->blockSignals( b );
449 mDrawVerticalGrid->blockSignals( b );
450 mShowGridGroupCheckBox->blockSignals( b );
451 mResizeModeComboBox->blockSignals( b );
452 mEmptyFrameCheckBox->blockSignals( b );
453 mHideEmptyBgCheckBox->blockSignals( b );
454 mDrawEmptyCheckBox->blockSignals( b );
455 mWrapBehaviorComboBox->blockSignals( b );
456 mContentFontToolButton->blockSignals( b );
457 mHeaderHAlignmentComboBox->blockSignals( b );
458 mHeaderModeComboBox->blockSignals( b );
459 mHeaderFontToolButton->blockSignals( b );
462void QgsLayoutManualTableWidget::mEmptyFrameCheckBox_toggled(
bool checked )
469 mFrame->beginCommand( tr(
"Toggle Empty Frame Mode" ) );
470 mFrame->setHidePageIfEmpty( checked );
471 mFrame->endCommand();
474void QgsLayoutManualTableWidget::mHideEmptyBgCheckBox_toggled(
bool checked )
481 mFrame->beginCommand( tr(
"Toggle Background Display" ) );
482 mFrame->setHideBackgroundIfEmpty( checked );
483 mFrame->endCommand();
486void QgsLayoutManualTableWidget::mAddFramePushButton_clicked()
488 if ( !mTable || !mFrame )
494 QPointF pos = mFrame->pos();
496 pos.ry() += mFrame->rect().height() + 10;
498 QgsLayoutFrame *newFrame = mTable->createNewFrame( mFrame, pos, mFrame->rect().size() );
499 mTable->recalculateFrameSizes();
502 if ( QgsLayout *layout = mTable->layout() )
504 layout->setSelectedItem( newFrame );
508void QgsLayoutManualTableWidget::mResizeModeComboBox_currentIndexChanged(
int index )
515 mTable->beginCommand( tr(
"Change Resize Mode" ) );
517 mTable->endCommand();
522void QgsLayoutManualTableWidget::mWrapBehaviorComboBox_currentIndexChanged(
int index )
529 mTable->beginCommand( tr(
"Change Table Wrap Mode" ) );
531 mTable->endCommand();
534void QgsLayoutManualTableWidget::mAdvancedCustomizationButton_clicked()
541 QgsLayoutTableBackgroundColorsDialog d( mTable,
this );
546void QgsLayoutManualTableWidget::mDrawEmptyCheckBox_toggled(
bool checked )
553 mTable->beginCommand( tr(
"Change Show Empty Rows" ) );
554 mTable->setShowEmptyRows( checked );
555 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.
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.
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.