35 connect( mSetContentsButton, &QPushButton::clicked,
this, &QgsLayoutManualTableWidget::setTableContents );
36 connect( mMarginSpinBox,
static_cast < void ( QDoubleSpinBox::* )(
double )
> ( &QDoubleSpinBox::valueChanged ),
this, &QgsLayoutManualTableWidget::mMarginSpinBox_valueChanged );
37 connect( mGridStrokeWidthSpinBox,
static_cast < void ( QDoubleSpinBox::* )(
double )
> ( &QDoubleSpinBox::valueChanged ),
this, &QgsLayoutManualTableWidget::mGridStrokeWidthSpinBox_valueChanged );
39 connect( mBackgroundColorButton, &
QgsColorButton::colorChanged,
this, &QgsLayoutManualTableWidget::mBackgroundColorButton_colorChanged );
40 connect( mDrawHorizontalGrid, &QCheckBox::toggled,
this, &QgsLayoutManualTableWidget::mDrawHorizontalGrid_toggled );
41 connect( mDrawVerticalGrid, &QCheckBox::toggled,
this, &QgsLayoutManualTableWidget::mDrawVerticalGrid_toggled );
42 connect( mShowGridGroupCheckBox, &QgsCollapsibleGroupBoxBasic::toggled,
this, &QgsLayoutManualTableWidget::mShowGridGroupCheckBox_toggled );
43 connect( mHeaderHAlignmentComboBox,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, &QgsLayoutManualTableWidget::mHeaderHAlignmentComboBox_currentIndexChanged );
44 connect( mHeaderModeComboBox,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, &QgsLayoutManualTableWidget::mHeaderModeComboBox_currentIndexChanged );
45 connect( mAddFramePushButton, &QPushButton::clicked,
this, &QgsLayoutManualTableWidget::mAddFramePushButton_clicked );
46 connect( mResizeModeComboBox,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, &QgsLayoutManualTableWidget::mResizeModeComboBox_currentIndexChanged );
47 connect( mDrawEmptyCheckBox, &QCheckBox::toggled,
this, &QgsLayoutManualTableWidget::mDrawEmptyCheckBox_toggled );
48 connect( mEmptyFrameCheckBox, &QCheckBox::toggled,
this, &QgsLayoutManualTableWidget::mEmptyFrameCheckBox_toggled );
49 connect( mHideEmptyBgCheckBox, &QCheckBox::toggled,
this, &QgsLayoutManualTableWidget::mHideEmptyBgCheckBox_toggled );
50 connect( mWrapBehaviorComboBox,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, &QgsLayoutManualTableWidget::mWrapBehaviorComboBox_currentIndexChanged );
51 connect( mAdvancedCustomizationButton, &QPushButton::clicked,
this, &QgsLayoutManualTableWidget::mAdvancedCustomizationButton_clicked );
57 mContentFontToolButton->registerExpressionContextGenerator(
this );
58 mHeaderFontToolButton->registerExpressionContextGenerator(
this );
60 blockAllSignals(
true );
78 mGridColorButton->setColorDialogTitle( tr(
"Select Grid Color" ) );
79 mGridColorButton->setAllowOpacity(
true );
80 mGridColorButton->setContext( QStringLiteral(
"composer" ) );
81 mGridColorButton->setDefaultColor( Qt::black );
82 mBackgroundColorButton->setColorDialogTitle( tr(
"Select Background Color" ) );
83 mBackgroundColorButton->setAllowOpacity(
true );
84 mBackgroundColorButton->setContext( QStringLiteral(
"composer" ) );
85 mBackgroundColorButton->setShowNoColor(
true );
86 mBackgroundColorButton->setNoColorString( tr(
"No Background" ) );
100 mainLayout->addWidget( mItemPropertiesWidget );
103 connect( mHeaderFontToolButton, &
QgsFontButton::changed,
this, &QgsLayoutManualTableWidget::headerFontChanged );
104 connect( mContentFontToolButton, &
QgsFontButton::changed,
this, &QgsLayoutManualTableWidget::contentFontChanged );
109 if ( mItemPropertiesWidget )
119 context = mFrame->createExpressionContext();
121 context = mTable->createExpressionContext();
123 std::unique_ptr< QgsExpressionContextScope > cellScope = std::make_unique< QgsExpressionContextScope >();
124 cellScope->setVariable( QStringLiteral(
"row_number" ), 1,
true );
125 cellScope->setVariable( QStringLiteral(
"column_number" ), 1,
true );
129 QStringLiteral(
"column_number" )} );
153 mEditorDialog->close();
156 mTable = qobject_cast< QgsLayoutItemManualTable * >( multiFrame );
158 mItemPropertiesWidget->
setItem( frame );
170 void QgsLayoutManualTableWidget::setTableContents()
180 mEditorDialog->show();
181 mEditorDialog->raise();
182 mEditorDialog->setWindowState( windowState() & ~Qt::WindowMinimized );
183 mEditorDialog->activateWindow();
188 mEditorDialog->registerExpressionContextGenerator( mTable );
189 connect(
this, &QWidget::destroyed, mEditorDialog, &QMainWindow::close );
191 mEditorDialog->setIncludeTableHeader( mTable->includeTableHeader() );
192 mEditorDialog->setTableContents( mTable->tableContents() );
195 const QList< double > rowHeights = mTable->rowHeights();
196 for (
const double height : rowHeights )
198 mEditorDialog->setTableRowHeight( row, height );
202 const QList< double > columnWidths = mTable->columnWidths();
203 QVariantList headers;
204 headers.reserve( columnWidths.size() );
205 for (
const double width : columnWidths )
207 mEditorDialog->setTableColumnWidth( col, width );
208 headers << ( col < mTable->headers().count() ? mTable->headers().value( col ).heading() : QVariant() );
211 mEditorDialog->setTableHeaders( headers );
217 mTable->beginCommand( tr(
"Change Table Contents" ) );
218 mTable->setTableContents( mEditorDialog->tableContents() );
220 const QVariantList headerText = mEditorDialog->tableHeaders();
221 if ( mEditorDialog->includeTableHeader() )
223 QgsLayoutTableColumns headers;
224 for ( const QVariant &h : headerText )
226 headers << QgsLayoutTableColumn( h.toString() );
228 mTable->setHeaders( headers );
231 const int rowCount = mTable->tableContents().size();
232 QList< double > rowHeights;
233 rowHeights.reserve( rowCount );
234 for (
int row = 0; row < rowCount; ++row )
236 rowHeights << mEditorDialog->tableRowHeight( row );
238 mTable->setRowHeights( rowHeights );
240 if ( !mTable->tableContents().empty() )
242 const int columnCount = mTable->tableContents().at( 0 ).size();
243 QList< double > columnWidths;
244 columnWidths.reserve( columnCount );
245 for ( int col = 0; col < columnCount; ++col )
247 columnWidths << mEditorDialog->tableColumnWidth( col );
249 mTable->setColumnWidths( columnWidths );
252 mTable->endCommand();
260 mTable->beginCommand( tr(
"Change Table Header" ) );
261 mTable->setIncludeTableHeader( included );
262 mTable->endCommand();
265 mEditorDialog->show();
269 void QgsLayoutManualTableWidget::mMarginSpinBox_valueChanged(
double d )
277 mTable->setCellMargin( d );
278 mTable->endCommand();
281 void QgsLayoutManualTableWidget::contentFontChanged()
288 mTable->beginCommand( tr(
"Change Table Font" ) );
289 mTable->setContentTextFormat( mContentFontToolButton->textFormat() );
290 mTable->endCommand();
293 void QgsLayoutManualTableWidget::mGridStrokeWidthSpinBox_valueChanged(
double d )
301 mTable->setGridStrokeWidth( d );
302 mTable->endCommand();
305 void QgsLayoutManualTableWidget::mGridColorButton_colorChanged(
const QColor &newColor )
313 mTable->setGridColor( newColor );
314 mTable->endCommand();
317 void QgsLayoutManualTableWidget::mDrawHorizontalGrid_toggled(
bool state )
324 mTable->beginCommand( tr(
"Toggle Table Grid" ) );
325 mTable->setHorizontalGrid( state );
326 mTable->endCommand();
329 void QgsLayoutManualTableWidget::mDrawVerticalGrid_toggled(
bool state )
336 mTable->beginCommand( tr(
"Toggled Table Grid" ) );
337 mTable->setVerticalGrid( state );
338 mTable->endCommand();
341 void QgsLayoutManualTableWidget::mShowGridGroupCheckBox_toggled(
bool state )
348 mTable->beginCommand( tr(
"Toggle Table Grid" ) );
349 mTable->setShowGrid( state );
350 mTable->endCommand();
353 void QgsLayoutManualTableWidget::mHeaderHAlignmentComboBox_currentIndexChanged(
int )
360 mTable->beginCommand( tr(
"Change Table Alignment" ) );
362 mTable->endCommand();
365 void QgsLayoutManualTableWidget::mHeaderModeComboBox_currentIndexChanged(
int )
372 mTable->beginCommand( tr(
"Change Table Header Mode" ) );
374 mTable->endCommand();
377 void QgsLayoutManualTableWidget::mBackgroundColorButton_colorChanged(
const QColor &newColor )
385 mTable->setBackgroundColor( newColor );
386 mTable->endCommand();
389 void QgsLayoutManualTableWidget::headerFontChanged()
394 mTable->beginCommand( tr(
"Change Table Font" ) );
395 mTable->setHeaderTextFormat( mHeaderFontToolButton->textFormat() );
396 mTable->endCommand();
399 void QgsLayoutManualTableWidget::updateGuiElements()
401 if ( !mTable || !mFrame )
406 blockAllSignals(
true );
408 mMarginSpinBox->setValue( mTable->cellMargin() );
409 mGridStrokeWidthSpinBox->setValue( mTable->gridStrokeWidth() );
410 mGridColorButton->setColor( mTable->gridColor() );
411 mDrawHorizontalGrid->setChecked( mTable->horizontalGrid() );
412 mDrawVerticalGrid->setChecked( mTable->verticalGrid() );
413 if ( mTable->showGrid() )
415 mShowGridGroupCheckBox->setChecked(
true );
419 mShowGridGroupCheckBox->setChecked(
false );
421 mBackgroundColorButton->setColor( mTable->backgroundColor() );
423 mHeaderFontToolButton->setTextFormat( mTable->headerTextFormat() );
424 mContentFontToolButton->setTextFormat( mTable->contentTextFormat() );
426 mDrawEmptyCheckBox->setChecked( mTable->showEmptyRows() );
427 mWrapBehaviorComboBox->setCurrentIndex( mWrapBehaviorComboBox->findData( mTable->wrapBehavior() ) );
429 mResizeModeComboBox->setCurrentIndex( mResizeModeComboBox->findData( mTable->resizeMode() ) );
432 mHeaderHAlignmentComboBox->setCurrentIndex( mHeaderHAlignmentComboBox->findData( mTable->headerHAlignment() ) );
433 mHeaderModeComboBox->setCurrentIndex( mHeaderModeComboBox->findData( mTable->headerMode() ) );
435 mEmptyFrameCheckBox->setChecked( mFrame->hidePageIfEmpty() );
436 mHideEmptyBgCheckBox->setChecked( mFrame->hideBackgroundIfEmpty() );
438 blockAllSignals(
false );
441 void QgsLayoutManualTableWidget::blockAllSignals(
bool b )
443 mMarginSpinBox->blockSignals( b );
444 mGridColorButton->blockSignals( b );
445 mGridStrokeWidthSpinBox->blockSignals( b );
446 mBackgroundColorButton->blockSignals( b );
447 mDrawHorizontalGrid->blockSignals( b );
448 mDrawVerticalGrid->blockSignals( b );
449 mShowGridGroupCheckBox->blockSignals( b );
450 mResizeModeComboBox->blockSignals( b );
451 mEmptyFrameCheckBox->blockSignals( b );
452 mHideEmptyBgCheckBox->blockSignals( b );
453 mDrawEmptyCheckBox->blockSignals( b );
454 mWrapBehaviorComboBox->blockSignals( b );
455 mContentFontToolButton->blockSignals( b );
456 mHeaderHAlignmentComboBox->blockSignals( b );
457 mHeaderModeComboBox->blockSignals( b );
458 mHeaderFontToolButton->blockSignals( b );
461 void QgsLayoutManualTableWidget::mEmptyFrameCheckBox_toggled(
bool checked )
468 mFrame->beginCommand( tr(
"Toggle Empty Frame Mode" ) );
469 mFrame->setHidePageIfEmpty( checked );
470 mFrame->endCommand();
473 void QgsLayoutManualTableWidget::mHideEmptyBgCheckBox_toggled(
bool checked )
480 mFrame->beginCommand( tr(
"Toggle Background Display" ) );
481 mFrame->setHideBackgroundIfEmpty( checked );
482 mFrame->endCommand();
485 void QgsLayoutManualTableWidget::mAddFramePushButton_clicked()
487 if ( !mTable || !mFrame )
493 QPointF pos = mFrame->pos();
495 pos.ry() += mFrame->rect().height() + 10;
497 QgsLayoutFrame *newFrame = mTable->createNewFrame( mFrame, pos, mFrame->rect().size() );
498 mTable->recalculateFrameSizes();
501 if (
QgsLayout *layout = mTable->layout() )
503 layout->setSelectedItem( newFrame );
507 void QgsLayoutManualTableWidget::mResizeModeComboBox_currentIndexChanged(
int index )
514 mTable->beginCommand( tr(
"Change Resize Mode" ) );
516 mTable->endCommand();
521 void QgsLayoutManualTableWidget::mWrapBehaviorComboBox_currentIndexChanged(
int index )
528 mTable->beginCommand( tr(
"Change Table Wrap Mode" ) );
530 mTable->endCommand();
533 void QgsLayoutManualTableWidget::mAdvancedCustomizationButton_clicked()
545 void QgsLayoutManualTableWidget::mDrawEmptyCheckBox_toggled(
bool checked )
552 mTable->beginCommand( tr(
"Change Show Empty Rows" ) );
553 mTable->setShowEmptyRows( checked );
554 mTable->endCommand();