File indexing completed on 2024-05-19 05:05:20

0001 /***************************************************************************
0002  *   SPDX-License-Identifier: GPL-2.0-or-later
0003  *                                                                         *
0004  *   SPDX-FileCopyrightText: 2004-2023 Thomas Fischer <fischer@unix-ag.uni-kl.de>
0005  *                                                                         *
0006  *   This program is free software; you can redistribute it and/or modify  *
0007  *   it under the terms of the GNU General Public License as published by  *
0008  *   the Free Software Foundation; either version 2 of the License, or     *
0009  *   (at your option) any later version.                                   *
0010  *                                                                         *
0011  *   This program is distributed in the hope that it will be useful,       *
0012  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
0013  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
0014  *   GNU General Public License for more details.                          *
0015  *                                                                         *
0016  *   You should have received a copy of the GNU General Public License     *
0017  *   along with this program; if not, see <https://www.gnu.org/licenses/>. *
0018  ***************************************************************************/
0019 
0020 #ifndef KBIBTEX_DATA_COMMENT_H
0021 #define KBIBTEX_DATA_COMMENT_H
0022 
0023 #include <Element>
0024 #include <Preferences>
0025 #ifdef HAVE_KF
0026 #include "kbibtexdata_export.h"
0027 #endif // HAVE_KF
0028 
0029 /**
0030  * This class represents a comment in a BibTeX file. In BibTeX files,
0031  * everything that cannot be interpreted as a BibTeX comment is see
0032  * as a comment. Alternatively, the comment command can be used in BibTeX
0033  * files.
0034  * @author Thomas Fischer <fischer@unix-ag.uni-kl.de>
0035  */
0036 class KBIBTEXDATA_EXPORT Comment : public Element
0037 {
0038 public:
0039     /**
0040      * Create a new comment with a given text.
0041      * @param text comment's textual content
0042      * @param useCommand mark this comment to use BibTeX's comment command
0043      */
0044     explicit Comment(const QString &text, Preferences::CommentContext context, const QString &prefix = QString());
0045 
0046     /**
0047      * Copy constructor cloning another comment object.
0048      * @param other comment object to clone
0049      */
0050     Comment(const Comment &other);
0051 
0052     ~Comment() override;
0053 
0054     /**
0055      * Assignment operator, working similar to a copy constructor,
0056      * but overwrites the current object's values.
0057      */
0058     Comment &operator= (const Comment &other);
0059 
0060     /**
0061      * Retrieve the text of this comment with out the prefix in case the context is 'Prefix'.
0062      * @return text of this comment
0063      */
0064     QString text() const;
0065 
0066     /**
0067      * Set the text of this comment (without the prefix in case the context is 'Prefix').
0068      * @param text text of this comment
0069      */
0070     void setText(const QString &text);
0071 
0072     /**
0073      * Retrieve the context of this comment
0074      * @return context of this comment
0075      */
0076     Preferences::CommentContext context() const;
0077 
0078     /**
0079      * Set the context of this comment
0080      * @param context the context to use for this comment
0081      */
0082     void setContext(const Preferences::CommentContext context);
0083 
0084     /**
0085      * Set the prefix of this comment.
0086      * Invoking this function will change this comment's prefix to 'Prefix'.
0087      * @param prefix the prefix to use for this comment
0088      */
0089     void setPrefix(const QString &prefix);
0090 
0091     /**
0092      * Retrieve the prefix of this comment.
0093      * If the prefix uses another prefix, this function will return QString().
0094      * @return prefix of this comment
0095      */
0096     QString prefix() const;
0097 
0098     /**
0099      * Cheap and fast test if another Element is a Comment object.
0100      * @param other another Element object to test
0101      * @return true if Element is actually a Comment
0102      */
0103     static bool isComment(const Element &other);
0104 
0105     bool operator==(const Comment &other) const;
0106     bool operator!=(const Comment &other) const;
0107 
0108 private:
0109     class Private;
0110     Private *const d;
0111 };
0112 
0113 KBIBTEXDATA_EXPORT QDebug operator<<(QDebug dbg, const Comment &comment);
0114 
0115 #endif // KBIBTEX_DATA_COMMENT_H