document_dummy.h 6.29 KB
Newer Older
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
/* This file is part of the KDE libraries
   Copyright (C) 2001 Christoph Cullmann <cullmann@kde.org>
   Copyright (C) 2005 Dominik Haumann (dhdev@gmx.de) (documentation)

   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Library General Public
   License as published by the Free Software Foundation; either
   version 2 of the License, or (at your option) any later version.

   This library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Library General Public License for more details.

   You should have received a copy of the GNU Library General Public License
   along with this library; see the file COPYING.LIB.  If not, write to
   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
   Boston, MA 02110-1301, USA.
*/

#ifndef TEST_DOCUMENT_H
#define TEST_DOCUMENT_H

#include <KTextEditor/Document>
#include <KTextEditor/ModificationInterface>

class DummyDocument : public KTextEditor::Document
{
Michal Humpula's avatar
Michal Humpula committed
29 30
  Q_OBJECT

31 32
  public:
    DummyDocument (const QString &url = QString())
Christoph Cullmann's avatar
Christoph Cullmann committed
33
      : KTextEditor::Document(nullptr, nullptr)
34 35 36 37
      , m_name(QLatin1String("foo"))
      , m_encoding()
      , m_views()
    {
Michal Humpula's avatar
Michal Humpula committed
38 39
      setUrl(url);
      m_name = url.section(QLatin1Char('/'), -1); // some nice default to mimic the KateDocument
40 41 42
    }
    DummyDocument (const char *url) : DummyDocument(QString::fromLatin1(url)) {}

Laurent Montel's avatar
Laurent Montel committed
43
    virtual ~DummyDocument () {}
Laurent Montel's avatar
Laurent Montel committed
44
    KTextEditor::View *createView ( QWidget *, KTextEditor::MainWindow * = nullptr ) Q_DECL_OVERRIDE { return 0; }
45
    virtual KTextEditor::View *activeView() const { return 0; }
Laurent Montel's avatar
Laurent Montel committed
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
    QList<KTextEditor::View*> views() const Q_DECL_OVERRIDE { return m_views; }

    QString documentName() const Q_DECL_OVERRIDE { return m_name; }

    QString mimeType() Q_DECL_OVERRIDE { return QString(); }
    QByteArray checksum() const Q_DECL_OVERRIDE { return QByteArray(); }
    bool setEncoding (const QString &) Q_DECL_OVERRIDE { return false; }
    QString encoding () const Q_DECL_OVERRIDE { return m_encoding; }

    bool documentReload () Q_DECL_OVERRIDE { return true; }
    bool documentSave () Q_DECL_OVERRIDE { return true; }
    bool documentSaveAs () Q_DECL_OVERRIDE { return true; }

    bool isEditingTransactionRunning() const Q_DECL_OVERRIDE { return false; }
    QString text () const Q_DECL_OVERRIDE { return QString(); }
    QString text ( const KTextEditor::Range&, bool = false ) const Q_DECL_OVERRIDE { return QString(); }
    QChar characterAt( const KTextEditor::Cursor&) const Q_DECL_OVERRIDE { return QChar(); }
    QString wordAt(const KTextEditor::Cursor&) const Q_DECL_OVERRIDE { return QString(); }
    KTextEditor::Range wordRangeAt(const KTextEditor::Cursor&) const Q_DECL_OVERRIDE { return KTextEditor::Range(); }
    bool isValidTextPosition(const KTextEditor::Cursor&) const Q_DECL_OVERRIDE { return true; }
    QStringList textLines ( const KTextEditor::Range&, bool = false ) const Q_DECL_OVERRIDE { return QStringList(); }
    QString line ( int ) const Q_DECL_OVERRIDE { return QString(); }
    int lines () const Q_DECL_OVERRIDE { return 0; }
    KTextEditor::Cursor documentEnd() const Q_DECL_OVERRIDE { return KTextEditor::Cursor(); }
    int totalCharacters() const Q_DECL_OVERRIDE { return 0; }
    int lineLength ( int ) const Q_DECL_OVERRIDE { return 0; }

    bool setText ( const QString & ) Q_DECL_OVERRIDE { return false; }
    bool setText ( const QStringList & ) Q_DECL_OVERRIDE { return false; }
    bool clear () Q_DECL_OVERRIDE { return true; }
    bool insertText ( const KTextEditor::Cursor &, const QString &, bool = false ) Q_DECL_OVERRIDE { return false; }
    bool insertText ( const KTextEditor::Cursor &, const QStringList &, bool = false ) Q_DECL_OVERRIDE { return false; }
    bool removeText ( const KTextEditor::Range &, bool = false ) Q_DECL_OVERRIDE { return false; }
    bool insertLine ( int, const QString & ) Q_DECL_OVERRIDE { return false; }
    bool insertLines ( int, const QStringList & ) Q_DECL_OVERRIDE { return false; }
    bool removeLine ( int ) Q_DECL_OVERRIDE { return false; }
    KTextEditor::DefaultStyle defaultStyleAt(const KTextEditor::Cursor &) const Q_DECL_OVERRIDE { return KTextEditor::dsNormal; }
    QString mode() const Q_DECL_OVERRIDE { return QString(); }
    QString highlightingMode() const Q_DECL_OVERRIDE { return QString(); }
    QStringList modes() const Q_DECL_OVERRIDE { return QStringList(); }
    QStringList highlightingModes() const Q_DECL_OVERRIDE {return QStringList(); }
    bool setMode(const QString &) Q_DECL_OVERRIDE { return false; }
    bool setHighlightingMode(const QString &) Q_DECL_OVERRIDE { return false; }
    QString highlightingModeSection( int ) const Q_DECL_OVERRIDE { return QString(); }
    QString modeSection( int ) const Q_DECL_OVERRIDE { return QString(); }
    bool print() Q_DECL_OVERRIDE { return false; }
    void printPreview() Q_DECL_OVERRIDE {}
    QStringList embeddedHighlightingModes() const Q_DECL_OVERRIDE { return QStringList(); }
    QString highlightingModeAt(const KTextEditor::Cursor &) Q_DECL_OVERRIDE { return QString(); }
    bool isLineModified(int) const Q_DECL_OVERRIDE { return false; }
    bool isLineSaved(int) const Q_DECL_OVERRIDE { return false; }
    bool isLineTouched(int) const Q_DECL_OVERRIDE { return false; }
98 99

    // KParts::ReadWritePart
Laurent Montel's avatar
Laurent Montel committed
100
    bool saveFile() Q_DECL_OVERRIDE { return false; }
101

Michal Humpula's avatar
Michal Humpula committed
102 103 104 105
  // make QObject happy
  Q_SIGNALS:
    void modifiedOnDisk(KTextEditor::Document*, bool, KTextEditor::ModificationInterface::ModifiedOnDiskReason);

Michal Humpula's avatar
Michal Humpula committed
106 107 108
  public:
    void setUrl(const QString &url) { KParts::ReadOnlyPart::setUrl(QUrl(url)); }
    void setName(const QString &name) { m_name = name; }
109
    
Laurent Montel's avatar
Laurent Montel committed
110 111
    void readSessionConfig(const KConfigGroup &, const QSet<QString> & = QSet<QString>()) Q_DECL_OVERRIDE {}
    void writeSessionConfig(KConfigGroup &, const QSet<QString> & = QSet<QString>()) Q_DECL_OVERRIDE {}
Michal Humpula's avatar
Michal Humpula committed
112

Laurent Montel's avatar
Laurent Montel committed
113
    bool postMessage(KTextEditor::Message *) Q_DECL_OVERRIDE { return false; }
114

Laurent Montel's avatar
Laurent Montel committed
115 116 117
    bool isDataRecoveryAvailable() const Q_DECL_OVERRIDE { return false; }
    void recoverData() Q_DECL_OVERRIDE {}
    void discardDataRecovery() Q_DECL_OVERRIDE {}
118

Michal Humpula's avatar
Michal Humpula committed
119 120 121
  private:
    QString m_name, m_encoding;
    QList<KTextEditor::View*> m_views;
122 123 124 125 126 127
};

#endif

// kate: space-indent on; indent-width 2; replace-tabs on;