16#include "moc_qgslayouthtmlwidget.cpp" 
   32  , mHtml( frame ? qobject_cast<
QgsLayoutItemHtml *>( frame->multiFrame() ) : nullptr )
 
   36  connect( mUrlLineEdit, &QLineEdit::editingFinished, 
this, &QgsLayoutHtmlWidget::mUrlLineEdit_editingFinished );
 
   37  connect( mFileToolButton, &QToolButton::clicked, 
this, &QgsLayoutHtmlWidget::mFileToolButton_clicked );
 
   38  connect( mResizeModeComboBox, 
static_cast<void ( QComboBox::* )( 
int )
>( &QComboBox::currentIndexChanged ), 
this, &QgsLayoutHtmlWidget::mResizeModeComboBox_currentIndexChanged );
 
   39  connect( mEvaluateExpressionsCheckbox, &QCheckBox::toggled, 
this, &QgsLayoutHtmlWidget::mEvaluateExpressionsCheckbox_toggled );
 
   40  connect( mUseSmartBreaksCheckBox, &QgsCollapsibleGroupBoxBasic::toggled, 
this, &QgsLayoutHtmlWidget::mUseSmartBreaksCheckBox_toggled );
 
   41  connect( mMaxDistanceSpinBox, 
static_cast<void ( QDoubleSpinBox::* )( 
double )
>( &QDoubleSpinBox::valueChanged ), 
this, &QgsLayoutHtmlWidget::mMaxDistanceSpinBox_valueChanged );
 
   42  connect( mUserStylesheetCheckBox, &QgsCollapsibleGroupBoxBasic::toggled, 
this, &QgsLayoutHtmlWidget::mUserStylesheetCheckBox_toggled );
 
   43  connect( mRadioManualSource, &QRadioButton::clicked, 
this, &QgsLayoutHtmlWidget::mRadioManualSource_clicked );
 
   44  connect( mRadioUrlSource, &QRadioButton::clicked, 
this, &QgsLayoutHtmlWidget::mRadioUrlSource_clicked );
 
   45  connect( mInsertExpressionButton, &QPushButton::clicked, 
this, &QgsLayoutHtmlWidget::mInsertExpressionButton_clicked );
 
   46  connect( mReloadPushButton, &QPushButton::clicked, 
this, &QgsLayoutHtmlWidget::mReloadPushButton_clicked );
 
   47  connect( mReloadPushButton2, &QPushButton::clicked, 
this, &QgsLayoutHtmlWidget::mReloadPushButton_clicked );
 
   48  connect( mAddFramePushButton, &QPushButton::clicked, 
this, &QgsLayoutHtmlWidget::mAddFramePushButton_clicked );
 
   49  connect( mEmptyFrameCheckBox, &QCheckBox::toggled, 
this, &QgsLayoutHtmlWidget::mEmptyFrameCheckBox_toggled );
 
   50  connect( mHideEmptyBgCheckBox, &QCheckBox::toggled, 
this, &QgsLayoutHtmlWidget::mHideEmptyBgCheckBox_toggled );
 
   55  connect( mHtmlEditor, &QsciScintilla::textChanged, 
this, &QgsLayoutHtmlWidget::htmlEditorChanged );
 
   56  htmlEditorLayout->addWidget( mHtmlEditor );
 
   60  connect( mStylesheetEditor, &QsciScintilla::textChanged, 
this, &QgsLayoutHtmlWidget::stylesheetEditorChanged );
 
   61  stylesheetEditorLayout->addWidget( mStylesheetEditor );
 
   68  blockSignals( 
false );
 
   69  setGuiElementValues();
 
   81    mainLayout->addWidget( mItemPropertiesWidget );
 
 
   91  if ( mItemPropertiesWidget )
 
 
  113  mHtml = qobject_cast<QgsLayoutItemHtml *>( multiFrame );
 
  115  mItemPropertiesWidget->
setItem( frame );
 
  122  setGuiElementValues();
 
 
  127void QgsLayoutHtmlWidget::blockSignals( 
bool block )
 
  129  mUrlLineEdit->blockSignals( block );
 
  130  mFileToolButton->blockSignals( block );
 
  131  mResizeModeComboBox->blockSignals( block );
 
  132  mUseSmartBreaksCheckBox->blockSignals( block );
 
  133  mMaxDistanceSpinBox->blockSignals( block );
 
  134  mHtmlEditor->blockSignals( block );
 
  135  mStylesheetEditor->blockSignals( block );
 
  136  mUserStylesheetCheckBox->blockSignals( block );
 
  137  mRadioManualSource->blockSignals( block );
 
  138  mRadioUrlSource->blockSignals( block );
 
  139  mEvaluateExpressionsCheckbox->blockSignals( block );
 
  140  mEmptyFrameCheckBox->blockSignals( block );
 
  141  mHideEmptyBgCheckBox->blockSignals( block );
 
  144void QgsLayoutHtmlWidget::mUrlLineEdit_editingFinished()
 
  148    const QUrl newUrl( mUrlLineEdit->text() );
 
  149    if ( newUrl == mHtml->url() )
 
  154    mHtml->beginCommand( tr( 
"Change HTML Url" ) );
 
  155    mHtml->setUrl( newUrl );
 
  161void QgsLayoutHtmlWidget::mFileToolButton_clicked()
 
  164  const QString lastDir = s.
value( QStringLiteral( 
"/UI/lastHtmlDir" ), QDir::homePath() ).toString();
 
  165  const QString file = QFileDialog::getOpenFileName( 
this, tr( 
"Select HTML document" ), lastDir, QStringLiteral( 
"HTML (*.html *.htm);;All files (*.*)" ) );
 
  166  if ( !file.isEmpty() )
 
  168    const QUrl url = QUrl::fromLocalFile( file );
 
  169    mUrlLineEdit->setText( url.toString() );
 
  170    mUrlLineEdit_editingFinished();
 
  172    s.
setValue( QStringLiteral( 
"/UI/lastHtmlDir" ), QFileInfo( file ).absolutePath() );
 
  176void QgsLayoutHtmlWidget::mResizeModeComboBox_currentIndexChanged( 
int index )
 
  183  mHtml->beginCommand( tr( 
"Change Resize Mode" ) );
 
  190void QgsLayoutHtmlWidget::mEvaluateExpressionsCheckbox_toggled( 
bool checked )
 
  197  blockSignals( 
true );
 
  198  mHtml->beginCommand( tr( 
"Change Evaluate Expressions" ) );
 
  199  mHtml->setEvaluateExpressions( checked );
 
  201  blockSignals( 
false );
 
  204void QgsLayoutHtmlWidget::mUseSmartBreaksCheckBox_toggled( 
bool checked )
 
  211  blockSignals( 
true );
 
  212  mHtml->beginCommand( tr( 
"Change Smart Breaks" ) );
 
  213  mHtml->setUseSmartBreaks( checked );
 
  215  blockSignals( 
false );
 
  218void QgsLayoutHtmlWidget::mMaxDistanceSpinBox_valueChanged( 
double val )
 
  225  blockSignals( 
true );
 
  227  mHtml->setMaxBreakDistance( val );
 
  229  blockSignals( 
false );
 
  232void QgsLayoutHtmlWidget::htmlEditorChanged()
 
  239  blockSignals( 
true );
 
  241  mHtml->setHtml( mHtmlEditor->text() );
 
  243  blockSignals( 
false );
 
  246void QgsLayoutHtmlWidget::stylesheetEditorChanged()
 
  253  blockSignals( 
true );
 
  255  mHtml->setUserStylesheet( mStylesheetEditor->text() );
 
  257  blockSignals( 
false );
 
  260void QgsLayoutHtmlWidget::mUserStylesheetCheckBox_toggled( 
bool checked )
 
  267  blockSignals( 
true );
 
  268  mHtml->beginCommand( tr( 
"Toggle User Stylesheet" ) );
 
  269  mHtml->setUserStylesheetEnabled( checked );
 
  271  blockSignals( 
false );
 
  274void QgsLayoutHtmlWidget::mEmptyFrameCheckBox_toggled( 
bool checked )
 
  281  mFrame->beginCommand( tr( 
"Toggle Empty Frame Mode" ) );
 
  282  mFrame->setHidePageIfEmpty( checked );
 
  283  mFrame->endCommand();
 
  286void QgsLayoutHtmlWidget::mHideEmptyBgCheckBox_toggled( 
bool checked )
 
  293  mFrame->beginCommand( tr( 
"Toggle Hide Background" ) );
 
  294  mFrame->setHideBackgroundIfEmpty( checked );
 
  295  mFrame->endCommand();
 
  298void QgsLayoutHtmlWidget::mRadioManualSource_clicked( 
bool checked )
 
  305  blockSignals( 
true );
 
  306  mHtml->beginCommand( tr( 
"Change HTML Source" ) );
 
  308  blockSignals( 
false );
 
  310  mHtmlEditor->setEnabled( checked );
 
  311  mInsertExpressionButton->setEnabled( checked );
 
  312  mUrlLineEdit->setEnabled( !checked );
 
  313  mFileToolButton->setEnabled( !checked );
 
  319void QgsLayoutHtmlWidget::mRadioUrlSource_clicked( 
bool checked )
 
  326  blockSignals( 
true );
 
  327  mHtml->beginCommand( tr( 
"Change HTML Source" ) );
 
  329  blockSignals( 
false );
 
  331  mHtmlEditor->setEnabled( !checked );
 
  332  mInsertExpressionButton->setEnabled( !checked );
 
  333  mUrlLineEdit->setEnabled( checked );
 
  334  mFileToolButton->setEnabled( checked );
 
  340void QgsLayoutHtmlWidget::mInsertExpressionButton_clicked()
 
  354  exprDlg.setWindowTitle( tr( 
"Insert Expression" ) );
 
  355  if ( exprDlg.exec() == QDialog::Accepted )
 
  357    expression = exprDlg.expressionText();
 
  358    if ( !expression.isEmpty() )
 
  360      blockSignals( 
true );
 
  361      mHtml->beginCommand( tr( 
"Change HTML Source" ) );
 
  362      mHtmlEditor->
insertText( 
"[%" + expression.trimmed() + 
"%]" );
 
  363      mHtml->setHtml( mHtmlEditor->text() );
 
  365      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 setText(const QString &text) override
 
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.
 
Stores settings for use within QGIS.
 
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 dataset.