Sunday, December 30, 2012

GUI – File Operations - Actions

To start, the EditBox will be made to handle simple text files.  Once the base GUI functionality is implemented, the process of implementing a full program editor will commence .  The first file operations to implement are new, open, save, and save as.

To create an action, several lines of code are needed, plus there needs to be a QAction pointer added to the class definition for each.  The program is going to end up with a lot of actions, so a more streamlined way of handling actions was needed.

In the MainWindow class definition, an enumeration for all actions was added.  Values will be added to this enumeration for each new action implemented.  The enumeration ends with a size of value, which is used to declare an array of QAction pointers.

In the createActions() function, a simple action information structure was added containing the action enumeration value, the name, the shortcut key sequence and the status tip string of the action.  An array of these action information structures is declared and initialized.  The size of enumeration value in the action value is used to indicate the end of the array.

A loop was added to process each element in this array, creating the QAction instance, setting its shortcut key sequence and status tip.  Not all actions will have a shortcut key sequence, so for these, the key sequence is initialized to an unknown value and no key sequence will not be set for these.

Finally all the actions are connected to their associated functions.  Unfortunately, the connection call could not be included in the loop because of the Qt SIGNAL and SLOT macros and the inability to declare a function pointer that could be added to the information array.  Plus, not all connection calls are identical (the close function returns a boolean instead of nothing and the About Qt action is connected to an application function, not a MainWindow function).  For now only dummy file operation functions were added - these will be implemented next.

[commit 8958bacc2e]

No comments:

Post a Comment

All comments and feedback welcomed, whether positive or negative.
(Anonymous comments are allowed, but comments with URL links or unrelated comments will be removed.)