22using namespace Qt::StringLiterals;
189 return formatted(
false );
194 return formatted(
true );
197QString QgsAcademicReference::formatted(
bool asHtml )
const
199 QString formattedReference;
201 if ( !mAuthors.isEmpty() )
203 if ( mAuthors.size() == 1 )
205 formattedReference += mAuthors.first();
207 else if ( mAuthors.size() == 2 )
209 formattedReference += mAuthors.at( 0 ) + u
" & "_s + mAuthors.at( 1 );
213 for (
int index = 0; index < mAuthors.size(); ++index )
217 if ( index == mAuthors.size() - 1 )
219 formattedReference +=
", & "_L1;
223 formattedReference +=
", "_L1;
226 formattedReference += mAuthors.at( index );
230 if ( !formattedReference.endsWith(
'.' ) )
232 formattedReference +=
'.'_L1;
238 formattedReference += u
" ("_s + QString::number( mYear ) + u
")."_s;
241 if ( !mTitle.isEmpty() )
243 if ( !formattedReference.isEmpty() )
245 formattedReference +=
' '_L1;
247 formattedReference += mTitle;
248 if ( !formattedReference.endsWith(
'.' ) )
250 formattedReference +=
'.'_L1;
254 if ( !mJournal.isEmpty() )
256 if ( !formattedReference.isEmpty() )
258 formattedReference +=
' '_L1;
261 const QString journalText =
asHtml ? u
"<i>%1</i>"_s.arg( mJournal ) : mJournal;
262 formattedReference += journalText;
264 if ( !mVolume.isEmpty() )
266 const QString volumeText =
asHtml ? u
"<i>%1</i>"_s.arg( mVolume ) : mVolume;
267 formattedReference += u
" "_s + volumeText;
270 if ( !mIssue.isEmpty() )
272 formattedReference += u
"("_s + mIssue + u
")"_s;
275 if ( !mPages.isEmpty() )
277 formattedReference += u
", "_s + mPages;
280 formattedReference +=
'.'_L1;
284 if ( !mPublisher.isEmpty() )
286 if ( !formattedReference.isEmpty() )
288 formattedReference +=
' '_L1;
290 formattedReference += mPublisher + u
"."_s;
293 if ( !mPages.isEmpty() )
295 if ( !formattedReference.isEmpty() )
297 formattedReference +=
' '_L1;
299 formattedReference += mPages + u
"."_s;
303 if ( !mUrl.isEmpty() )
305 if ( !formattedReference.isEmpty() )
307 formattedReference +=
' '_L1;
311 formattedReference += u
"<a href=\"%1\">%1</a>"_s.arg( mUrl );
315 formattedReference += mUrl;
319 return formattedReference;
AcademicReferenceType
Type of academic reference.
@ WebPage
Web page or online resource.
@ Preprint
Preprint or repository paper.
@ Presentation
Conference paper, presentation, or proceeding.
@ JournalArticle
Journal or periodical article.
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.