/
qgsdecorationcopyrightdialog.cpp
134 lines (115 loc) · 5.41 KB
/
qgsdecorationcopyrightdialog.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
/***************************************************************************
* Copyright (C) 2003 by Tim Sutton *
* tim@linfiniti.com *
* *
* This is a plugin generated from the QGIS plugin template *
* *
* 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 "qgsdecorationcopyrightdialog.h"
#include "qgsdecorationcopyright.h"
#include "qgisapp.h"
#include "qgsexpression.h"
#include "qgsexpressionbuilderdialog.h"
#include "qgsexpressioncontext.h"
#include "qgshelp.h"
#include "qgsmapcanvas.h"
#include "qgssettings.h"
//qt includes
#include <QColorDialog>
#include <QColor>
#include <QFont>
#include <QDialogButtonBox>
#include <QPushButton>
QgsDecorationCopyrightDialog::QgsDecorationCopyrightDialog( QgsDecorationCopyright &deco, QWidget *parent )
: QDialog( parent )
, mDeco( deco )
{
setupUi( this );
connect( buttonBox, &QDialogButtonBox::accepted, this, &QgsDecorationCopyrightDialog::buttonBox_accepted );
connect( buttonBox, &QDialogButtonBox::rejected, this, &QgsDecorationCopyrightDialog::buttonBox_rejected );
connect( mInsertExpressionButton, &QPushButton::clicked, this, &QgsDecorationCopyrightDialog::mInsertExpressionButton_clicked );
connect( buttonBox, &QDialogButtonBox::helpRequested, this, &QgsDecorationCopyrightDialog::showHelp );
QgsSettings settings;
restoreGeometry( settings.value( QStringLiteral( "Windows/DecorationCopyright/geometry" ) ).toByteArray() );
QPushButton *applyButton = buttonBox->button( QDialogButtonBox::Apply );
connect( applyButton, &QAbstractButton::clicked, this, &QgsDecorationCopyrightDialog::apply );
grpEnable->setChecked( mDeco.enabled() );
// label text
txtCopyrightText->setAcceptRichText( false );
if ( !mDeco.enabled() && mDeco.mLabelText.isEmpty() )
{
QDate now = QDate::currentDate();
QString defaultString = QStringLiteral( "%1 %2 %3" ).arg( QChar( 0x00A9 ), QgsProject::instance()->metadata().author(), now.toString( QStringLiteral( "yyyy" ) ) );
txtCopyrightText->setPlainText( defaultString );
}
else
{
txtCopyrightText->setPlainText( mDeco.mLabelText );
}
// placement
cboPlacement->addItem( tr( "Top Left" ), QgsDecorationItem::TopLeft );
cboPlacement->addItem( tr( "Top Center" ), QgsDecorationItem::TopCenter );
cboPlacement->addItem( tr( "Top Right" ), QgsDecorationItem::TopRight );
cboPlacement->addItem( tr( "Bottom Left" ), QgsDecorationItem::BottomLeft );
cboPlacement->addItem( tr( "Bottom Center" ), QgsDecorationItem::BottomCenter );
cboPlacement->addItem( tr( "Bottom Right" ), QgsDecorationItem::BottomRight );
cboPlacement->setCurrentIndex( cboPlacement->findData( mDeco.placement() ) );
spnHorizontal->setValue( mDeco.mMarginHorizontal );
spnVertical->setValue( mDeco.mMarginVertical );
wgtUnitSelection->setUnits( QgsUnitTypes::RenderUnitList() << QgsUnitTypes::RenderMillimeters << QgsUnitTypes::RenderPercentage << QgsUnitTypes::RenderPixels );
wgtUnitSelection->setUnit( mDeco.mMarginUnit );
// font settings
mButtonFontStyle->setDialogTitle( tr( "Copyright Label Text Format" ) );
mButtonFontStyle->setMapCanvas( QgisApp::instance()->mapCanvas() );
mButtonFontStyle->setTextFormat( mDeco.textFormat() );
}
QgsDecorationCopyrightDialog::~QgsDecorationCopyrightDialog()
{
QgsSettings settings;
settings.setValue( QStringLiteral( "Windows/DecorationCopyright/geometry" ), saveGeometry() );
}
void QgsDecorationCopyrightDialog::buttonBox_accepted()
{
apply();
accept();
}
void QgsDecorationCopyrightDialog::buttonBox_rejected()
{
reject();
}
void QgsDecorationCopyrightDialog::mInsertExpressionButton_clicked()
{
QString selText = txtCopyrightText->textCursor().selectedText();
// edit the selected expression if there's one
if ( selText.startsWith( QLatin1String( "[%" ) ) && selText.endsWith( QLatin1String( "%]" ) ) )
selText = selText.mid( 2, selText.size() - 4 );
QgsExpressionBuilderDialog exprDlg( nullptr, selText, this, QStringLiteral( "generic" ), QgisApp::instance()->mapCanvas()->mapSettings().expressionContext() );
exprDlg.setWindowTitle( QObject::tr( "Insert Expression" ) );
if ( exprDlg.exec() == QDialog::Accepted )
{
QString expression = exprDlg.expressionText();
if ( !expression.isEmpty() )
{
txtCopyrightText->insertPlainText( "[%" + expression + "%]" );
}
}
}
void QgsDecorationCopyrightDialog::apply()
{
mDeco.setTextFormat( mButtonFontStyle->textFormat() );
mDeco.mLabelText = txtCopyrightText->toPlainText();
mDeco.setPlacement( static_cast< QgsDecorationItem::Placement>( cboPlacement->currentData().toInt() ) );
mDeco.mMarginUnit = wgtUnitSelection->unit();
mDeco.mMarginHorizontal = spnHorizontal->value();
mDeco.mMarginVertical = spnVertical->value();
mDeco.setEnabled( grpEnable->isChecked() );
mDeco.update();
}
void QgsDecorationCopyrightDialog::showHelp()
{
QgsHelp::openHelp( QStringLiteral( "introduction/general_tools.html#copyright-label" ) );
}