30#include "moc_qgslayouthtmlwidget.cpp"
34 , mHtml( frame ? qobject_cast<
QgsLayoutItemHtml *>( frame->multiFrame() ) : nullptr )
38 connect( mUrlLineEdit, &QLineEdit::editingFinished,
this, &QgsLayoutHtmlWidget::mUrlLineEdit_editingFinished );
39 connect( mFileToolButton, &QToolButton::clicked,
this, &QgsLayoutHtmlWidget::mFileToolButton_clicked );
40 connect( mResizeModeComboBox,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, &QgsLayoutHtmlWidget::mResizeModeComboBox_currentIndexChanged );
41 connect( mEvaluateExpressionsCheckbox, &QCheckBox::toggled,
this, &QgsLayoutHtmlWidget::mEvaluateExpressionsCheckbox_toggled );
42 connect( mUseSmartBreaksCheckBox, &QgsCollapsibleGroupBoxBasic::toggled,
this, &QgsLayoutHtmlWidget::mUseSmartBreaksCheckBox_toggled );
43 connect( mMaxDistanceSpinBox,
static_cast<void ( QDoubleSpinBox::* )(
double )
>( &QDoubleSpinBox::valueChanged ),
this, &QgsLayoutHtmlWidget::mMaxDistanceSpinBox_valueChanged );
44 connect( mUserStylesheetCheckBox, &QgsCollapsibleGroupBoxBasic::toggled,
this, &QgsLayoutHtmlWidget::mUserStylesheetCheckBox_toggled );
45 connect( mRadioManualSource, &QRadioButton::clicked,
this, &QgsLayoutHtmlWidget::mRadioManualSource_clicked );
46 connect( mRadioUrlSource, &QRadioButton::clicked,
this, &QgsLayoutHtmlWidget::mRadioUrlSource_clicked );
47 connect( mInsertExpressionButton, &QPushButton::clicked,
this, &QgsLayoutHtmlWidget::mInsertExpressionButton_clicked );
48 connect( mReloadPushButton, &QPushButton::clicked,
this, &QgsLayoutHtmlWidget::mReloadPushButton_clicked );
49 connect( mReloadPushButton2, &QPushButton::clicked,
this, &QgsLayoutHtmlWidget::mReloadPushButton_clicked );
50 connect( mAddFramePushButton, &QPushButton::clicked,
this, &QgsLayoutHtmlWidget::mAddFramePushButton_clicked );
51 connect( mEmptyFrameCheckBox, &QCheckBox::toggled,
this, &QgsLayoutHtmlWidget::mEmptyFrameCheckBox_toggled );
52 connect( mHideEmptyBgCheckBox, &QCheckBox::toggled,
this, &QgsLayoutHtmlWidget::mHideEmptyBgCheckBox_toggled );
57 connect( mHtmlEditor, &QsciScintilla::textChanged,
this, &QgsLayoutHtmlWidget::htmlEditorChanged );
58 htmlEditorLayout->addWidget( mHtmlEditor );
62 connect( mStylesheetEditor, &QsciScintilla::textChanged,
this, &QgsLayoutHtmlWidget::stylesheetEditorChanged );
63 stylesheetEditorLayout->addWidget( mStylesheetEditor );
70 blockSignals(
false );
71 setGuiElementValues();
83 mainLayout->addWidget( mItemPropertiesWidget );
93 if ( mItemPropertiesWidget )
94 mItemPropertiesWidget->setMasterLayout( masterLayout );
115 mHtml = qobject_cast<QgsLayoutItemHtml *>( multiFrame );
117 mItemPropertiesWidget->setItem( frame );
124 setGuiElementValues();
129void QgsLayoutHtmlWidget::blockSignals(
bool block )
131 mUrlLineEdit->blockSignals( block );
132 mFileToolButton->blockSignals( block );
133 mResizeModeComboBox->blockSignals( block );
134 mUseSmartBreaksCheckBox->blockSignals( block );
135 mMaxDistanceSpinBox->blockSignals( block );
136 mHtmlEditor->blockSignals( block );
137 mStylesheetEditor->blockSignals( block );
138 mUserStylesheetCheckBox->blockSignals( block );
139 mRadioManualSource->blockSignals( block );
140 mRadioUrlSource->blockSignals( block );
141 mEvaluateExpressionsCheckbox->blockSignals( block );
142 mEmptyFrameCheckBox->blockSignals( block );
143 mHideEmptyBgCheckBox->blockSignals( block );
146void QgsLayoutHtmlWidget::mUrlLineEdit_editingFinished()
150 const QUrl newUrl( mUrlLineEdit->text() );
151 if ( newUrl == mHtml->url() )
156 mHtml->beginCommand( tr(
"Change HTML Url" ) );
157 mHtml->setUrl( newUrl );
163void QgsLayoutHtmlWidget::mFileToolButton_clicked()
166 const QString lastDir = s.
value( QStringLiteral(
"/UI/lastHtmlDir" ), QDir::homePath() ).toString();
167 const QString file = QFileDialog::getOpenFileName(
this, tr(
"Select HTML document" ), lastDir, QStringLiteral(
"HTML (*.html *.htm);;All files (*.*)" ) );
168 if ( !file.isEmpty() )
170 const QUrl url = QUrl::fromLocalFile( file );
171 mUrlLineEdit->setText( url.toString() );
172 mUrlLineEdit_editingFinished();
174 s.
setValue( QStringLiteral(
"/UI/lastHtmlDir" ), QFileInfo( file ).absolutePath() );
178void QgsLayoutHtmlWidget::mResizeModeComboBox_currentIndexChanged(
int index )
185 mHtml->beginCommand( tr(
"Change Resize Mode" ) );
192void QgsLayoutHtmlWidget::mEvaluateExpressionsCheckbox_toggled(
bool checked )
199 blockSignals(
true );
200 mHtml->beginCommand( tr(
"Change Evaluate Expressions" ) );
201 mHtml->setEvaluateExpressions( checked );
203 blockSignals(
false );
206void QgsLayoutHtmlWidget::mUseSmartBreaksCheckBox_toggled(
bool checked )
213 blockSignals(
true );
214 mHtml->beginCommand( tr(
"Change Smart Breaks" ) );
215 mHtml->setUseSmartBreaks( checked );
217 blockSignals(
false );
220void QgsLayoutHtmlWidget::mMaxDistanceSpinBox_valueChanged(
double val )
227 blockSignals(
true );
229 mHtml->setMaxBreakDistance( val );
231 blockSignals(
false );
234void QgsLayoutHtmlWidget::htmlEditorChanged()
241 blockSignals(
true );
243 mHtml->setHtml( mHtmlEditor->text() );
245 blockSignals(
false );
248void QgsLayoutHtmlWidget::stylesheetEditorChanged()
255 blockSignals(
true );
257 mHtml->setUserStylesheet( mStylesheetEditor->text() );
259 blockSignals(
false );
262void QgsLayoutHtmlWidget::mUserStylesheetCheckBox_toggled(
bool checked )
269 blockSignals(
true );
270 mHtml->beginCommand( tr(
"Toggle User Stylesheet" ) );
271 mHtml->setUserStylesheetEnabled( checked );
273 blockSignals(
false );
276void QgsLayoutHtmlWidget::mEmptyFrameCheckBox_toggled(
bool checked )
283 mFrame->beginCommand( tr(
"Toggle Empty Frame Mode" ) );
284 mFrame->setHidePageIfEmpty( checked );
285 mFrame->endCommand();
288void QgsLayoutHtmlWidget::mHideEmptyBgCheckBox_toggled(
bool checked )
295 mFrame->beginCommand( tr(
"Toggle Hide Background" ) );
296 mFrame->setHideBackgroundIfEmpty( checked );
297 mFrame->endCommand();
300void QgsLayoutHtmlWidget::mRadioManualSource_clicked(
bool checked )
307 blockSignals(
true );
308 mHtml->beginCommand( tr(
"Change HTML Source" ) );
310 blockSignals(
false );
312 mHtmlEditor->setEnabled( checked );
313 mInsertExpressionButton->setEnabled( checked );
314 mUrlLineEdit->setEnabled( !checked );
315 mFileToolButton->setEnabled( !checked );
321void QgsLayoutHtmlWidget::mRadioUrlSource_clicked(
bool checked )
328 blockSignals(
true );
329 mHtml->beginCommand( tr(
"Change HTML Source" ) );
331 blockSignals(
false );
333 mHtmlEditor->setEnabled( !checked );
334 mInsertExpressionButton->setEnabled( !checked );
335 mUrlLineEdit->setEnabled( checked );
336 mFileToolButton->setEnabled( checked );
342void QgsLayoutHtmlWidget::mInsertExpressionButton_clicked()
354 const QgsExpressionContext context = mHtml->createExpressionContext();
355 QgsExpressionBuilderDialog exprDlg( layer, expression,
this, QStringLiteral(
"generic" ), context );
356 exprDlg.setWindowTitle( tr(
"Insert Expression" ) );
357 if ( exprDlg.exec() == QDialog::Accepted )
359 expression = exprDlg.expressionText();
360 if ( !expression.isEmpty() )
362 blockSignals(
true );
363 mHtml->beginCommand( tr(
"Change HTML Source" ) );
364 mHtmlEditor->insertText(
"[%" + expression.trimmed() +
"%]" );
365 mHtml->setHtml( mHtmlEditor->text() );
367 blockSignals(
false );
372void QgsLayoutHtmlWidget::mReloadPushButton_clicked()
379 if ( mHtml->layout() )
380 mHtml->layout()->undoStack()->blockCommands(
true );
382 if ( mHtml->layout() )
383 mHtml->layout()->undoStack()->blockCommands(
false );
386void QgsLayoutHtmlWidget::mAddFramePushButton_clicked()
388 if ( !mHtml || !mFrame )
394 QPointF pos = mFrame->pos();
396 pos.ry() += mFrame->rect().height() + 10;
398 QgsLayoutFrame *newFrame = mHtml->createNewFrame( mFrame, pos, mFrame->rect().size() );
399 mHtml->recalculateFrameSizes();
402 if ( QgsLayout *layout = mHtml->layout() )
404 layout->setSelectedItem( newFrame );
408void QgsLayoutHtmlWidget::setGuiElementValues()
410 if ( !mHtml || !mFrame )
415 blockSignals(
true );
416 mUrlLineEdit->setText( mHtml->url().toString() );
417 mResizeModeComboBox->setCurrentIndex( mResizeModeComboBox->findData( mHtml->resizeMode() ) );
418 mEvaluateExpressionsCheckbox->setChecked( mHtml->evaluateExpressions() );
419 mUseSmartBreaksCheckBox->setChecked( mHtml->useSmartBreaks() );
420 mMaxDistanceSpinBox->setValue( mHtml->maxBreakDistance() );
423 mHtmlEditor->setText( mHtml->html() );
432 mUserStylesheetCheckBox->setChecked( mHtml->userStylesheetEnabled() );
433 mStylesheetEditor->setText( mHtml->userStylesheet() );
435 mEmptyFrameCheckBox->setChecked( mFrame->hidePageIfEmpty() );
436 mHideEmptyBgCheckBox->setChecked( mFrame->hideBackgroundIfEmpty() );
440 blockSignals(
false );
448 mUrlLineEdit->setEnabled( !mUrlDDBtn->isActive() );
A CSS editor based on QScintilla2.
A HTML editor based on QScintilla2.
static QString findAndSelectActiveExpression(QgsCodeEditor *editor, const QString &pattern=QString())
Find the expression under the cursor in the given editor and select it.
Base class for frame items, which form a layout multiframe item.
QgsLayoutMultiFrame * multiFrame() const
Returns the parent multiframe for the frame.
A layout multiframe subclass for HTML content.
@ ManualHtml
HTML content is manually set for the item.
@ Url
Using this mode item fetches its content via a url.
@ LayoutHtml
Html multiframe item.
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.
@ RepeatOnEveryPage
Repeats the same frame on every page.
@ ExtendToNextPage
Creates new full page frames on the following page(s) until the entire multiframe content is visible.
@ UndoHtmlBreakDistance
HTML page break distance.
@ UndoHtmlStylesheet
HTML stylesheet.
@ UndoHtmlSource
HTML source.
void changed()
Emitted when the object's properties change.
@ SourceUrl
Html source url.
Interface for master layout type objects, such as print layouts and reports.
QVariant value(const QString &key, const QVariant &defaultValue=QVariant(), Section section=NoSection) const
Returns the value for setting key.
void setValue(const QString &key, const QVariant &value, QgsSettings::Section section=QgsSettings::NoSection)
Sets the value of setting key to value.