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 blockAllSignals(
true );
75 mGridColorButton->setColorDialogTitle( tr(
"Select Grid Color" ) );
76 mGridColorButton->setAllowOpacity(
true );
77 mGridColorButton->setContext( QStringLiteral(
"composer" ) );
78 mGridColorButton->setDefaultColor( Qt::black );
79 mBackgroundColorButton->setColorDialogTitle( tr(
"Select Background Color" ) );
80 mBackgroundColorButton->setAllowOpacity(
true );
81 mBackgroundColorButton->setContext( QStringLiteral(
"composer" ) );
82 mBackgroundColorButton->setShowNoColor(
true );
83 mBackgroundColorButton->setNoColorString( tr(
"No Background" ) );
97 mainLayout->addWidget( mItemPropertiesWidget );
100 connect( mHeaderFontToolButton, &
QgsFontButton::changed,
this, &QgsLayoutManualTableWidget::headerFontChanged );
101 connect( mContentFontToolButton, &
QgsFontButton::changed,
this, &QgsLayoutManualTableWidget::contentFontChanged );
106 if ( mItemPropertiesWidget )
129 mEditorDialog->close();
132 mTable = qobject_cast< QgsLayoutItemManualTable * >( multiFrame );
134 mItemPropertiesWidget->
setItem( frame );
146 void QgsLayoutManualTableWidget::setTableContents()
156 mEditorDialog->show();
157 mEditorDialog->raise();
158 mEditorDialog->setWindowState( windowState() & ~Qt::WindowMinimized );
159 mEditorDialog->activateWindow();
163 mEditorDialog =
new QgsTableEditorDialog(
this );
164 mEditorDialog->registerExpressionContextGenerator( mTable );
165 connect(
this, &QWidget::destroyed, mEditorDialog, &QMainWindow::close );
167 mEditorDialog->setIncludeTableHeader( mTable->includeTableHeader() );
168 mEditorDialog->setTableContents( mTable->tableContents() );
171 const QList< double > rowHeights = mTable->rowHeights();
172 for (
double height : rowHeights )
174 mEditorDialog->setTableRowHeight( row, height );
178 const QList< double > columnWidths = mTable->columnWidths();
179 QVariantList headers;
180 headers.reserve( columnWidths.size() );
181 for (
double width : columnWidths )
183 mEditorDialog->setTableColumnWidth( col, width );
184 headers << ( col < mTable->headers().count() ? mTable->headers().value( col ).heading() : QVariant() );
187 mEditorDialog->setTableHeaders( headers );
189 connect( mEditorDialog, &QgsTableEditorDialog::tableChanged,
this, [ = ]
193 mTable->beginCommand( tr(
"Change Table Contents" ) );
194 mTable->setTableContents( mEditorDialog->tableContents() );
196 const QVariantList headerText = mEditorDialog->tableHeaders();
197 if ( mEditorDialog->includeTableHeader() )
199 QgsLayoutTableColumns headers;
200 for ( const QVariant &h : headerText )
202 headers << QgsLayoutTableColumn( h.toString() );
204 mTable->setHeaders( headers );
207 const int rowCount = mTable->tableContents().size();
208 QList< double > rowHeights;
209 rowHeights.reserve( rowCount );
210 for (
int row = 0; row < rowCount; ++row )
212 rowHeights << mEditorDialog->tableRowHeight( row );
214 mTable->setRowHeights( rowHeights );
216 if ( !mTable->tableContents().empty() )
218 const int columnCount = mTable->tableContents().at( 0 ).size();
219 QList< double > columnWidths;
220 columnWidths.reserve( columnCount );
221 for ( int col = 0; col < columnCount; ++col )
223 columnWidths << mEditorDialog->tableColumnWidth( col );
225 mTable->setColumnWidths( columnWidths );
228 mTable->endCommand();
232 connect( mEditorDialog, &QgsTableEditorDialog::includeHeaderChanged,
this, [ = ](
bool included )
236 mTable->beginCommand( tr(
"Change Table Header" ) );
237 mTable->setIncludeTableHeader( included );
238 mTable->endCommand();
241 mEditorDialog->show();
245 void QgsLayoutManualTableWidget::mMarginSpinBox_valueChanged(
double d )
253 mTable->setCellMargin( d );
254 mTable->endCommand();
257 void QgsLayoutManualTableWidget::contentFontChanged()
264 mTable->beginCommand( tr(
"Change Table Font" ) );
265 mTable->setContentTextFormat( mContentFontToolButton->textFormat() );
266 mTable->endCommand();
269 void QgsLayoutManualTableWidget::mGridStrokeWidthSpinBox_valueChanged(
double d )
277 mTable->setGridStrokeWidth( d );
278 mTable->endCommand();
281 void QgsLayoutManualTableWidget::mGridColorButton_colorChanged(
const QColor &newColor )
289 mTable->setGridColor( newColor );
290 mTable->endCommand();
293 void QgsLayoutManualTableWidget::mDrawHorizontalGrid_toggled(
bool state )
300 mTable->beginCommand( tr(
"Toggle Table Grid" ) );
301 mTable->setHorizontalGrid( state );
302 mTable->endCommand();
305 void QgsLayoutManualTableWidget::mDrawVerticalGrid_toggled(
bool state )
312 mTable->beginCommand( tr(
"Toggled Table Grid" ) );
313 mTable->setVerticalGrid( state );
314 mTable->endCommand();
317 void QgsLayoutManualTableWidget::mShowGridGroupCheckBox_toggled(
bool state )
324 mTable->beginCommand( tr(
"Toggle Table Grid" ) );
325 mTable->setShowGrid( state );
326 mTable->endCommand();
329 void QgsLayoutManualTableWidget::mHeaderHAlignmentComboBox_currentIndexChanged(
int )
336 mTable->beginCommand( tr(
"Change Table Alignment" ) );
338 mTable->endCommand();
341 void QgsLayoutManualTableWidget::mHeaderModeComboBox_currentIndexChanged(
int )
348 mTable->beginCommand( tr(
"Change Table Header Mode" ) );
350 mTable->endCommand();
353 void QgsLayoutManualTableWidget::mBackgroundColorButton_colorChanged(
const QColor &newColor )
361 mTable->setBackgroundColor( newColor );
362 mTable->endCommand();
365 void QgsLayoutManualTableWidget::headerFontChanged()
370 mTable->beginCommand( tr(
"Change Table Font" ) );
371 mTable->setHeaderTextFormat( mHeaderFontToolButton->textFormat() );
372 mTable->endCommand();
375 void QgsLayoutManualTableWidget::updateGuiElements()
377 if ( !mTable || !mFrame )
382 blockAllSignals(
true );
384 mMarginSpinBox->setValue( mTable->cellMargin() );
385 mGridStrokeWidthSpinBox->setValue( mTable->gridStrokeWidth() );
386 mGridColorButton->setColor( mTable->gridColor() );
387 mDrawHorizontalGrid->setChecked( mTable->horizontalGrid() );
388 mDrawVerticalGrid->setChecked( mTable->verticalGrid() );
389 if ( mTable->showGrid() )
391 mShowGridGroupCheckBox->setChecked(
true );
395 mShowGridGroupCheckBox->setChecked(
false );
397 mBackgroundColorButton->setColor( mTable->backgroundColor() );
399 mHeaderFontToolButton->setTextFormat( mTable->headerTextFormat() );
400 mContentFontToolButton->setTextFormat( mTable->contentTextFormat() );
402 mDrawEmptyCheckBox->setChecked( mTable->showEmptyRows() );
403 mWrapBehaviorComboBox->setCurrentIndex( mWrapBehaviorComboBox->findData( mTable->wrapBehavior() ) );
405 mResizeModeComboBox->setCurrentIndex( mResizeModeComboBox->findData( mTable->resizeMode() ) );
408 mHeaderHAlignmentComboBox->setCurrentIndex( mHeaderHAlignmentComboBox->findData( mTable->headerHAlignment() ) );
409 mHeaderModeComboBox->setCurrentIndex( mHeaderModeComboBox->findData( mTable->headerMode() ) );
411 mEmptyFrameCheckBox->setChecked( mFrame->hidePageIfEmpty() );
412 mHideEmptyBgCheckBox->setChecked( mFrame->hideBackgroundIfEmpty() );
414 blockAllSignals(
false );
417 void QgsLayoutManualTableWidget::blockAllSignals(
bool b )
419 mMarginSpinBox->blockSignals( b );
420 mGridColorButton->blockSignals( b );
421 mGridStrokeWidthSpinBox->blockSignals( b );
422 mBackgroundColorButton->blockSignals( b );
423 mDrawHorizontalGrid->blockSignals( b );
424 mDrawVerticalGrid->blockSignals( b );
425 mShowGridGroupCheckBox->blockSignals( b );
426 mResizeModeComboBox->blockSignals( b );
427 mEmptyFrameCheckBox->blockSignals( b );
428 mHideEmptyBgCheckBox->blockSignals( b );
429 mDrawEmptyCheckBox->blockSignals( b );
430 mWrapBehaviorComboBox->blockSignals( b );
431 mContentFontToolButton->blockSignals( b );
432 mHeaderHAlignmentComboBox->blockSignals( b );
433 mHeaderModeComboBox->blockSignals( b );
434 mHeaderFontToolButton->blockSignals( b );
437 void QgsLayoutManualTableWidget::mEmptyFrameCheckBox_toggled(
bool checked )
444 mFrame->beginCommand( tr(
"Toggle Empty Frame Mode" ) );
445 mFrame->setHidePageIfEmpty( checked );
446 mFrame->endCommand();
449 void QgsLayoutManualTableWidget::mHideEmptyBgCheckBox_toggled(
bool checked )
456 mFrame->beginCommand( tr(
"Toggle Background Display" ) );
457 mFrame->setHideBackgroundIfEmpty( checked );
458 mFrame->endCommand();
461 void QgsLayoutManualTableWidget::mAddFramePushButton_clicked()
463 if ( !mTable || !mFrame )
469 QPointF pos = mFrame->pos();
471 pos.ry() += mFrame->rect().height() + 10;
473 QgsLayoutFrame *newFrame = mTable->createNewFrame( mFrame, pos, mFrame->rect().size() );
474 mTable->recalculateFrameSizes();
477 if (
QgsLayout *layout = mTable->layout() )
479 layout->setSelectedItem( newFrame );
483 void QgsLayoutManualTableWidget::mResizeModeComboBox_currentIndexChanged(
int index )
490 mTable->beginCommand( tr(
"Change Resize Mode" ) );
492 mTable->endCommand();
497 void QgsLayoutManualTableWidget::mWrapBehaviorComboBox_currentIndexChanged(
int index )
504 mTable->beginCommand( tr(
"Change Table Wrap Mode" ) );
506 mTable->endCommand();
509 void QgsLayoutManualTableWidget::mAdvancedCustomizationButton_clicked()
521 void QgsLayoutManualTableWidget::mDrawEmptyCheckBox_toggled(
bool checked )
528 mTable->beginCommand( tr(
"Change Show Empty Rows" ) );
529 mTable->setShowEmptyRows( checked );
530 mTable->endCommand();