31 , mHtml( frame ? qobject_cast<
QgsLayoutItemHtml* >( frame->multiFrame() ) : nullptr )
35 connect( mUrlLineEdit, &QLineEdit::editingFinished,
this, &QgsLayoutHtmlWidget::mUrlLineEdit_editingFinished );
36 connect( mFileToolButton, &QToolButton::clicked,
this, &QgsLayoutHtmlWidget::mFileToolButton_clicked );
37 connect( mResizeModeComboBox,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, &QgsLayoutHtmlWidget::mResizeModeComboBox_currentIndexChanged );
38 connect( mEvaluateExpressionsCheckbox, &QCheckBox::toggled,
this, &QgsLayoutHtmlWidget::mEvaluateExpressionsCheckbox_toggled );
39 connect( mUseSmartBreaksCheckBox, &QgsCollapsibleGroupBoxBasic::toggled,
this, &QgsLayoutHtmlWidget::mUseSmartBreaksCheckBox_toggled );
40 connect( mMaxDistanceSpinBox,
static_cast < void ( QDoubleSpinBox::* )(
double )
> ( &QDoubleSpinBox::valueChanged ),
this, &QgsLayoutHtmlWidget::mMaxDistanceSpinBox_valueChanged );
41 connect( mUserStylesheetCheckBox, &QgsCollapsibleGroupBoxBasic::toggled,
this, &QgsLayoutHtmlWidget::mUserStylesheetCheckBox_toggled );
42 connect( mRadioManualSource, &QRadioButton::clicked,
this, &QgsLayoutHtmlWidget::mRadioManualSource_clicked );
43 connect( mRadioUrlSource, &QRadioButton::clicked,
this, &QgsLayoutHtmlWidget::mRadioUrlSource_clicked );
44 connect( mInsertExpressionButton, &QPushButton::clicked,
this, &QgsLayoutHtmlWidget::mInsertExpressionButton_clicked );
45 connect( mReloadPushButton, &QPushButton::clicked,
this, &QgsLayoutHtmlWidget::mReloadPushButton_clicked );
46 connect( mReloadPushButton2, &QPushButton::clicked,
this, &QgsLayoutHtmlWidget::mReloadPushButton_clicked );
47 connect( mAddFramePushButton, &QPushButton::clicked,
this, &QgsLayoutHtmlWidget::mAddFramePushButton_clicked );
48 connect( mEmptyFrameCheckBox, &QCheckBox::toggled,
this, &QgsLayoutHtmlWidget::mEmptyFrameCheckBox_toggled );
49 connect( mHideEmptyBgCheckBox, &QCheckBox::toggled,
this, &QgsLayoutHtmlWidget::mHideEmptyBgCheckBox_toggled );
54 connect( mHtmlEditor, &QsciScintilla::textChanged,
this, &QgsLayoutHtmlWidget::htmlEditorChanged );
55 htmlEditorLayout->addWidget( mHtmlEditor );
59 connect( mStylesheetEditor, &QsciScintilla::textChanged,
this, &QgsLayoutHtmlWidget::stylesheetEditorChanged );
60 stylesheetEditorLayout->addWidget( mStylesheetEditor );
67 blockSignals(
false );
68 setGuiElementValues();
80 mainLayout->addWidget( mItemPropertiesWidget );
90 if ( mItemPropertiesWidget )
112 mHtml = qobject_cast< QgsLayoutItemHtml * >( multiFrame );
114 mItemPropertiesWidget->
setItem( frame );
121 setGuiElementValues();
126void QgsLayoutHtmlWidget::blockSignals(
bool block )
128 mUrlLineEdit->blockSignals( block );
129 mFileToolButton->blockSignals( block );
130 mResizeModeComboBox->blockSignals( block );
131 mUseSmartBreaksCheckBox->blockSignals( block );
132 mMaxDistanceSpinBox->blockSignals( block );
133 mHtmlEditor->blockSignals( block );
134 mStylesheetEditor->blockSignals( block );
135 mUserStylesheetCheckBox->blockSignals( block );
136 mRadioManualSource->blockSignals( block );
137 mRadioUrlSource->blockSignals( block );
138 mEvaluateExpressionsCheckbox->blockSignals( block );
139 mEmptyFrameCheckBox->blockSignals( block );
140 mHideEmptyBgCheckBox->blockSignals( block );
143void QgsLayoutHtmlWidget::mUrlLineEdit_editingFinished()
147 const QUrl newUrl( mUrlLineEdit->text() );
148 if ( newUrl == mHtml->url() )
153 mHtml->beginCommand( tr(
"Change HTML Url" ) );
154 mHtml->setUrl( newUrl );
160void QgsLayoutHtmlWidget::mFileToolButton_clicked()
163 const QString lastDir = s.
value( QStringLiteral(
"/UI/lastHtmlDir" ), QDir::homePath() ).toString();
164 const QString file = QFileDialog::getOpenFileName(
this, tr(
"Select HTML document" ), lastDir, QStringLiteral(
"HTML (*.html *.htm);;All files (*.*)" ) );
165 if ( !file.isEmpty() )
167 const QUrl url = QUrl::fromLocalFile( file );
168 mUrlLineEdit->setText( url.toString() );
169 mUrlLineEdit_editingFinished();
171 s.
setValue( QStringLiteral(
"/UI/lastHtmlDir" ), QFileInfo( file ).absolutePath() );
175void QgsLayoutHtmlWidget::mResizeModeComboBox_currentIndexChanged(
int index )
182 mHtml->beginCommand( tr(
"Change Resize Mode" ) );
189void QgsLayoutHtmlWidget::mEvaluateExpressionsCheckbox_toggled(
bool checked )
196 blockSignals(
true );
197 mHtml->beginCommand( tr(
"Change Evaluate Expressions" ) );
198 mHtml->setEvaluateExpressions( checked );
200 blockSignals(
false );
203void QgsLayoutHtmlWidget::mUseSmartBreaksCheckBox_toggled(
bool checked )
210 blockSignals(
true );
211 mHtml->beginCommand( tr(
"Change Smart Breaks" ) );
212 mHtml->setUseSmartBreaks( checked );
214 blockSignals(
false );
217void QgsLayoutHtmlWidget::mMaxDistanceSpinBox_valueChanged(
double val )
224 blockSignals(
true );
226 mHtml->setMaxBreakDistance( val );
228 blockSignals(
false );
231void QgsLayoutHtmlWidget::htmlEditorChanged()
238 blockSignals(
true );
240 mHtml->setHtml( mHtmlEditor->text() );
242 blockSignals(
false );
245void QgsLayoutHtmlWidget::stylesheetEditorChanged()
252 blockSignals(
true );
254 mHtml->setUserStylesheet( mStylesheetEditor->text() );
256 blockSignals(
false );
259void QgsLayoutHtmlWidget::mUserStylesheetCheckBox_toggled(
bool checked )
266 blockSignals(
true );
267 mHtml->beginCommand( tr(
"Toggle User Stylesheet" ) );
268 mHtml->setUserStylesheetEnabled( checked );
270 blockSignals(
false );
273void QgsLayoutHtmlWidget::mEmptyFrameCheckBox_toggled(
bool checked )
280 mFrame->beginCommand( tr(
"Toggle Empty Frame Mode" ) );
281 mFrame->setHidePageIfEmpty( checked );
282 mFrame->endCommand();
285void QgsLayoutHtmlWidget::mHideEmptyBgCheckBox_toggled(
bool checked )
292 mFrame->beginCommand( tr(
"Toggle Hide Background" ) );
293 mFrame->setHideBackgroundIfEmpty( checked );
294 mFrame->endCommand();
297void QgsLayoutHtmlWidget::mRadioManualSource_clicked(
bool checked )
304 blockSignals(
true );
305 mHtml->beginCommand( tr(
"Change HTML Source" ) );
307 blockSignals(
false );
309 mHtmlEditor->setEnabled( checked );
310 mInsertExpressionButton->setEnabled( checked );
311 mUrlLineEdit->setEnabled( !checked );
312 mFileToolButton->setEnabled( !checked );
318void QgsLayoutHtmlWidget::mRadioUrlSource_clicked(
bool checked )
325 blockSignals(
true );
326 mHtml->beginCommand( tr(
"Change HTML Source" ) );
328 blockSignals(
false );
330 mHtmlEditor->setEnabled( !checked );
331 mInsertExpressionButton->setEnabled( !checked );
332 mUrlLineEdit->setEnabled( checked );
333 mFileToolButton->setEnabled( checked );
339void QgsLayoutHtmlWidget::mInsertExpressionButton_clicked()
353 exprDlg.setWindowTitle( tr(
"Insert Expression" ) );
354 if ( exprDlg.exec() == QDialog::Accepted )
356 expression = exprDlg.expressionText();
357 if ( !expression.isEmpty() )
359 blockSignals(
true );
360 mHtml->beginCommand( tr(
"Change HTML Source" ) );
361 mHtmlEditor->
insertText(
"[%" + expression.trimmed() +
"%]" );
362 mHtml->setHtml( mHtmlEditor->text() );
364 blockSignals(
false );
370void QgsLayoutHtmlWidget::mReloadPushButton_clicked()
377 if ( mHtml->layout() )
378 mHtml->layout()->undoStack()->blockCommands(
true );
380 if ( mHtml->layout() )
381 mHtml->layout()->undoStack()->blockCommands(
false );
384void QgsLayoutHtmlWidget::mAddFramePushButton_clicked()
386 if ( !mHtml || !mFrame )
392 QPointF pos = mFrame->pos();
394 pos.ry() += mFrame->rect().height() + 10;
396 QgsLayoutFrame *newFrame = mHtml->createNewFrame( mFrame, pos, mFrame->rect().size() );
397 mHtml->recalculateFrameSizes();
400 if (
QgsLayout *layout = mHtml->layout() )
402 layout->setSelectedItem( newFrame );
406void QgsLayoutHtmlWidget::setGuiElementValues()
408 if ( !mHtml || !mFrame )
413 blockSignals(
true );
414 mUrlLineEdit->setText( mHtml->url().toString() );
415 mResizeModeComboBox->setCurrentIndex( mResizeModeComboBox->findData( mHtml->resizeMode() ) );
416 mEvaluateExpressionsCheckbox->setChecked( mHtml->evaluateExpressions() );
417 mUseSmartBreaksCheckBox->setChecked( mHtml->useSmartBreaks() );
418 mMaxDistanceSpinBox->setValue( mHtml->maxBreakDistance() );
421 mHtmlEditor->setText( mHtml->html() );
430 mUserStylesheetCheckBox->setChecked( mHtml->userStylesheetEnabled() );
431 mStylesheetEditor->setText( mHtml->userStylesheet() );
433 mEmptyFrameCheckBox->setChecked( mFrame->hidePageIfEmpty() );
434 mHideEmptyBgCheckBox->setChecked( mFrame->hideBackgroundIfEmpty() );
438 blockSignals(
false );
446 mUrlLineEdit->setEnabled( !mUrlDDBtn->isActive() );
A CSS editor based on QScintilla2.
A HTML editor based on QScintilla2.
void insertText(const QString &text)
Insert text at cursor position, or replace any selected text if user has made a selection.
A generic dialog for building expression strings.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
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.
Base class for layouts, which can contain items such as maps, labels, scalebars, etc.
Interface for master layout type objects, such as print layouts and reports.
This class is a composition of two QSettings instances:
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.
Represents a vector layer which manages a vector based data sets.