QGIS API Documentation 4.3.0-Master (d57cc4a041c)
Loading...
Searching...
No Matches
qgsacademicreference.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsacademicreference.cpp
3 -------------------
4 begin : August 2026
5 copyright : (C) 2026 by Nyall Dawson
6 email : nyall dot dawson at gmail dot com
7 ***************************************************************************/
8
9/***************************************************************************
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 ***************************************************************************/
17
19
20#include <QString>
21
22using namespace Qt::StringLiterals;
23
24QgsAcademicReference QgsAcademicReference::createBook( const QStringList &authors, int year, const QString &title, const QString &publisher )
25{
26 QgsAcademicReference reference;
28 reference.setAuthors( authors );
29 reference.setYear( year );
30 reference.setTitle( title );
31 reference.setPublisher( publisher );
32 return reference;
33}
34
36 const QStringList &authors, int year, const QString &title, const QString &journal, const QString &volume, const QString &issue, const QString &pages
37)
38{
39 QgsAcademicReference reference;
41 reference.setAuthors( authors );
42 reference.setYear( year );
43 reference.setTitle( title );
44 reference.setJournal( journal );
45 reference.setVolume( volume );
46 reference.setIssue( issue );
47 reference.setPages( pages );
48 return reference;
49}
50
51QgsAcademicReference QgsAcademicReference::createPresentation( const QStringList &authors, int year, const QString &title, const QString &meeting, const QString &publisher, const QString &pages )
52{
53 QgsAcademicReference reference;
55 reference.setAuthors( authors );
56 reference.setYear( year );
57 reference.setTitle( title );
58 reference.setJournal( meeting );
59 reference.setPublisher( publisher );
60 reference.setPages( pages );
61 return reference;
62}
63
64QgsAcademicReference QgsAcademicReference::createWebPage( const QStringList &authors, int year, const QString &title, const QString &url )
65{
66 QgsAcademicReference reference;
68 reference.setAuthors( authors );
69 reference.setYear( year );
70 reference.setTitle( title );
71 reference.setUrl( url );
72 return reference;
73}
74
75QgsAcademicReference QgsAcademicReference::createPreprint( const QStringList &authors, int year, const QString &title, const QString &repository, const QString &url )
76{
77 QgsAcademicReference reference;
79 reference.setAuthors( authors );
80 reference.setYear( year );
81 reference.setTitle( title );
82 reference.setJournal( repository );
83 reference.setUrl( url );
84 return reference;
85}
86
91
96
98{
99 return mAuthors;
100}
101
103{
104 mAuthors = authors;
105}
106
108{
109 return mYear;
110}
111
113{
114 mYear = year;
115}
116
118{
119 return mTitle;
120}
121
123{
124 mTitle = title;
125}
126
128{
129 return mJournal;
130}
131
133{
134 mJournal = journal;
135}
136
138{
139 return mVolume;
140}
141
143{
144 mVolume = volume;
145}
146
148{
149 return mIssue;
150}
151
153{
154 mIssue = issue;
155}
156
158{
159 return mPages;
160}
161
163{
164 mPages = pages;
165}
166
168{
169 return mPublisher;
170}
171
173{
174 mPublisher = publisher;
175}
176
178{
179 return mUrl;
180}
181
182void QgsAcademicReference::setUrl( const QString &url )
183{
184 mUrl = url;
185}
186
188{
189 return formatted( false );
190}
191
193{
194 return formatted( true );
195}
196
197QString QgsAcademicReference::formatted( bool asHtml ) const
198{
199 QString formattedReference;
200
201 if ( !mAuthors.isEmpty() )
202 {
203 if ( mAuthors.size() == 1 )
204 {
205 formattedReference += mAuthors.first();
206 }
207 else if ( mAuthors.size() == 2 )
208 {
209 formattedReference += mAuthors.at( 0 ) + u" & "_s + mAuthors.at( 1 );
210 }
211 else
212 {
213 for ( int index = 0; index < mAuthors.size(); ++index )
214 {
215 if ( index > 0 )
216 {
217 if ( index == mAuthors.size() - 1 )
218 {
219 formattedReference += ", & "_L1;
220 }
221 else
222 {
223 formattedReference += ", "_L1;
224 }
225 }
226 formattedReference += mAuthors.at( index );
227 }
228 }
229
230 if ( !formattedReference.endsWith( '.' ) )
231 {
232 formattedReference += '.'_L1;
233 }
234 }
235
236 if ( mYear > 0 )
237 {
238 formattedReference += u" ("_s + QString::number( mYear ) + u")."_s;
239 }
240
241 if ( !mTitle.isEmpty() )
242 {
243 if ( !formattedReference.isEmpty() )
244 {
245 formattedReference += ' '_L1;
246 }
247 formattedReference += mTitle;
248 if ( !formattedReference.endsWith( '.' ) )
249 {
250 formattedReference += '.'_L1;
251 }
252 }
253
254 if ( !mJournal.isEmpty() )
255 {
256 if ( !formattedReference.isEmpty() )
257 {
258 formattedReference += ' '_L1;
259 }
260
261 const QString journalText = asHtml ? u"<i>%1</i>"_s.arg( mJournal ) : mJournal;
262 formattedReference += journalText;
263
264 if ( !mVolume.isEmpty() )
265 {
266 const QString volumeText = asHtml ? u"<i>%1</i>"_s.arg( mVolume ) : mVolume;
267 formattedReference += u" "_s + volumeText;
268 }
269
270 if ( !mIssue.isEmpty() )
271 {
272 formattedReference += u"("_s + mIssue + u")"_s;
273 }
274
275 if ( !mPages.isEmpty() )
276 {
277 formattedReference += u", "_s + mPages;
278 }
279
280 formattedReference += '.'_L1;
281 }
282 else
283 {
284 if ( !mPublisher.isEmpty() )
285 {
286 if ( !formattedReference.isEmpty() )
287 {
288 formattedReference += ' '_L1;
289 }
290 formattedReference += mPublisher + u"."_s;
291 }
292
293 if ( !mPages.isEmpty() )
294 {
295 if ( !formattedReference.isEmpty() )
296 {
297 formattedReference += ' '_L1;
298 }
299 formattedReference += mPages + u"."_s;
300 }
301 }
302
303 if ( !mUrl.isEmpty() )
304 {
305 if ( !formattedReference.isEmpty() )
306 {
307 formattedReference += ' '_L1;
308 }
309 if ( asHtml )
310 {
311 formattedReference += u"<a href=\"%1\">%1</a>"_s.arg( mUrl );
312 }
313 else
314 {
315 formattedReference += mUrl;
316 }
317 }
318
319 return formattedReference;
320}
AcademicReferenceType
Type of academic reference.
Definition qgis.h:5190
@ WebPage
Web page or online resource.
Definition qgis.h:5195
@ Preprint
Preprint or repository paper.
Definition qgis.h:5196
@ Presentation
Conference paper, presentation, or proceeding.
Definition qgis.h:5194
@ JournalArticle
Journal or periodical article.
Definition qgis.h:5193
QString pages() const
Returns the page numbers.
QString asPlainText() const
Returns a plain text representation of the reference (in APA style).
Qgis::AcademicReferenceType type() const
Returns the reference type.
int year() const
Returns the publication year.
QString publisher() const
Returns the publisher name.
void setVolume(const QString &volume)
Sets the volume identifier.
void setPublisher(const QString &publisher)
Sets the publisher name.
QString title() const
Returns the title of the work.
void setPages(const QString &pages)
Sets the page numbers.
void setIssue(const QString &issue)
Sets the issue number.
QgsAcademicReference()=default
Constructor for an invalid QgsAcademicReference.
QString journal() const
Returns the journal title.
void setYear(int year)
Sets the publication year.
QString url() const
Returns the URL.
QStringList authors() const
Returns the authors of the reference.
QString asHtml() const
Returns a HTML formatted representation of the reference (in APA style).
void setAuthors(const QStringList &authors)
Sets the authors of the reference.
QString issue() const
Returns the issue number.
static QgsAcademicReference createBook(const QStringList &authors, int year, const QString &title, const QString &publisher)
Creates a book reference.
static QgsAcademicReference createPresentation(const QStringList &authors, int year, const QString &title, const QString &meeting, const QString &publisher=QString(), const QString &pages=QString())
Creates a conference paper or presentation reference.
void setJournal(const QString &journal)
Sets the journal title.
void setType(Qgis::AcademicReferenceType type)
Sets the reference type.
void setUrl(const QString &url)
Sets the url.
static QgsAcademicReference createWebPage(const QStringList &authors, int year, const QString &title, const QString &url)
Creates a web page or online resource reference.
void setTitle(const QString &title)
Sets the title of the work.
static QgsAcademicReference createJournalArticle(const QStringList &authors, int year, const QString &title, const QString &journal, const QString &volume=QString(), const QString &issue=QString(), const QString &pages=QString())
Creates a journal article reference.
QString volume() const
Returns the volume identifier.
static QgsAcademicReference createPreprint(const QStringList &authors, int year, const QString &title, const QString &repository, const QString &url)
Creates a preprint reference.