File indexing completed on 2024-04-14 05:44:26

0001 /*
0002  *  SPDX-FileCopyrightText: 2002-2003 Jesper K. Pedersen <blackie@kde.org>
0003  *
0004  *  SPDX-License-Identifier: LGPL-2.0-only
0005  **/
0006 
0007 #include "textregexp.h"
0008 
0009 #include <KLocalizedString>
0010 #include <KMessageBox>
0011 
0012 TextRegExp::TextRegExp(bool selected, const QString &text)
0013     : RegExp(selected)
0014 {
0015     _text = text;
0016 }
0017 
0018 bool TextRegExp::check(ErrorMap &, bool, bool)
0019 {
0020     return false;
0021 }
0022 
0023 void TextRegExp::append(const QString &str)
0024 {
0025     _text.append(str);
0026 }
0027 
0028 QDomNode TextRegExp::toXml(QDomDocument *doc) const
0029 {
0030     QDomElement top = doc->createElement(QStringLiteral("Text"));
0031     QDomText text = doc->createTextNode(_text);
0032     top.appendChild(text);
0033     return top;
0034 }
0035 
0036 bool TextRegExp::load(const QDomElement &top, const QString & /*version*/)
0037 {
0038     Q_ASSERT(top.tagName() == QStringLiteral("Text"));
0039     if (top.hasChildNodes()) {
0040         QDomNode child = top.firstChild();
0041         if (!child.isText()) {
0042             KMessageBox::error(nullptr, i18n("<p>Element <b>Text</b> did not contain any textual data.</p>"), i18n("Error While Loading From XML File"));
0043             return false;
0044         }
0045         QDomText txtNode = child.toText();
0046         _text = txtNode.data();
0047     } else {
0048         _text = QString();
0049     }
0050 
0051     return true;
0052 }
0053 
0054 bool TextRegExp::operator==(const RegExp &other) const
0055 {
0056     if (other.type() != type()) {
0057         return false;
0058     }
0059 
0060     const TextRegExp &theOther = dynamic_cast<const TextRegExp &>(other);
0061     if (text() == theOther.text()) {
0062         return true;
0063     }
0064 
0065     return false;
0066 }