File: document.h

package info (click to toggle)
kdevelop 4%3A22.12.2-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 70,096 kB
  • sloc: cpp: 284,635; javascript: 3,558; python: 3,422; sh: 1,319; ansic: 685; xml: 331; php: 95; lisp: 66; makefile: 39; sed: 12
file content (136 lines) | stat: -rw-r--r-- 4,196 bytes parent folder | download | duplicates (3)
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
/*
    SPDX-FileCopyrightText: 2006-2007 Alexander Dymo <adymo@kdevelop.org>

    SPDX-License-Identifier: LGPL-2.0-or-later
*/

#ifndef KDEVPLATFORM_SUBLIMEDOCUMENT_H
#define KDEVPLATFORM_SUBLIMEDOCUMENT_H

#include <QObject>
#include <QList>


#include "sublimeexport.h"

class QIcon;

class QWidget;

namespace Sublime {

class Area;
class View;
class Controller;
class DocumentPrivate;

/**
@short Abstract base class for all Sublime documents

Subclass from Document and implement createViewWidget() method
to return a new widget for a view.
*/
class KDEVPLATFORMSUBLIME_EXPORT Document: public QObject {
    Q_OBJECT
public:
    /**Creates a document and adds it to a @p controller.*/
    Document(const QString &title, Controller *controller);
    ~Document() override;

    /**@return the new view for this document.
    @note it will not create a widget, just return a view object.*/
    View *createView();
    /**@return the list of all views in all areas for this document.*/
    const QList<View*> &views() const;

    /**@return the controller for this document.*/
    Controller *controller() const;

    enum TitleType { Normal, Extended};
    /**@return the document title.*/
    virtual QString title(TitleType type = Normal) const;
    /**Set the document title.*/
    void setTitle(const QString& newTitle);
    void setToolTip(const QString& newToolTip);
    QString toolTip() const;
    /**@return the type of document which can be written to config.*/
    virtual QString documentType() const = 0;

    /**@return the specifics of this document which can be written to config.*/
    virtual QString documentSpecifier() const = 0;

    /**
     * If the document is in a state where data may be lost while closing,
     * asks the user whether he really wants to close the document.
     * 
     * This function may also take actions like saving the document before closing
     * if the user desires so.
     * 
     * @return true if the document is allowed to be closed, otherwise false.
     *
     * The default implementation always returns true.
     *
     * */
    virtual bool askForCloseFeedback();
    
    /**Should try closing the document, eventually asking the user for feedback.
      *
      *If closing is successful, all views should be deleted, and the document itself
      *be scheduled for deletion using deleteLater().
      *
      * @param silent If this is true, the user must not be asked.
      * 
      * Returns whether closing was successful (The user did not push 'Cancel') */
    virtual bool closeDocument(bool silent = false);

    void setStatusIcon(const QIcon& icon);

    /**
     * @return The status icon of the document.
     */
    QIcon statusIcon() const;

    /**
     * @return The status icon of the document, or, if none is present, an icon
     *         that resembles the document, i.e. based on its mime type.
     * @see defaultIcon()
     */
    QIcon icon() const;

    /**
     * Optionally override this to return a default icon when no status
     * icon is set for the document. The default returns an invalid icon.
     */
    virtual QIcon defaultIcon() const;

Q_SIGNALS:
    /**Emitted when the document is about to be deleted but is still in valid state.*/
    void aboutToDelete(Sublime::Document *doc);
    /**Emitted when the document's title is changed.*/
    void titleChanged(Sublime::Document *doc);
   /**Emitted when the document status-icon has changed */
    void statusIconChanged(Sublime::Document *doc);

protected:
    /**Creates and returns the new view. Reimplement in subclasses to instantiate
    views of derived from Sublime::View classes.*/
    virtual View *newView(Document *doc);
    /**Reimplement this to create and return the new widget to display
    this document in the view. This method is used by View class when it
    is asked for its widget.*/
    virtual QWidget *createViewWidget(QWidget *parent = nullptr) = 0;
    /** Closes all views associated to this document */
    virtual void closeViews();

private:
    const QScopedPointer<class DocumentPrivate> d_ptr;
    Q_DECLARE_PRIVATE(Document)

    friend class DocumentPrivate;
    friend class View;
};

}

#endif