A code editor widget which contains a CodeEditor. More...
#include <CodeEditorWidget.h>
Public Types | |
enum | ActionFlag { ActionNoHints = 1 << 0, ActionNew = 1 << 1, ActionOpenFile = 1 << 2, ActionSaveFile = 1 << 3, ActionSaveFileAs = 1 << 4, ActionPrint = 1 << 5, ActionPrintPreview = 1 << 6, ActionPrintPDF = 1 << 7, ActionUndo = 1 << 8, ActionRedo = 1 << 9, ActionCut = 1 << 10, ActionCopy = 1 << 11, ActionPaste = 1 << 12, ActionClear = 1 << 13, ActionSelectAll = 1 << 14, ActionFind = 1 << 15 } |
The possible actions that can be constructed in a code editor. More... | |
enum | DisplayFlag { NoDisplayFlagsHint = 1 << 1, Editor = 1 << 1, SearchBox = 1 << 2, ActionToolBar = 1 << 3 } |
The possible display flags of the code editor widget. More... | |
enum | FileModifiedOutsideHandlingPolicy { PromptForUpdate = 0, AutoUpdate = 1, AutoIgnore = 2, AutoIgnoreSetModified = 3 } |
Defines how the editor should handle a situation where the open file is modified outside of the editor. More... | |
enum | FileRemovedOutsideHandlingPolicy { CloseFile = 0, DeleteEditor = 1 } |
Defines how the editor should handle a situation where the open file is removed outside of the editor. More... | |
Public Types inherited from Qtilities::Core::Interfaces::IModificationNotifier | |
enum | NotificationTarget { NotifyNone = 0, NotifyListeners = 1, NotifySubjects = 2 } |
The targets which should be notified when the state of the object implementing this interface changes. More... |
Signals | |
void | fileNameChanged (const QString &new_file_name) |
Signal which is emitted as soon as the file shown in the editor changed. | |
void | modificationStateChanged (bool is_modified) const |
Implement this function as a signal when implementing the object. |
Public Member Functions | |
ActionFlags | actionFlagsHint () const |
Gets the action display flags hint. | |
IActionProvider * | actionProvider () |
Returns the action handler interface for this code editor widget. | |
void | closeFile () |
Closes the current file being edited, if any. | |
CodeEditor * | codeEditor () |
Returns the code editor contained in this code editor widget. | |
CodeEditorWidget (ActionFlags action_flags=ActionAllHints, DisplayFlags display_flags=AllDisplayFlagHint, QWidget *parent=0) | |
QString | contextHelpId () const |
Returns a help ID for this context. | |
QString | contextString () const |
Returns a context string for the context represented by this interface. | |
QString | defaultPath () const |
Gets the default path used by the code editor widget when using file dialogs. | |
DisplayFlags | displayFlagsHint () const |
Gets the current display flags hint. | |
FileModifiedOutsideHandlingPolicy | fileModifiedOutsideHandlingPolicy () const |
Gets the FileModifiedOutsideHandlingPolicy of the editor widget. | |
QString | fileName () const |
The file name linked to the contents of the code editor. | |
FileRemovedOutsideHandlingPolicy | fileRemovedOutsideHandlingPolicy () const |
Gets the FileRemovedOutsideHandlingPolicy of the editor widget. | |
void | initialize () |
Initializes the window according to the current flags. | |
bool | isModified () const |
Indicates the modification state of the object. | |
bool | loadFile (const QString &file_name) |
Loads a file into the editor. | |
QObject * | objectBase () |
Returns the QObject* base of the interface. | |
const QObject * | objectBase () const |
Returns a const QObject* base of the interface. | |
bool | saveFile (QString file_name=QString()) |
Saves the content of the editor to a file. | |
SearchBoxWidget * | searchBoxWidget () const |
Returns the search box widget of this code editor if it was constructed. | |
void | setActionFlagsHint (ActionFlags action_flags) |
Sets the current action flags hints. | |
void | setDefaultPath (const QString &file_path) |
Sets the default path used by the code editor widget when using file dialogs. | |
void | setDisplayFlagsHint (DisplayFlags display_flags) |
Sets the current display flags hints. | |
void | setFileModifiedOutsideHandlingPolicy (FileModifiedOutsideHandlingPolicy policy) |
Sets the FileModifiedOutsideHandlingPolicy of the editor widget. | |
void | setFileRemovedOutsideHandlingPolicy (FileRemovedOutsideHandlingPolicy policy) |
Sets the FileRemovedOutsideHandlingPolicy of the editor widget. | |
void | setSyntaxHighlighter (QSyntaxHighlighter *highlighter) |
Sets the syntax highlighter to be used in this code editor. | |
QSyntaxHighlighter * | syntaxHighlighter () const |
Gets the syntax highlighter used in this code editor. | |
Public Member Functions inherited from Qtilities::Core::Interfaces::IModificationNotifier | |
virtual void | setModificationState (bool new_state, NotificationTargets notification_targets=NotifyListeners, bool force_notifications=false)=0 |
Sets the modification state of the object. Returns true if it was successfull. | |
Public Member Functions inherited from Qtilities::Core::Interfaces::IObjectBase | |
QString | objectOriginID () const |
Allows interfaces to provide some sort of source identification. | |
void | setObjectOriginID (const QString &object_origin_id) |
Allows setting of the object source ID of this interface implementation. |
A code editor widget which contains a CodeEditor.
The CodeEditorWidget class is a ready to use text editor widget. It is a very convenient widget to use if you just want to display simple files to a user. For example:
The screenshot below shows the CodeEditorWidget in the MainWindowExample
in the QtilitiesExamples
project.
The CodeEditorWidget contains a search & replace box as well as a range of actions which is registered in the action manager and available through the Qtilities::CoreGui::Interfaces::IActionProvider interface. For example we can provide the user with toolbar actions to save a file and to load a file like this:
A list of available actions are defined in ActionFlag and the widget can further be customized using DisplayFlag. Since the IActionProvider
interface is implemented you can easily add new actions to the toolbars. See action_providers for more information.
The CodeEditorWidget provides a file loading interface. Through this interface you can load a file into the editor using the loadFile() function. The contents of the editor can be saved to a file using the saveFile() function. When the contents in the editor was loaded from a file through the loadFile() method, you can call saveFile() without any parameters to save the content to the file from which it was loaded. The fileName() function returns the name of this file if it was set.
Any CodeEditorWidget can easily be made part of a project using Qtilities::ProjectManagement::CodeEditorProjectItemWrapper.
The possible actions that can be constructed in a code editor.
ActionNoHints |
No actions hint. |
ActionNew |
Action to create a new document in the editor. This will clear the current file information.
|
ActionOpenFile |
Action to open a file in the editor. |
ActionSaveFile |
Action to save the editor content to a file. |
ActionSaveFileAs |
Action to prompt for a file name to save the editor content to. |
ActionPrint |
Action to print the editor content. |
ActionPrintPreview |
Action to display a print preview of the editor content. |
ActionPrintPDF |
Action to print the editor content to a PDF document. |
ActionUndo |
Action to perform an undo operation. |
ActionRedo |
Action to perform a redo operation. |
ActionCut |
Action to perform a cut operation. |
ActionCopy |
Action to perform a copy operation. |
ActionPaste |
Action to perform a paste operation. |
ActionClear |
Action to clear the content of the editor. |
ActionSelectAll |
Action to select all content in the editor. |
ActionFind |
Action to bring up the search and replace box. |
The possible display flags of the code editor widget.
Defines how the editor should handle a situation where the open file is modified outside of the editor.
Qtilities::CoreGui::CodeEditorWidget::CodeEditorWidget | ( | ActionFlags | action_flags = ActionAllHints , |
DisplayFlags | display_flags = AllDisplayFlagHint , |
||
QWidget * | parent = 0 |
||
) |
display_flags | The display flags which must be used for this code editor. |
Qtilities::CoreGui::CodeEditorWidget::ActionFlags Qtilities::CoreGui::CodeEditorWidget::actionFlagsHint | ( | ) | const |
Gets the action display flags hint.
This function was added in Qtilities v1.1.
void Qtilities::CoreGui::CodeEditorWidget::closeFile | ( | ) |
Closes the current file being edited, if any.
This function was added in Qtilities v1.1.
QString Qtilities::CoreGui::CodeEditorWidget::defaultPath | ( | ) | const |
Gets the default path used by the code editor widget when using file dialogs.
By default QtilitiesApplication::applicationSessionPath().
This function was added in Qtilities v1.1.
DisplayFlags Qtilities::CoreGui::CodeEditorWidget::displayFlagsHint | ( | ) | const |
Gets the current display flags hint.
Qtilities::CoreGui::CodeEditorWidget::FileModifiedOutsideHandlingPolicy Qtilities::CoreGui::CodeEditorWidget::fileModifiedOutsideHandlingPolicy | ( | ) | const |
Gets the FileModifiedOutsideHandlingPolicy of the editor widget.
Default is PromptForUpdate.
This function was added in Qtilities v1.2.
QString Qtilities::CoreGui::CodeEditorWidget::fileName | ( | ) | const |
The file name linked to the contents of the code editor.
This name will only be valid if loadFile() has been called.
|
signal |
Signal which is emitted as soon as the file shown in the editor changed.
This function was added in Qtilities v1.1.
Qtilities::CoreGui::CodeEditorWidget::FileRemovedOutsideHandlingPolicy Qtilities::CoreGui::CodeEditorWidget::fileRemovedOutsideHandlingPolicy | ( | ) | const |
Gets the FileRemovedOutsideHandlingPolicy of the editor widget.
Default is CloseFile.
This function was added in Qtilities v1.1.
void Qtilities::CoreGui::CodeEditorWidget::initialize | ( | ) |
Initializes the window according to the current flags.
This function was added in Qtilities v1.1.
bool Qtilities::CoreGui::CodeEditorWidget::loadFile | ( | const QString & | file_name | ) |
Loads a file into the editor.
|
virtualsignal |
Implement this function as a signal when implementing the object.
Because this interface does not use the Q_OBJECT macro, you cannot connect to this signal directly. Instead you need to connect to the signal on the base object implementing this interface as follows:
Implements Qtilities::Core::Interfaces::IModificationNotifier.
|
inlinevirtual |
Returns a const QObject* base of the interface.
This function can be used in const methods, but make sure that you don't modify things that should stay const. An example where this is used is when we want to get a property on an object in a const method. This is a const operation.
Implements Qtilities::Core::Interfaces::IObjectBase.
bool Qtilities::CoreGui::CodeEditorWidget::saveFile | ( | QString | file_name = QString() | ) |
Saves the content of the editor to a file.
file_name | The file name to which the contents must be saved. If loadFile() was already called, the file name does not need to be specified. |
void Qtilities::CoreGui::CodeEditorWidget::setActionFlagsHint | ( | ActionFlags | action_flags | ) |
Sets the current action flags hints.
This function was added in Qtilities v1.1.
void Qtilities::CoreGui::CodeEditorWidget::setDefaultPath | ( | const QString & | file_path | ) |
Sets the default path used by the code editor widget when using file dialogs.
By default QtilitiesApplication::applicationSessionPath().
This function was added in Qtilities v1.1.
void Qtilities::CoreGui::CodeEditorWidget::setDisplayFlagsHint | ( | DisplayFlags | display_flags | ) |
Sets the current display flags hints.
This function was added in Qtilities v1.1.
void Qtilities::CoreGui::CodeEditorWidget::setFileModifiedOutsideHandlingPolicy | ( | FileModifiedOutsideHandlingPolicy | policy | ) |
Sets the FileModifiedOutsideHandlingPolicy of the editor widget.
Default is PromptForUpdate.
This function was added in Qtilities v1.2.
void Qtilities::CoreGui::CodeEditorWidget::setFileRemovedOutsideHandlingPolicy | ( | FileRemovedOutsideHandlingPolicy | policy | ) |
Sets the FileRemovedOutsideHandlingPolicy of the editor widget.
Default is CloseFile.
This function was added in Qtilities v1.1.
void Qtilities::CoreGui::CodeEditorWidget::setSyntaxHighlighter | ( | QSyntaxHighlighter * | highlighter | ) |
Sets the syntax highlighter to be used in this code editor.
Qtilities : Reference Documentation | Back to top |
Copyright © 2009-2013, Jaco Naudé
|