Document

class qte.Document

A class representing the state of a single document.

This framework provides methods for working with documents and files, specifically dealing with operations such as opening and saving them. The Document class should be inherited to create a new type of document, and newDocument, openDocument, saveDocument and closeDocument re-implemented. The value of hasChanged should be managed by the subclass.

Acceptable file filters are stored in the saveFilters and openFilters attributes, and are each a list of filters, e.g., ["Images (*.png *.xpm *.jpg)", "Text files (*.txt)"]

The new, open, save, saveAs and close methods of this class may be used as slots and connected to relevant actions.

Members

Properties

Document.currentPath

Return or set the path at which open and save dialogs open.

This defaults to the user home directory.

Document.ext

Return the extension of the currently opened file.

See also

name

Document.fullName

Return the full path to the currently opened file.

See also

name

Document.hasChanged

True if the document has changed since the last save.

By default, this is always True. It is up to the implementation to change it as necessary.

Document.name

Return the name of the currently opened file.

This returns the name portion of the full path. If no named file is opened, an empty string is returned. Note that an empty return value does not mean that the document is empty; a new one may be open which has not yet been saved.

Document.openFilters

A list of filters to apply to the open dialog.

Document.path

Return the folder path to the currently opened file.

See also

name

Document.saveFilters

A list of filters to apply to the save dialog.

New Methods

Document.close()

Close an open document.

This method should be used as a slot to request that the current document be closed. If there is no open document, it does nothing and returns False, otherwise it prompts for the user to save, and calls closeDocument.

True is returned on success.

Document.closeDocument()

Close an open document and return True for success.

This method should be re-implemented by subclasses and should perform the necessary operations to clear document data. Operations such as saving the document are handled prior to calling this function, so it can be assumed that it is safe to clear the data.

The default implementation does nothing and returns True.

Document.isOpen()

Return true if there is a currently open document.

Document.new()

Create a new document.

This method should be used as a slot to create a new document. If there is a document already open, it first attempts to close it using close. newDocument is called to initialise a new document. True is returned on success.

Document.newDocument()

Initialise a new, empty document and return True for success.

This method should be re-implemented by subclasses and should perform the necessary operations to create new document data. Before this is called, Document ensures that there is no open document, so document data can be assumed to be in the default state or as left by closeDocument.

The default implementation does nothing and returns True.

Document.open()

Open an existing document.

This method should be used as a slot to open an existing document. It behaves in a similar manner to new, except that it displays an open dialog with filters set by openFilters and calls openDocument to open the requested file. True is returned on success.

Document.openDocument(path)

Load a document into memory by name and return True for success.

This method should be re-implemented by subclasses and should perform the necessary operations (i.e. opening the file, locking it, etc) to load the document data from path. All GUI operations, such as querying the name are handled prior to calling this function, but no checks are made as to whether path exists or is accessible.

The default implementation does nothing and returns True.

Document.save()

Save an open document.

This method should be used as a slot to save the current document. If there is no open document, it does nothing and returns False. If the current document has a name, it is saved silently, otherwise saveAs is called. True is returned on success.

Document.saveAs()

Save an open document under a new name.

This method should be called as a slot to save the current document with a new name. If there is no open document, it does nothing and returns False. A save dialog is displayed wit filters set by new name, and saveDocument is called to write it. True is returned on success.

Document.saveDocument(path)

Save a document to disk and return True success.

This method should be re-implemented by subclasses and should perform the necessary operations to write the document data to path. All GUI operations, such as querying the name are handled prior to calling this function, but no checks are made as to whether path exists or is accessible.

The default implementation does nothing and returns True.

Signals

Document.documentOpened()
Document.documentClosed()

Project Versions

Table Of Contents

Previous topic

DateTimeEdit

Next topic

EditWidgetABC

This Page