31#include "moc_qgslayoutmanualtablewidget.cpp"
33QPointer<QgsTableEditorDialog> QgsLayoutManualTableWidget::sEditorDialog =
nullptr;
42 connect( mSetContentsButton, &QPushButton::clicked,
this, &QgsLayoutManualTableWidget::setTableContents );
43 connect( mMarginSpinBox,
static_cast<void ( QDoubleSpinBox::* )(
double )
>( &QDoubleSpinBox::valueChanged ),
this, &QgsLayoutManualTableWidget::mMarginSpinBox_valueChanged );
44 connect( mGridStrokeWidthSpinBox,
static_cast<void ( QDoubleSpinBox::* )(
double )
>( &QDoubleSpinBox::valueChanged ),
this, &QgsLayoutManualTableWidget::mGridStrokeWidthSpinBox_valueChanged );
46 connect( mBackgroundColorButton, &
QgsColorButton::colorChanged,
this, &QgsLayoutManualTableWidget::mBackgroundColorButton_colorChanged );
47 connect( mDrawHorizontalGrid, &QCheckBox::toggled,
this, &QgsLayoutManualTableWidget::mDrawHorizontalGrid_toggled );
48 connect( mDrawVerticalGrid, &QCheckBox::toggled,
this, &QgsLayoutManualTableWidget::mDrawVerticalGrid_toggled );
49 connect( mShowGridGroupCheckBox, &QgsCollapsibleGroupBoxBasic::toggled,
this, &QgsLayoutManualTableWidget::mShowGridGroupCheckBox_toggled );
50 connect( mHeaderHAlignmentComboBox,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, &QgsLayoutManualTableWidget::mHeaderHAlignmentComboBox_currentIndexChanged );
51 connect( mHeaderModeComboBox,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, &QgsLayoutManualTableWidget::mHeaderModeComboBox_currentIndexChanged );
52 connect( mAddFramePushButton, &QPushButton::clicked,
this, &QgsLayoutManualTableWidget::mAddFramePushButton_clicked );
53 connect( mResizeModeComboBox,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, &QgsLayoutManualTableWidget::mResizeModeComboBox_currentIndexChanged );
54 connect( mDrawEmptyCheckBox, &QCheckBox::toggled,
this, &QgsLayoutManualTableWidget::mDrawEmptyCheckBox_toggled );
55 connect( mEmptyFrameCheckBox, &QCheckBox::toggled,
this, &QgsLayoutManualTableWidget::mEmptyFrameCheckBox_toggled );
56 connect( mHideEmptyBgCheckBox, &QCheckBox::toggled,
this, &QgsLayoutManualTableWidget::mHideEmptyBgCheckBox_toggled );
57 connect( mWrapBehaviorComboBox,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, &QgsLayoutManualTableWidget::mWrapBehaviorComboBox_currentIndexChanged );
58 connect( mAdvancedCustomizationButton, &QPushButton::clicked,
this, &QgsLayoutManualTableWidget::mAdvancedCustomizationButton_clicked );
64 mContentFontToolButton->registerExpressionContextGenerator(
this );
65 mHeaderFontToolButton->registerExpressionContextGenerator(
this );
67 blockAllSignals(
true );
85 mGridColorButton->setColorDialogTitle( tr(
"Select Grid Color" ) );
86 mGridColorButton->setAllowOpacity(
true );
87 mGridColorButton->setContext( QStringLiteral(
"composer" ) );
88 mGridColorButton->setDefaultColor( Qt::black );
89 mBackgroundColorButton->setColorDialogTitle( tr(
"Select Background Color" ) );
90 mBackgroundColorButton->setAllowOpacity(
true );
91 mBackgroundColorButton->setContext( QStringLiteral(
"composer" ) );
92 mBackgroundColorButton->setShowNoColor(
true );
93 mBackgroundColorButton->setNoColorString( tr(
"No Background" ) );
107 mainLayout->addWidget( mItemPropertiesWidget );
110 connect( mHeaderFontToolButton, &
QgsFontButton::changed,
this, &QgsLayoutManualTableWidget::headerFontChanged );
111 connect( mContentFontToolButton, &
QgsFontButton::changed,
this, &QgsLayoutManualTableWidget::contentFontChanged );
116 if ( mItemPropertiesWidget )
117 mItemPropertiesWidget->setMasterLayout( masterLayout );
126 context = mFrame->createExpressionContext();
128 context = mTable->createExpressionContext();
130 auto cellScope = std::make_unique<QgsExpressionContextScope>();
131 cellScope->setVariable( QStringLiteral(
"row_number" ), 1,
true );
132 cellScope->setVariable( QStringLiteral(
"column_number" ), 1,
true );
157 if ( sEditorDialog && sEditorDialog->table() != mTable )
159 sEditorDialog->close();
162 mTable = qobject_cast<QgsLayoutItemManualTable *>( multiFrame );
164 mItemPropertiesWidget->setItem( frame );
187 if ( sEditorDialog->table() == table )
190 sEditorDialog->show();
191 sEditorDialog->raise();
194 sEditorDialog->setWindowState( parent->windowState() & ~Qt::WindowMinimized );
196 sEditorDialog->activateWindow();
200 sEditorDialog->close();
204 sEditorDialog->setTable( table );
206 connect( frame, &QgsLayoutFrame::destroyed, sEditorDialog, &QMainWindow::close );
207 auto updateName = [frame] { sEditorDialog->setWindowTitle( QString(
"%1 - %2 " ).arg( tr(
"Table Designer" ) ).arg( frame->
displayName() ) ); };
212 connect( parent, &QWidget::destroyed, sEditorDialog, &QMainWindow::close );
218 const QVariantList headerText = sEditorDialog->tableHeaders();
219 if ( sEditorDialog->includeTableHeader() )
222 for (
const QVariant &h : headerText )
230 QList<double> rowHeights;
231 rowHeights.reserve( rowCount );
232 for (
int row = 0; row < rowCount; ++row )
234 rowHeights << sEditorDialog->tableRowHeight( row );
240 const int columnCount = table->
tableContents().at( 0 ).size();
241 QList<double> columnWidths;
242 columnWidths.reserve( columnCount );
243 for (
int col = 0; col < columnCount; ++col )
245 columnWidths << sEditorDialog->tableColumnWidth( col );
258 sEditorDialog->show();
261void QgsLayoutManualTableWidget::setTableContents()
266void QgsLayoutManualTableWidget::mMarginSpinBox_valueChanged(
double d )
274 mTable->setCellMargin( d );
275 mTable->endCommand();
278void QgsLayoutManualTableWidget::contentFontChanged()
285 mTable->beginCommand( tr(
"Change Table Font" ) );
286 mTable->setContentTextFormat( mContentFontToolButton->textFormat() );
287 mTable->endCommand();
290void QgsLayoutManualTableWidget::mGridStrokeWidthSpinBox_valueChanged(
double d )
298 mTable->setGridStrokeWidth( d );
299 mTable->endCommand();
302void QgsLayoutManualTableWidget::mGridColorButton_colorChanged(
const QColor &newColor )
310 mTable->setGridColor( newColor );
311 mTable->endCommand();
314void QgsLayoutManualTableWidget::mDrawHorizontalGrid_toggled(
bool state )
321 mTable->beginCommand( tr(
"Toggle Table Grid" ) );
322 mTable->setHorizontalGrid( state );
323 mTable->endCommand();
326void QgsLayoutManualTableWidget::mDrawVerticalGrid_toggled(
bool state )
333 mTable->beginCommand( tr(
"Toggled Table Grid" ) );
334 mTable->setVerticalGrid( state );
335 mTable->endCommand();
338void QgsLayoutManualTableWidget::mShowGridGroupCheckBox_toggled(
bool state )
345 mTable->beginCommand( tr(
"Toggle Table Grid" ) );
346 mTable->setShowGrid( state );
347 mTable->endCommand();
350void QgsLayoutManualTableWidget::mHeaderHAlignmentComboBox_currentIndexChanged(
int )
357 mTable->beginCommand( tr(
"Change Table Alignment" ) );
359 mTable->endCommand();
362void QgsLayoutManualTableWidget::mHeaderModeComboBox_currentIndexChanged(
int )
369 mTable->beginCommand( tr(
"Change Table Header Mode" ) );
371 mTable->endCommand();
374void QgsLayoutManualTableWidget::mBackgroundColorButton_colorChanged(
const QColor &newColor )
382 mTable->setBackgroundColor( newColor );
383 mTable->endCommand();
386void QgsLayoutManualTableWidget::headerFontChanged()
391 mTable->beginCommand( tr(
"Change Table Font" ) );
392 mTable->setHeaderTextFormat( mHeaderFontToolButton->textFormat() );
393 mTable->endCommand();
396void QgsLayoutManualTableWidget::updateGuiElements()
398 if ( !mTable || !mFrame )
403 blockAllSignals(
true );
405 mMarginSpinBox->setValue( mTable->cellMargin() );
406 mGridStrokeWidthSpinBox->setValue( mTable->gridStrokeWidth() );
407 mGridColorButton->setColor( mTable->gridColor() );
408 mDrawHorizontalGrid->setChecked( mTable->horizontalGrid() );
409 mDrawVerticalGrid->setChecked( mTable->verticalGrid() );
410 if ( mTable->showGrid() )
412 mShowGridGroupCheckBox->setChecked(
true );
416 mShowGridGroupCheckBox->setChecked(
false );
418 mBackgroundColorButton->setColor( mTable->backgroundColor() );
420 mHeaderFontToolButton->setTextFormat( mTable->headerTextFormat() );
421 mContentFontToolButton->setTextFormat( mTable->contentTextFormat() );
423 mDrawEmptyCheckBox->setChecked( mTable->showEmptyRows() );
424 mWrapBehaviorComboBox->setCurrentIndex( mWrapBehaviorComboBox->findData( mTable->wrapBehavior() ) );
426 mResizeModeComboBox->setCurrentIndex( mResizeModeComboBox->findData( mTable->resizeMode() ) );
429 mHeaderHAlignmentComboBox->setCurrentIndex( mHeaderHAlignmentComboBox->findData( mTable->headerHAlignment() ) );
430 mHeaderModeComboBox->setCurrentIndex( mHeaderModeComboBox->findData( mTable->headerMode() ) );
432 mEmptyFrameCheckBox->setChecked( mFrame->hidePageIfEmpty() );
433 mHideEmptyBgCheckBox->setChecked( mFrame->hideBackgroundIfEmpty() );
435 blockAllSignals(
false );
438void QgsLayoutManualTableWidget::blockAllSignals(
bool b )
440 mMarginSpinBox->blockSignals( b );
441 mGridColorButton->blockSignals( b );
442 mGridStrokeWidthSpinBox->blockSignals( b );
443 mBackgroundColorButton->blockSignals( b );
444 mDrawHorizontalGrid->blockSignals( b );
445 mDrawVerticalGrid->blockSignals( b );
446 mShowGridGroupCheckBox->blockSignals( b );
447 mResizeModeComboBox->blockSignals( b );
448 mEmptyFrameCheckBox->blockSignals( b );
449 mHideEmptyBgCheckBox->blockSignals( b );
450 mDrawEmptyCheckBox->blockSignals( b );
451 mWrapBehaviorComboBox->blockSignals( b );
452 mContentFontToolButton->blockSignals( b );
453 mHeaderHAlignmentComboBox->blockSignals( b );
454 mHeaderModeComboBox->blockSignals( b );
455 mHeaderFontToolButton->blockSignals( b );
458void QgsLayoutManualTableWidget::mEmptyFrameCheckBox_toggled(
bool checked )
465 mFrame->beginCommand( tr(
"Toggle Empty Frame Mode" ) );
466 mFrame->setHidePageIfEmpty( checked );
467 mFrame->endCommand();
470void QgsLayoutManualTableWidget::mHideEmptyBgCheckBox_toggled(
bool checked )
477 mFrame->beginCommand( tr(
"Toggle Background Display" ) );
478 mFrame->setHideBackgroundIfEmpty( checked );
479 mFrame->endCommand();
482void QgsLayoutManualTableWidget::mAddFramePushButton_clicked()
484 if ( !mTable || !mFrame )
490 QPointF pos = mFrame->pos();
492 pos.ry() += mFrame->rect().height() + 10;
494 QgsLayoutFrame *newFrame = mTable->createNewFrame( mFrame, pos, mFrame->rect().size() );
495 mTable->recalculateFrameSizes();
498 if ( QgsLayout *layout = mTable->layout() )
500 layout->setSelectedItem( newFrame );
504void QgsLayoutManualTableWidget::mResizeModeComboBox_currentIndexChanged(
int index )
511 mTable->beginCommand( tr(
"Change Resize Mode" ) );
513 mTable->endCommand();
518void QgsLayoutManualTableWidget::mWrapBehaviorComboBox_currentIndexChanged(
int index )
525 mTable->beginCommand( tr(
"Change Table Wrap Mode" ) );
527 mTable->endCommand();
530void QgsLayoutManualTableWidget::mAdvancedCustomizationButton_clicked()
537 QgsLayoutTableBackgroundColorsDialog d( mTable,
this );
542void QgsLayoutManualTableWidget::mDrawEmptyCheckBox_toggled(
bool checked )
549 mTable->beginCommand( tr(
"Change Show Empty Rows" ) );
550 mTable->setShowEmptyRows( checked );
551 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.