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" ) );
98 mBackgroundColorButton->setOpaqueColorString( tr(
"Opaque Background" ) );
112 mainLayout->addWidget( mItemPropertiesWidget );
115 connect( mHeaderFontToolButton, &
QgsFontButton::changed,
this, &QgsLayoutManualTableWidget::headerFontChanged );
116 connect( mContentFontToolButton, &
QgsFontButton::changed,
this, &QgsLayoutManualTableWidget::contentFontChanged );
121 if ( mItemPropertiesWidget )
122 mItemPropertiesWidget->setMasterLayout( masterLayout );
131 context = mFrame->createExpressionContext();
133 context = mTable->createExpressionContext();
135 auto cellScope = std::make_unique<QgsExpressionContextScope>();
136 cellScope->setVariable( u
"row_number"_s, 1,
true );
137 cellScope->setVariable( u
"column_number"_s, 1,
true );
162 if ( sEditorDialog && sEditorDialog->table() != mTable )
164 sEditorDialog->close();
167 mTable = qobject_cast<QgsLayoutItemManualTable *>( multiFrame );
169 mItemPropertiesWidget->setItem( frame );
192 if ( sEditorDialog->table() == table )
195 sEditorDialog->show();
196 sEditorDialog->raise();
199 sEditorDialog->setWindowState( parent->windowState() & ~Qt::WindowMinimized );
201 sEditorDialog->activateWindow();
205 sEditorDialog->close();
209 sEditorDialog->setTable( table );
211 connect( frame, &QgsLayoutFrame::destroyed, sEditorDialog, &QMainWindow::close );
212 auto updateName = [frame] { sEditorDialog->setWindowTitle( QString(
"%1 - %2 " ).arg( tr(
"Table Designer" ) ).arg( frame->
displayName() ) ); };
217 connect( parent, &QWidget::destroyed, sEditorDialog, &QMainWindow::close );
223 const QVariantList headerText = sEditorDialog->tableHeaders();
224 if ( sEditorDialog->includeTableHeader() )
227 for (
const QVariant &h : headerText )
235 QList<double> rowHeights;
236 rowHeights.reserve( rowCount );
237 for (
int row = 0; row < rowCount; ++row )
239 rowHeights << sEditorDialog->tableRowHeight( row );
245 const int columnCount = table->
tableContents().at( 0 ).size();
246 QList<double> columnWidths;
247 columnWidths.reserve( columnCount );
248 for (
int col = 0; col < columnCount; ++col )
250 columnWidths << sEditorDialog->tableColumnWidth( col );
263 sEditorDialog->show();
266void QgsLayoutManualTableWidget::setTableContents()
271void QgsLayoutManualTableWidget::mMarginSpinBox_valueChanged(
double d )
279 mTable->setCellMargin( d );
280 mTable->endCommand();
283void QgsLayoutManualTableWidget::contentFontChanged()
290 mTable->beginCommand( tr(
"Change Table Font" ) );
291 mTable->setContentTextFormat( mContentFontToolButton->textFormat() );
292 mTable->endCommand();
295void QgsLayoutManualTableWidget::mGridStrokeWidthSpinBox_valueChanged(
double d )
303 mTable->setGridStrokeWidth( d );
304 mTable->endCommand();
307void QgsLayoutManualTableWidget::mGridColorButton_colorChanged(
const QColor &newColor )
315 mTable->setGridColor( newColor );
316 mTable->endCommand();
319void QgsLayoutManualTableWidget::mDrawHorizontalGrid_toggled(
bool state )
326 mTable->beginCommand( tr(
"Toggle Table Grid" ) );
327 mTable->setHorizontalGrid( state );
328 mTable->endCommand();
331void QgsLayoutManualTableWidget::mDrawVerticalGrid_toggled(
bool state )
338 mTable->beginCommand( tr(
"Toggled Table Grid" ) );
339 mTable->setVerticalGrid( state );
340 mTable->endCommand();
343void QgsLayoutManualTableWidget::mShowGridGroupCheckBox_toggled(
bool state )
350 mTable->beginCommand( tr(
"Toggle Table Grid" ) );
351 mTable->setShowGrid( state );
352 mTable->endCommand();
355void QgsLayoutManualTableWidget::mHeaderHAlignmentComboBox_currentIndexChanged(
int )
362 mTable->beginCommand( tr(
"Change Table Alignment" ) );
364 mTable->endCommand();
367void QgsLayoutManualTableWidget::mHeaderModeComboBox_currentIndexChanged(
int )
374 mTable->beginCommand( tr(
"Change Table Header Mode" ) );
376 mTable->endCommand();
379void QgsLayoutManualTableWidget::mBackgroundColorButton_colorChanged(
const QColor &newColor )
387 mTable->setBackgroundColor( newColor );
388 mTable->endCommand();
391void QgsLayoutManualTableWidget::headerFontChanged()
396 mTable->beginCommand( tr(
"Change Table Font" ) );
397 mTable->setHeaderTextFormat( mHeaderFontToolButton->textFormat() );
398 mTable->endCommand();
401void QgsLayoutManualTableWidget::updateGuiElements()
403 if ( !mTable || !mFrame )
408 blockAllSignals(
true );
410 mMarginSpinBox->setValue( mTable->cellMargin() );
411 mGridStrokeWidthSpinBox->setValue( mTable->gridStrokeWidth() );
412 mGridColorButton->setColor( mTable->gridColor() );
413 mDrawHorizontalGrid->setChecked( mTable->horizontalGrid() );
414 mDrawVerticalGrid->setChecked( mTable->verticalGrid() );
415 if ( mTable->showGrid() )
417 mShowGridGroupCheckBox->setChecked(
true );
421 mShowGridGroupCheckBox->setChecked(
false );
423 mBackgroundColorButton->setColor( mTable->backgroundColor() );
425 mHeaderFontToolButton->setTextFormat( mTable->headerTextFormat() );
426 mContentFontToolButton->setTextFormat( mTable->contentTextFormat() );
428 mDrawEmptyCheckBox->setChecked( mTable->showEmptyRows() );
429 mWrapBehaviorComboBox->setCurrentIndex( mWrapBehaviorComboBox->findData( mTable->wrapBehavior() ) );
431 mResizeModeComboBox->setCurrentIndex( mResizeModeComboBox->findData( mTable->resizeMode() ) );
434 mHeaderHAlignmentComboBox->setCurrentIndex( mHeaderHAlignmentComboBox->findData( mTable->headerHAlignment() ) );
435 mHeaderModeComboBox->setCurrentIndex( mHeaderModeComboBox->findData( mTable->headerMode() ) );
437 mEmptyFrameCheckBox->setChecked( mFrame->hidePageIfEmpty() );
438 mHideEmptyBgCheckBox->setChecked( mFrame->hideBackgroundIfEmpty() );
440 blockAllSignals(
false );
443void QgsLayoutManualTableWidget::blockAllSignals(
bool b )
445 mMarginSpinBox->blockSignals( b );
446 mGridColorButton->blockSignals( b );
447 mGridStrokeWidthSpinBox->blockSignals( b );
448 mBackgroundColorButton->blockSignals( b );
449 mDrawHorizontalGrid->blockSignals( b );
450 mDrawVerticalGrid->blockSignals( b );
451 mShowGridGroupCheckBox->blockSignals( b );
452 mResizeModeComboBox->blockSignals( b );
453 mEmptyFrameCheckBox->blockSignals( b );
454 mHideEmptyBgCheckBox->blockSignals( b );
455 mDrawEmptyCheckBox->blockSignals( b );
456 mWrapBehaviorComboBox->blockSignals( b );
457 mContentFontToolButton->blockSignals( b );
458 mHeaderHAlignmentComboBox->blockSignals( b );
459 mHeaderModeComboBox->blockSignals( b );
460 mHeaderFontToolButton->blockSignals( b );
463void QgsLayoutManualTableWidget::mEmptyFrameCheckBox_toggled(
bool checked )
470 mFrame->beginCommand( tr(
"Toggle Empty Frame Mode" ) );
471 mFrame->setHidePageIfEmpty( checked );
472 mFrame->endCommand();
475void QgsLayoutManualTableWidget::mHideEmptyBgCheckBox_toggled(
bool checked )
482 mFrame->beginCommand( tr(
"Toggle Background Display" ) );
483 mFrame->setHideBackgroundIfEmpty( checked );
484 mFrame->endCommand();
487void QgsLayoutManualTableWidget::mAddFramePushButton_clicked()
489 if ( !mTable || !mFrame )
495 QPointF pos = mFrame->pos();
497 pos.ry() += mFrame->rect().height() + 10;
499 QgsLayoutFrame *newFrame = mTable->createNewFrame( mFrame, pos, mFrame->rect().size() );
500 mTable->recalculateFrameSizes();
503 if ( QgsLayout *layout = mTable->layout() )
505 layout->setSelectedItem( newFrame );
509void QgsLayoutManualTableWidget::mResizeModeComboBox_currentIndexChanged(
int index )
516 mTable->beginCommand( tr(
"Change Resize Mode" ) );
518 mTable->endCommand();
523void QgsLayoutManualTableWidget::mWrapBehaviorComboBox_currentIndexChanged(
int index )
530 mTable->beginCommand( tr(
"Change Table Wrap Mode" ) );
532 mTable->endCommand();
535void QgsLayoutManualTableWidget::mAdvancedCustomizationButton_clicked()
542 QgsLayoutTableBackgroundColorsDialog d( mTable,
this );
547void QgsLayoutManualTableWidget::mDrawEmptyCheckBox_toggled(
bool checked )
554 mTable->beginCommand( tr(
"Change Show Empty Rows" ) );
555 mTable->setShowEmptyRows( checked );
556 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.