-
-
Notifications
You must be signed in to change notification settings - Fork 3k
/
qgshtmlannotationdialog.cpp
134 lines (121 loc) · 4.46 KB
/
qgshtmlannotationdialog.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
/***************************************************************************
QgsHTMLAnnotationDialog.cpp
---------------------
begin : March 2010
copyright : (C) 2010 by Marco Hugentobler
email : marco dot hugentobler at sourcepole dot ch
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#include "qgshtmlannotationdialog.h"
#include "qgshtmlannotation.h"
#include "qgsannotationwidget.h"
#include "qgsmapcanvasannotationitem.h"
#include "qgsvectorlayer.h"
#include "qgsproject.h"
#include "qgsannotationmanager.h"
#include "qgsgui.h"
#include "qgshelp.h"
#include <QFileDialog>
#include <QFileInfo>
#include <QGraphicsScene>
#include <QPushButton>
QgsHtmlAnnotationDialog::QgsHtmlAnnotationDialog( QgsMapCanvasAnnotationItem *item, QWidget *parent, Qt::WindowFlags f )
: QDialog( parent, f )
, mItem( item )
{
setupUi( this );
connect( mBrowseToolButton, &QToolButton::clicked, this, &QgsHtmlAnnotationDialog::mBrowseToolButton_clicked );
connect( mButtonBox, &QDialogButtonBox::clicked, this, &QgsHtmlAnnotationDialog::mButtonBox_clicked );
setWindowTitle( tr( "HTML Annotation" ) );
mEmbeddedWidget = new QgsAnnotationWidget( mItem );
mStackedWidget->addWidget( mEmbeddedWidget );
mStackedWidget->setCurrentWidget( mEmbeddedWidget );
if ( item && item->annotation() )
{
QgsHtmlAnnotation *annotation = static_cast< QgsHtmlAnnotation * >( item->annotation() );
const QString file = annotation->sourceFile();
if ( !file.isEmpty() )
{
mFileLineEdit->setText( file );
mFileRadioButton->setChecked( true );
}
else
{
mHtmlSourceTextEdit->setText( annotation->htmlSource() );
mSourceRadioButton->setChecked( true );
}
}
QObject::connect( mButtonBox, &QDialogButtonBox::accepted, this, &QgsHtmlAnnotationDialog::applySettingsToItem );
QObject::connect( mButtonBox, &QDialogButtonBox::helpRequested, this, &QgsHtmlAnnotationDialog::showHelp );
QPushButton *deleteButton = new QPushButton( tr( "Delete" ) );
QObject::connect( deleteButton, &QPushButton::clicked, this, &QgsHtmlAnnotationDialog::deleteItem );
mButtonBox->addButton( deleteButton, QDialogButtonBox::RejectRole );
QgsGui::enableAutoGeometryRestore( this );
}
void QgsHtmlAnnotationDialog::applySettingsToItem()
{
//apply settings from embedded item widget
if ( mEmbeddedWidget )
{
mEmbeddedWidget->apply();
}
if ( mItem && mItem->annotation() )
{
QgsHtmlAnnotation *annotation = static_cast< QgsHtmlAnnotation * >( mItem->annotation() );
if ( mFileRadioButton->isChecked() )
{
annotation->setSourceFile( mFileLineEdit->text() );
}
else
{
annotation->setHtmlSource( mHtmlSourceTextEdit->text() );
}
mItem->update();
}
}
void QgsHtmlAnnotationDialog::mBrowseToolButton_clicked()
{
QString directory;
const QFileInfo fi( mFileLineEdit->text() );
if ( fi.exists() )
{
directory = fi.absolutePath();
}
else
{
directory = QDir::homePath();
}
const QString filename = QFileDialog::getOpenFileName( nullptr, tr( "html" ), directory, QStringLiteral( "HTML (*.html *.htm);;All files (*.*)" ) );
mFileLineEdit->setText( filename );
}
void QgsHtmlAnnotationDialog::on_mFileRadioButton_toggled( bool checked )
{
mFileLineEdit->setEnabled( checked );
}
void QgsHtmlAnnotationDialog::on_mSourceRadioButton_toggled( bool checked )
{
mHtmlSourceTextEdit->setEnabled( checked );
}
void QgsHtmlAnnotationDialog::deleteItem()
{
if ( mItem && mItem->annotation() )
QgsProject::instance()->annotationManager()->removeAnnotation( mItem->annotation() );
mItem = nullptr;
}
void QgsHtmlAnnotationDialog::mButtonBox_clicked( QAbstractButton *button )
{
if ( mButtonBox->buttonRole( button ) == QDialogButtonBox::ApplyRole )
{
applySettingsToItem();
}
}
void QgsHtmlAnnotationDialog::showHelp()
{
QgsHelp::openHelp( QStringLiteral( "introduction/general_tools.html#annotation-tools" ) );
}