22 #include "qgssettings.h"
25 #include <QFileDialog>
30 , mHtml( frame ? qobject_cast<
QgsLayoutItemHtml* >( frame->multiFrame() ) : nullptr )
34 connect( mUrlLineEdit, &QLineEdit::editingFinished,
this, &QgsLayoutHtmlWidget::mUrlLineEdit_editingFinished );
35 connect( mFileToolButton, &QToolButton::clicked,
this, &QgsLayoutHtmlWidget::mFileToolButton_clicked );
36 connect( mResizeModeComboBox,
static_cast<void ( QComboBox::* )(
int )
>( &QComboBox::currentIndexChanged ),
this, &QgsLayoutHtmlWidget::mResizeModeComboBox_currentIndexChanged );
37 connect( mEvaluateExpressionsCheckbox, &QCheckBox::toggled,
this, &QgsLayoutHtmlWidget::mEvaluateExpressionsCheckbox_toggled );
38 connect( mUseSmartBreaksCheckBox, &QgsCollapsibleGroupBoxBasic::toggled,
this, &QgsLayoutHtmlWidget::mUseSmartBreaksCheckBox_toggled );
39 connect( mMaxDistanceSpinBox,
static_cast < void ( QDoubleSpinBox::* )(
double )
> ( &QDoubleSpinBox::valueChanged ),
this, &QgsLayoutHtmlWidget::mMaxDistanceSpinBox_valueChanged );
40 connect( mUserStylesheetCheckBox, &QgsCollapsibleGroupBoxBasic::toggled,
this, &QgsLayoutHtmlWidget::mUserStylesheetCheckBox_toggled );
41 connect( mRadioManualSource, &QRadioButton::clicked,
this, &QgsLayoutHtmlWidget::mRadioManualSource_clicked );
42 connect( mRadioUrlSource, &QRadioButton::clicked,
this, &QgsLayoutHtmlWidget::mRadioUrlSource_clicked );
43 connect( mInsertExpressionButton, &QPushButton::clicked,
this, &QgsLayoutHtmlWidget::mInsertExpressionButton_clicked );
44 connect( mReloadPushButton, &QPushButton::clicked,
this, &QgsLayoutHtmlWidget::mReloadPushButton_clicked );
45 connect( mReloadPushButton2, &QPushButton::clicked,
this, &QgsLayoutHtmlWidget::mReloadPushButton_clicked );
46 connect( mAddFramePushButton, &QPushButton::clicked,
this, &QgsLayoutHtmlWidget::mAddFramePushButton_clicked );
47 connect( mEmptyFrameCheckBox, &QCheckBox::toggled,
this, &QgsLayoutHtmlWidget::mEmptyFrameCheckBox_toggled );
48 connect( mHideEmptyBgCheckBox, &QCheckBox::toggled,
this, &QgsLayoutHtmlWidget::mHideEmptyBgCheckBox_toggled );
53 connect( mHtmlEditor, &QsciScintilla::textChanged,
this, &QgsLayoutHtmlWidget::htmlEditorChanged );
54 htmlEditorLayout->addWidget( mHtmlEditor );
58 connect( mStylesheetEditor, &QsciScintilla::textChanged,
this, &QgsLayoutHtmlWidget::stylesheetEditorChanged );
59 stylesheetEditorLayout->addWidget( mStylesheetEditor );
66 blockSignals(
false );
67 setGuiElementValues();
79 mainLayout->addWidget( mItemPropertiesWidget );
89 if ( mItemPropertiesWidget )
111 mHtml = qobject_cast< QgsLayoutItemHtml * >( multiFrame );
113 mItemPropertiesWidget->
setItem( frame );
120 setGuiElementValues();
125 void QgsLayoutHtmlWidget::blockSignals(
bool block )
127 mUrlLineEdit->blockSignals( block );
128 mFileToolButton->blockSignals( block );
129 mResizeModeComboBox->blockSignals( block );
130 mUseSmartBreaksCheckBox->blockSignals( block );
131 mMaxDistanceSpinBox->blockSignals( block );
132 mHtmlEditor->blockSignals( block );
133 mStylesheetEditor->blockSignals( block );
134 mUserStylesheetCheckBox->blockSignals( block );
135 mRadioManualSource->blockSignals( block );
136 mRadioUrlSource->blockSignals( block );
137 mEvaluateExpressionsCheckbox->blockSignals( block );
138 mEmptyFrameCheckBox->blockSignals( block );
139 mHideEmptyBgCheckBox->blockSignals( block );
142 void QgsLayoutHtmlWidget::mUrlLineEdit_editingFinished()
146 QUrl newUrl( mUrlLineEdit->text() );
147 if ( newUrl == mHtml->url() )
152 mHtml->beginCommand( tr(
"Change HTML Url" ) );
153 mHtml->setUrl( newUrl );
159 void QgsLayoutHtmlWidget::mFileToolButton_clicked()
162 QString lastDir = s.value( QStringLiteral(
"/UI/lastHtmlDir" ), QDir::homePath() ).toString();
163 QString file = QFileDialog::getOpenFileName(
this, tr(
"Select HTML document" ), lastDir, QStringLiteral(
"HTML (*.html *.htm);;All files (*.*)" ) );
164 if ( !file.isEmpty() )
166 QUrl url = QUrl::fromLocalFile( file );
167 mUrlLineEdit->setText( url.toString() );
168 mUrlLineEdit_editingFinished();
170 s.setValue( QStringLiteral(
"/UI/lastHtmlDir" ), QFileInfo( file ).absolutePath() );
174 void QgsLayoutHtmlWidget::mResizeModeComboBox_currentIndexChanged(
int index )
181 mHtml->beginCommand( tr(
"Change Resize Mode" ) );
188 void QgsLayoutHtmlWidget::mEvaluateExpressionsCheckbox_toggled(
bool checked )
195 blockSignals(
true );
196 mHtml->beginCommand( tr(
"Change Evaluate Expressions" ) );
197 mHtml->setEvaluateExpressions( checked );
199 blockSignals(
false );
202 void QgsLayoutHtmlWidget::mUseSmartBreaksCheckBox_toggled(
bool checked )
209 blockSignals(
true );
210 mHtml->beginCommand( tr(
"Change Smart Breaks" ) );
211 mHtml->setUseSmartBreaks( checked );
213 blockSignals(
false );
216 void QgsLayoutHtmlWidget::mMaxDistanceSpinBox_valueChanged(
double val )
223 blockSignals(
true );
225 mHtml->setMaxBreakDistance( val );
227 blockSignals(
false );
230 void QgsLayoutHtmlWidget::htmlEditorChanged()
237 blockSignals(
true );
239 mHtml->setHtml( mHtmlEditor->text() );
241 blockSignals(
false );
244 void QgsLayoutHtmlWidget::stylesheetEditorChanged()
251 blockSignals(
true );
253 mHtml->setUserStylesheet( mStylesheetEditor->text() );
255 blockSignals(
false );
258 void QgsLayoutHtmlWidget::mUserStylesheetCheckBox_toggled(
bool checked )
265 blockSignals(
true );
266 mHtml->beginCommand( tr(
"Toggle User Stylesheet" ) );
267 mHtml->setUserStylesheetEnabled( checked );
269 blockSignals(
false );
272 void QgsLayoutHtmlWidget::mEmptyFrameCheckBox_toggled(
bool checked )
279 mFrame->beginCommand( tr(
"Toggle Empty Frame Mode" ) );
280 mFrame->setHidePageIfEmpty( checked );
281 mFrame->endCommand();
284 void QgsLayoutHtmlWidget::mHideEmptyBgCheckBox_toggled(
bool checked )
291 mFrame->beginCommand( tr(
"Toggle Hide Background" ) );
292 mFrame->setHideBackgroundIfEmpty( checked );
293 mFrame->endCommand();
296 void QgsLayoutHtmlWidget::mRadioManualSource_clicked(
bool checked )
303 blockSignals(
true );
304 mHtml->beginCommand( tr(
"Change HTML Source" ) );
306 blockSignals(
false );
308 mHtmlEditor->setEnabled( checked );
309 mInsertExpressionButton->setEnabled( checked );
310 mUrlLineEdit->setEnabled( !checked );
311 mFileToolButton->setEnabled( !checked );
317 void QgsLayoutHtmlWidget::mRadioUrlSource_clicked(
bool checked )
324 blockSignals(
true );
325 mHtml->beginCommand( tr(
"Change HTML Source" ) );
327 blockSignals(
false );
329 mHtmlEditor->setEnabled( !checked );
330 mInsertExpressionButton->setEnabled( !checked );
331 mUrlLineEdit->setEnabled( checked );
332 mFileToolButton->setEnabled( checked );
338 void QgsLayoutHtmlWidget::mInsertExpressionButton_clicked()
348 if ( mHtmlEditor->hasSelectedText() )
350 selText = mHtmlEditor->selectedText();
353 if ( selText.startsWith( QLatin1String(
"[%" ) ) && selText.endsWith( QLatin1String(
"%]" ) ) )
354 selText = selText.mid( 2, selText.size() - 4 );
358 mHtmlEditor->getCursorPosition( &line, &index );
366 exprDlg.setWindowTitle( tr(
"Insert Expression" ) );
367 if ( exprDlg.exec() == QDialog::Accepted )
369 QString expression = exprDlg.expressionText();
370 if ( !expression.isEmpty() )
372 blockSignals(
true );
373 mHtml->beginCommand( tr(
"Change HTML Source" ) );
374 if ( mHtmlEditor->hasSelectedText() )
376 mHtmlEditor->replaceSelectedText(
"[%" + expression +
"%]" );
380 mHtmlEditor->insertAt(
"[%" + expression +
"%]", line, index );
382 mHtml->setHtml( mHtmlEditor->text() );
384 blockSignals(
false );
390 void QgsLayoutHtmlWidget::mReloadPushButton_clicked()
397 if ( mHtml->layout() )
398 mHtml->layout()->undoStack()->blockCommands(
true );
400 if ( mHtml->layout() )
401 mHtml->layout()->undoStack()->blockCommands(
false );
404 void QgsLayoutHtmlWidget::mAddFramePushButton_clicked()
406 if ( !mHtml || !mFrame )
412 QPointF pos = mFrame->pos();
414 pos.ry() += mFrame->rect().height() + 10;
416 QgsLayoutFrame *newFrame = mHtml->createNewFrame( mFrame, pos, mFrame->rect().size() );
417 mHtml->recalculateFrameSizes();
420 if (
QgsLayout *layout = mHtml->layout() )
422 layout->setSelectedItem( newFrame );
426 void QgsLayoutHtmlWidget::setGuiElementValues()
428 if ( !mHtml || !mFrame )
433 blockSignals(
true );
434 mUrlLineEdit->setText( mHtml->url().toString() );
435 mResizeModeComboBox->setCurrentIndex( mResizeModeComboBox->findData( mHtml->resizeMode() ) );
436 mEvaluateExpressionsCheckbox->setChecked( mHtml->evaluateExpressions() );
437 mUseSmartBreaksCheckBox->setChecked( mHtml->useSmartBreaks() );
438 mMaxDistanceSpinBox->setValue( mHtml->maxBreakDistance() );
441 mHtmlEditor->setText( mHtml->html() );
450 mUserStylesheetCheckBox->setChecked( mHtml->userStylesheetEnabled() );
451 mStylesheetEditor->setText( mHtml->userStylesheet() );
453 mEmptyFrameCheckBox->setChecked( mFrame->hidePageIfEmpty() );
454 mHideEmptyBgCheckBox->setChecked( mFrame->hideBackgroundIfEmpty() );
458 blockSignals(
false );
466 mUrlLineEdit->setEnabled( !mUrlDDBtn->isActive() );
A CSS editor based on QScintilla2.
A HTML editor based on QScintilla2.
A generic dialog for building expression strings.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
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.
Represents a vector layer which manages a vector based data sets.