Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Live Annotation preview
  • Loading branch information
YoannQDQ authored and nyalldawson committed May 12, 2023
1 parent e61f355 commit 7ff9b7c
Show file tree
Hide file tree
Showing 12 changed files with 160 additions and 37 deletions.
12 changes: 12 additions & 0 deletions src/app/qgsannotationwidget.cpp
Expand Up @@ -25,6 +25,7 @@
#include "qgisapp.h"
#include "qgsfillsymbol.h"
#include "qgsmarkersymbol.h"
#include "qgsdoublespinbox.h"

#include <QColorDialog>

Expand Down Expand Up @@ -79,6 +80,17 @@ QgsAnnotationWidget::QgsAnnotationWidget( QgsMapCanvasAnnotationItem *item, QWid
mFrameStyleButton->setMessageBar( QgisApp::instance()->messageBar() );

connect( mFrameStyleButton, &QgsSymbolButton::changed, this, &QgsAnnotationWidget::frameStyleChanged );

// connect to the changed signal
connect( mFrameStyleButton, &QgsSymbolButton::changed, this, &QgsAnnotationWidget::changed );
connect( mMapMarkerButton, &QgsSymbolButton::changed, this, &QgsAnnotationWidget::changed );
connect( mLayerComboBox, &QgsMapLayerComboBox::layerChanged, this, &QgsAnnotationWidget::changed );
connect( mSpinTopMargin, static_cast < void ( QgsDoubleSpinBox::* )( double ) > ( &QgsDoubleSpinBox::valueChanged ), this, &QgsAnnotationWidget::changed );
connect( mSpinLeftMargin, static_cast < void ( QgsDoubleSpinBox::* )( double ) > ( &QgsDoubleSpinBox::valueChanged ), this, &QgsAnnotationWidget::changed );
connect( mSpinRightMargin, static_cast < void ( QgsDoubleSpinBox::* )( double ) > ( &QgsDoubleSpinBox::valueChanged ), this, &QgsAnnotationWidget::changed );
connect( mSpinBottomMargin, static_cast < void ( QgsDoubleSpinBox::* )( double ) > ( &QgsDoubleSpinBox::valueChanged ), this, &QgsAnnotationWidget::changed );
connect( mMapPositionFixedCheckBox, &QCheckBox::stateChanged, this, &QgsAnnotationWidget::changed );

}

QColor QgsAnnotationWidget::backgroundColor()
Expand Down
3 changes: 3 additions & 0 deletions src/app/qgsannotationwidget.h
Expand Up @@ -52,6 +52,9 @@ class APP_EXPORT QgsAnnotationWidget: public QWidget, private Ui::QgsAnnotationW
//! Emitted when the background color of the annotation is changed
void backgroundColorChanged( const QColor &color );

//! \since QGIS 3.32 Emitted when any property of the annotation is changed
void changed();

private:

QgsMapCanvasAnnotationItem *mItem = nullptr;
Expand Down
20 changes: 20 additions & 0 deletions src/app/qgsformannotationdialog.cpp
Expand Up @@ -57,6 +57,11 @@ QgsFormAnnotationDialog::QgsFormAnnotationDialog( QgsMapCanvasAnnotationItem *it
QObject::connect( deleteButton, &QPushButton::clicked, this, &QgsFormAnnotationDialog::deleteItem );
mButtonBox->addButton( deleteButton, QDialogButtonBox::RejectRole );

connect( mLiveCheckBox, &QCheckBox::toggled, this, &QgsFormAnnotationDialog::onLiveUpdateToggled );
connect( mEmbeddedWidget, &QgsAnnotationWidget::changed, this, &QgsFormAnnotationDialog::onSettingsChanged );
connect( mFileLineEdit, &QLineEdit::textChanged, this, &QgsFormAnnotationDialog::onSettingsChanged );
connect( mLiveCheckBox, &QCheckBox::toggled, this, &QgsFormAnnotationDialog::onSettingsChanged );

QgsGui::enableAutoGeometryRestore( this );
}

Expand Down Expand Up @@ -114,3 +119,18 @@ void QgsFormAnnotationDialog::showHelp()
{
QgsHelp::openHelp( QStringLiteral( "map_views/map_view.html#sec-annotations" ) );
}

void QgsFormAnnotationDialog::onSettingsChanged()
{
if ( mLiveCheckBox->isChecked() )
{
applySettingsToItem();
}
}

void QgsFormAnnotationDialog::onLiveUpdateToggled( bool checked )
{
// Apply and Cancel buttons make no sense when live update is on
mButtonBox->button( QDialogButtonBox::Apply )->setHidden( checked );
mButtonBox->button( QDialogButtonBox::Cancel )->setHidden( checked );
}
2 changes: 2 additions & 0 deletions src/app/qgsformannotationdialog.h
Expand Up @@ -37,6 +37,8 @@ class APP_EXPORT QgsFormAnnotationDialog: public QDialog, private Ui::QgsFormAnn
void deleteItem();
void mButtonBox_clicked( QAbstractButton *button );
void showHelp();
void onSettingsChanged();
void onLiveUpdateToggled( bool checked );
};

#endif // QGSFORMANNOTATIONDIALOG_H
23 changes: 23 additions & 0 deletions src/app/qgshtmlannotationdialog.cpp
Expand Up @@ -65,6 +65,12 @@ QgsHtmlAnnotationDialog::QgsHtmlAnnotationDialog( QgsMapCanvasAnnotationItem *it
QObject::connect( deleteButton, &QPushButton::clicked, this, &QgsHtmlAnnotationDialog::deleteItem );
mButtonBox->addButton( deleteButton, QDialogButtonBox::RejectRole );

connect( mLiveCheckBox, &QCheckBox::toggled, this, &QgsHtmlAnnotationDialog::onLiveUpdateToggled );
connect( mEmbeddedWidget, &QgsAnnotationWidget::changed, this, &QgsHtmlAnnotationDialog::onSettingsChanged );
connect( mHtmlSourceTextEdit, &QgsCodeEditorHTML::textChanged, this, &QgsHtmlAnnotationDialog::onSettingsChanged );
connect( mFileLineEdit, &QLineEdit::textChanged, this, &QgsHtmlAnnotationDialog::onSettingsChanged );
connect( mLiveCheckBox, &QCheckBox::toggled, this, &QgsHtmlAnnotationDialog::onSettingsChanged );

QgsGui::enableAutoGeometryRestore( this );
}

Expand Down Expand Up @@ -114,11 +120,13 @@ void QgsHtmlAnnotationDialog::mBrowseToolButton_clicked()
void QgsHtmlAnnotationDialog::fileRadioButtonToggled( bool checked )
{
mFileLineEdit->setEnabled( checked );
onSettingsChanged();
}

void QgsHtmlAnnotationDialog::sourceRadioButtonToggled( bool checked )
{
mHtmlSourceTextEdit->setEnabled( checked );
onSettingsChanged();
}

void QgsHtmlAnnotationDialog::deleteItem()
Expand All @@ -140,3 +148,18 @@ void QgsHtmlAnnotationDialog::showHelp()
{
QgsHelp::openHelp( QStringLiteral( "map_views/map_view.html#sec-annotations" ) );
}

void QgsHtmlAnnotationDialog::onSettingsChanged()
{
if ( mLiveCheckBox->isChecked() )
{
applySettingsToItem();
}
}

void QgsHtmlAnnotationDialog::onLiveUpdateToggled( bool checked )
{
// Apply and Cancel buttons make no sense when live update is on
mButtonBox->button( QDialogButtonBox::Apply )->setHidden( checked );
mButtonBox->button( QDialogButtonBox::Cancel )->setHidden( checked );
}
2 changes: 2 additions & 0 deletions src/app/qgshtmlannotationdialog.h
Expand Up @@ -39,6 +39,8 @@ class APP_EXPORT QgsHtmlAnnotationDialog: public QDialog, private Ui::QgsFormAnn
void fileRadioButtonToggled( bool checked );
void sourceRadioButtonToggled( bool checked );
void showHelp();
void onSettingsChanged();
void onLiveUpdateToggled( bool checked );
};

#endif // QgsHTMLAnnotationDialog_H
20 changes: 20 additions & 0 deletions src/app/qgssvgannotationdialog.cpp
Expand Up @@ -60,6 +60,11 @@ QgsSvgAnnotationDialog::QgsSvgAnnotationDialog( QgsMapCanvasAnnotationItem *item
QObject::connect( deleteButton, &QPushButton::clicked, this, &QgsSvgAnnotationDialog::deleteItem );
mButtonBox->addButton( deleteButton, QDialogButtonBox::RejectRole );

connect( mLiveCheckBox, &QCheckBox::toggled, this, &QgsSvgAnnotationDialog::onLiveUpdateToggled );
connect( mEmbeddedWidget, &QgsAnnotationWidget::changed, this, &QgsSvgAnnotationDialog::onSettingsChanged );
connect( mFileLineEdit, &QLineEdit::textChanged, this, &QgsSvgAnnotationDialog::onSettingsChanged );
connect( mLiveCheckBox, &QCheckBox::toggled, this, &QgsSvgAnnotationDialog::onSettingsChanged );

QgsGui::enableAutoGeometryRestore( this );
}

Expand Down Expand Up @@ -117,3 +122,18 @@ void QgsSvgAnnotationDialog::showHelp()
{
QgsHelp::openHelp( QStringLiteral( "map_views/map_view.html#sec-annotations" ) );
}

void QgsSvgAnnotationDialog::onSettingsChanged()
{
if ( mLiveCheckBox->isChecked() )
{
applySettingsToItem();
}
}

void QgsSvgAnnotationDialog::onLiveUpdateToggled( bool checked )
{
// Apply and Cancel buttons make no sense when live update is on
mButtonBox->button( QDialogButtonBox::Apply )->setHidden( checked );
mButtonBox->button( QDialogButtonBox::Cancel )->setHidden( checked );
}
2 changes: 2 additions & 0 deletions src/app/qgssvgannotationdialog.h
Expand Up @@ -36,6 +36,8 @@ class APP_EXPORT QgsSvgAnnotationDialog: public QDialog, private Ui::QgsFormAnno
void deleteItem();
void mButtonBox_clicked( QAbstractButton *button );
void showHelp();
void onSettingsChanged();
void onLiveUpdateToggled( bool checked );

private:
QgsSvgAnnotationDialog() = delete; //forbidden
Expand Down
23 changes: 23 additions & 0 deletions src/app/qgstextannotationdialog.cpp
Expand Up @@ -68,6 +68,13 @@ QgsTextAnnotationDialog::QgsTextAnnotationDialog( QgsMapCanvasAnnotationItem *it
QPushButton *deleteButton = new QPushButton( tr( "Delete" ) );
QObject::connect( deleteButton, &QPushButton::clicked, this, &QgsTextAnnotationDialog::deleteItem );
mButtonBox->addButton( deleteButton, QDialogButtonBox::RejectRole );


connect( mLiveCheckBox, &QCheckBox::toggled, this, &QgsTextAnnotationDialog::onLiveUpdateToggled );
connect( mLiveCheckBox, &QCheckBox::toggled, this, &QgsTextAnnotationDialog::onSettingsChanged );
connect( mEmbeddedWidget, &QgsAnnotationWidget::changed, this, &QgsTextAnnotationDialog::onSettingsChanged );
connect( mTextEdit, &QTextEdit::textChanged, this, &QgsTextAnnotationDialog::onSettingsChanged );

}

void QgsTextAnnotationDialog::showEvent( QShowEvent * )
Expand Down Expand Up @@ -138,6 +145,7 @@ void QgsTextAnnotationDialog::changeCurrentFormat()

//color
mTextEdit->setTextColor( mFontColorButton->color() );
onSettingsChanged();
}

void QgsTextAnnotationDialog::mFontColorButton_colorChanged( const QColor &color )
Expand Down Expand Up @@ -178,3 +186,18 @@ void QgsTextAnnotationDialog::showHelp()
{
QgsHelp::openHelp( QStringLiteral( "map_views/map_view.html#sec-annotations" ) );
}

void QgsTextAnnotationDialog::onSettingsChanged()
{
if ( mLiveCheckBox->isChecked() )
{
applyTextToItem();
}
}

void QgsTextAnnotationDialog::onLiveUpdateToggled( bool checked )
{
// Apply and Cancel buttons make no sense when live update is on
mButtonBox->button( QDialogButtonBox::Apply )->setHidden( checked );
mButtonBox->button( QDialogButtonBox::Cancel )->setHidden( checked );
}
2 changes: 2 additions & 0 deletions src/app/qgstextannotationdialog.h
Expand Up @@ -52,6 +52,8 @@ class APP_EXPORT QgsTextAnnotationDialog: public QDialog, private Ui::QgsTextAnn
void mButtonBox_clicked( QAbstractButton *button );
void backgroundColorChanged( const QColor &color );
void showHelp();
void onSettingsChanged();
void onLiveUpdateToggled( bool checked );
};

#endif // QGSTEXTANNOTATIONDIALOG_H
43 changes: 25 additions & 18 deletions src/ui/qgsformannotationdialogbase.ui
Expand Up @@ -14,6 +14,19 @@
<string>Form Annotation</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="3" column="0">
<widget class="QStackedWidget" name="mStackedWidget">
<widget class="QWidget" name="page"/>
<widget class="QWidget" name="page_2"/>
</widget>
</item>
<item row="1" column="0">
<widget class="QRadioButton" name="mSourceRadioButton">
<property name="text">
<string>Source</string>
</property>
</widget>
</item>
<item row="0" column="0">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
Expand All @@ -38,13 +51,7 @@
</item>
</layout>
</item>
<item row="3" column="0">
<widget class="QStackedWidget" name="mStackedWidget">
<widget class="QWidget" name="page"/>
<widget class="QWidget" name="page_2"/>
</widget>
</item>
<item row="4" column="0">
<item row="5" column="0">
<widget class="QDialogButtonBox" name="mButtonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
Expand All @@ -55,17 +62,24 @@
</widget>
</item>
<item row="2" column="0">
<widget class="QgsCodeEditorHTML" name="mHtmlSourceTextEdit"/>
<widget class="QgsCodeEditorHTML" name="mHtmlSourceTextEdit" native="true"/>
</item>
<item row="1" column="0">
<widget class="QRadioButton" name="mSourceRadioButton">
<item row="4" column="0">
<widget class="QCheckBox" name="mLiveCheckBox">
<property name="text">
<string>Source</string>
<string>Live update</string>
</property>
</widget>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>QgsCodeEditorHTML</class>
<extends>QWidget</extends>
<header>qgscodeeditorhtml.h</header>
</customwidget>
</customwidgets>
<resources/>
<connections>
<connection>
Expand Down Expand Up @@ -101,11 +115,4 @@
</hints>
</connection>
</connections>
<customwidgets>
<customwidget>
<class>QgsCodeEditorHTML</class>
<extends>QWidget</extends>
<header>qgscodeeditorhtml.h</header>
</customwidget>
</customwidgets>
</ui>
45 changes: 26 additions & 19 deletions src/ui/qgstextannotationdialogbase.ui
Expand Up @@ -6,14 +6,36 @@
<rect>
<x>0</x>
<y>0</y>
<width>519</width>
<width>551</width>
<height>364</height>
</rect>
</property>
<property name="windowTitle">
<string>Annotation Text</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="1" column="0">
<widget class="QTextEdit" name="mTextEdit"/>
</item>
<item row="2" column="0">
<widget class="QStackedWidget" name="mStackedWidget">
<property name="currentIndex">
<number>0</number>
</property>
<widget class="QWidget" name="page"/>
<widget class="QWidget" name="page_2"/>
</widget>
</item>
<item row="4" column="0">
<widget class="QDialogButtonBox" name="mButtonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Apply|QDialogButtonBox::Cancel|QDialogButtonBox::Help|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
<item row="0" column="0">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
Expand Down Expand Up @@ -92,27 +114,12 @@
</layout>
</item>
<item row="3" column="0">
<widget class="QDialogButtonBox" name="mButtonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Apply|QDialogButtonBox::Cancel|QDialogButtonBox::Help|QDialogButtonBox::Ok</set>
<widget class="QCheckBox" name="mLiveCheckBox">
<property name="text">
<string>Live update</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QTextEdit" name="mTextEdit"/>
</item>
<item row="2" column="0">
<widget class="QStackedWidget" name="mStackedWidget">
<property name="currentIndex">
<number>0</number>
</property>
<widget class="QWidget" name="page"/>
<widget class="QWidget" name="page_2"/>
</widget>
</item>
</layout>
</widget>
<customwidgets>
Expand Down

0 comments on commit 7ff9b7c

Please sign in to comment.