![]() |
XML Mill
1.0.0
A GUI based XML editor with a memory.
|
The main application window class. More...
#include <gcmainwindow.h>
Public Member Functions | |
GCMainWindow (QWidget *parent=0) | |
Constructor. | |
~GCMainWindow () | |
Destructor. | |
Protected Member Functions | |
void | closeEvent (QCloseEvent *event) |
Re-implemented from QMainWindow. | |
Private Slots | |
void | initialise () |
Triggered as soon as the main event loop is entered (via a connection to a single shot timer in the constructor). | |
void | elementChanged (GCTreeWidgetItem *item, int column) |
Connected to the UI tree widget's "gcCurrentItemChanged( GCTreeWidgetItem*, int )" signal. | |
void | elementSelected (GCTreeWidgetItem *item, int column) |
Connected to the UI tree widget's "gcCurrentItemSelected( GCTreeWidgetItem*, int )" signal. | |
void | attributeChanged (QTableWidgetItem *tableItem) |
Connected to the UI table widget's "itemChanged( QTableWidgetItem* )" signal. | |
void | attributeSelected (QTableWidgetItem *tableItem) |
Connected to the UI table widget's "itemClicked( QTableWidgetItem* )" signal. | |
void | attributeValueChanged (const QString &value) |
Connected to GCComboBox's "currentIndexChanged( QString )" signal. | |
void | setCurrentComboBox (QWidget *combo) |
Connected to the signal mapper's "mapped( QWidget* )" signal which is emitted every time a GCComboBox is activated (whenever the user enters or otherwise activates a combo box). | |
bool | openXMLFile () |
Triggered whenever the user decides to open an XML file. | |
void | newXMLFile () |
Triggered whenever the user decides to create a new XML file. | |
bool | saveXMLFile () |
Triggered whenever the user explicitly saves the current document and also for scenarios where saving the file is implied/logical (generally preceded by a query to the user to confirm the file save operation). | |
bool | saveXMLFileAs () |
Triggered whenever the user explicitly wishes to save the current document with a specific name and also whenever the file save operation is requested without an active document name. | |
void | closeXMLFile () |
Triggered whenever the user explicitly wishes to close the current document. | |
void | saveTempFile () |
Saves a temporary file at 5 min intervals (when an active file is being edited) for auto-recovery purposes. | |
void | importXMLFromFile () |
Triggered by the "Import XML to Profile" UI action. | |
void | addNewDatabase () |
Triggered by the "Add New Profile" UI action. | |
void | addExistingDatabase () |
Triggered by the "Add Existing Profile" UI action. | |
void | removeDatabase () |
Triggered by the "Remove Profile" UI action. | |
void | switchActiveDatabase () |
Triggered by the "Switch Profile" UI action. | |
void | activeDatabaseChanged (QString dbName) |
Connected to GCDBSessionManager's "activeDatabaseChanged( QString )" signal. | |
void | addElementToDocument () |
Connected to the "Add Element" button's "clicked()" signal. | |
void | addSnippetToDocument () |
Connected to the "Add Snippet" button's "clicked()" signal. | |
void | insertSnippet (GCTreeWidgetItem *treeItem, QDomElement element) |
Connected to the GCAddSnippetsForm's "snippetAdded()" signal. | |
void | removeItemsFromDB () |
Triggered by the "Remove Items" UI action. | |
void | addItemsToDB () |
Triggered by the "Add Items" UI action. | |
void | searchDocument () |
Connected to the "Find in Document" UI action. | |
void | itemFound (GCTreeWidgetItem *item) |
Connected to GCSearchForm's "foundItem" signal. | |
void | commentOut (const QList< int > &indices, const QString &comment) |
Connected to GCPlainTextEdit's "commentOut" signal. | |
void | rebuild () |
Connected to GCPlainTextEdit's "manualEditAccepted()" signal. | |
void | updateComment (const QString &comment) |
Connected to the comment line edit's "textEdited" signal, this updates the active comment node's value to "comment". | |
void | collapseOrExpandTreeWidget (bool checked) |
Connectd to the "Expand All" checkbox's "clicked( bool )" signal. | |
void | uncheckExpandAll () |
Unchecks the "Expand All" checkbox as soon as any of the tree items are collapsed. | |
void | forgetMessagePreferences () |
Connected to the "Forget Message Preferences" UI action. | |
void | createSpinner () |
Creates and displays a "loading" style spinner for use during expensive operations. | |
void | resetDOM () |
Resets the DOM and DOM related flags and cleans and clears all maps containing DOM element information. | |
void | showEmptyProfileHelp () |
Triggered when the "empty profile help" button is clicked. | |
void | showElementHelp () |
Displays a brief message about adding elements to a document. | |
void | showMainHelp () |
Connected to the "Help Contents" action. | |
void | setShowHelpButtons (bool show) |
Decides whether or not to display help buttons throughout the entire application. | |
void | setShowTreeItemsVerbose (bool verbose) |
Decides whether or not to display tree items' elements "verbose" throughout the entire application. | |
void | goToSite () |
Opens this application's website. | |
void | useDarkTheme (bool dark) |
Sets the "dark theme" style sheet on the application. | |
Private Member Functions | |
GCDBSessionManager * | createDBSessionManager () |
Creates a new GCDBSessionManager and connects its signals to the relevant slots. | |
void | processDOMDoc () |
Kicks off a recursive DOM tree traversal to populate the tree widget and element maps with the information contained in the active DOM document. | |
void | setStatusBarMessage (const QString &message) |
Displays a message in the status bar. | |
void | setTextEditContent (GCTreeWidgetItem *item=0) |
Displays the DOM document's content in the text edit area. | |
void | highlightTextElement (GCTreeWidgetItem *item) |
Highlights the currently active DOM element in the text edit area. | |
void | insertEmptyTableRow () |
Creates an additional empty table row each time the table widget is populated so that the user may add new attributes to the active element. | |
void | resetTableWidget () |
Cleans up and clears the table widget. | |
void | startSaveTimer () |
Starts the timer responsible for the automatic saving of the current document. | |
void | toggleAddElementWidgets () |
Activates or deactivates the add element combo box and buttons when the profile is empty or when the active element doesn't have first level children. | |
void | querySetActiveSession (QString reason) |
Prompts the user to select a DB for the current session. | |
void | readSettings () |
Reads the saved window state, geometry and theme settings from the registry/XML/ini file. | |
void | saveSettings () |
Saves the window state, geometry and theme settings to the registry/XML/ini file. | |
bool | queryResetDOM (const QString &resetReason) |
Called whenever an action may or will reset the DOM document and prompts the user to confirm that it's OK to do so (if not, the action won't be completed). | |
bool | importXMLToDatabase () |
Imports the DOM content to the active database. | |
void | deleteSpinner () |
Deletes the "busy loading" spinner. | |
void | queryRestoreFiles () |
If temporary files exist, it may be that the application (unlikely) or Windows (more likely) crashed while the user was working on a file. | |
void | deleteTempFile () |
Delete the auto-recover temporary file every time the user changes or explicitly saves the active file. | |
Private Attributes | |
Ui::GCMainWindow * | ui |
QSignalMapper * | m_signalMapper |
QTableWidgetItem * | m_activeAttribute |
QWidget * | m_currentCombo |
QTimer * | m_saveTimer |
QLabel * | m_activeProfileLabel |
QLabel * | m_progressLabel |
QMovie * | m_spinner |
QString | m_currentXMLFileName |
QString | m_activeAttributeName |
bool | m_wasTreeItemActivated |
bool | m_newAttributeAdded |
bool | m_busyImporting |
bool | m_fileContentsChanged |
QHash< QWidget *, int > | m_comboBoxes |
The main application window class.
All the code refers to "databases" whereas all the user prompts reference "profiles". This is deliberate. In reality, everything is persisted to SQLite database files, but a friend suggested that end users may be intimidated by the use of the word "database" (especially if they aren't necessarily technically inclined) and that "profile" may be less scary... I agreed :)
Definition at line 82 of file gcmainwindow.h.
GCMainWindow::GCMainWindow | ( | QWidget * | parent = 0 | ) | [explicit] |
Constructor.
Definition at line 75 of file gcmainwindow.cpp.
Destructor.
Definition at line 158 of file gcmainwindow.cpp.
void GCMainWindow::activeDatabaseChanged | ( | QString | dbName | ) | [private, slot] |
Connected to GCDBSessionManager's "activeDatabaseChanged( QString )" signal.
Definition at line 866 of file gcmainwindow.cpp.
void GCMainWindow::addElementToDocument | ( | ) | [private, slot] |
Connected to the "Add Element" button's "clicked()" signal.
This function adds the new element (selected in the combo box) as a child to the current element or as a sibling in the case where the element of the same name and with the square bracket syntax is selected in the combo. In other words, if the current element is "MyElement", then selecting "[MyElement]" from the combo will add another MyElement element as a sibling to the currently active element.
Definition at line 907 of file gcmainwindow.cpp.
void GCMainWindow::addExistingDatabase | ( | ) | [private, slot] |
Triggered by the "Add Existing Profile" UI action.
Definition at line 796 of file gcmainwindow.cpp.
void GCMainWindow::addItemsToDB | ( | ) | [private, slot] |
Triggered by the "Add Items" UI action.
This function creates and displays an instance of GCAddItemsForm to allow the user to add elements and/or attributes to the active database.
Definition at line 1026 of file gcmainwindow.cpp.
void GCMainWindow::addNewDatabase | ( | ) | [private, slot] |
Triggered by the "Add New Profile" UI action.
Definition at line 772 of file gcmainwindow.cpp.
void GCMainWindow::addSnippetToDocument | ( | ) | [private, slot] |
Connected to the "Add Snippet" button's "clicked()" signal.
This function creates and displays an instance of GCAddSnippetsForm to allow the user to add one (or more) XML snippets to the active document.
Definition at line 958 of file gcmainwindow.cpp.
void GCMainWindow::attributeChanged | ( | QTableWidgetItem * | tableItem | ) | [private, slot] |
Connected to the UI table widget's "itemChanged( QTableWidgetItem* )" signal.
This function is called when the user changes the name of an existing attribute via the table widget, or when the attribute's include/exclude state changes. The new attribute name will be persisted to the database (with the same known values of the "old" attribute) and associated with the current highlighted element. The current DOM will be updated to reflect the new attribute name instead of the one that was replaced.
Definition at line 353 of file gcmainwindow.cpp.
void GCMainWindow::attributeSelected | ( | QTableWidgetItem * | tableItem | ) | [private, slot] |
Connected to the UI table widget's "itemClicked( QTableWidgetItem* )" signal.
This function is called whenever the user selects an attribute in the table widget and keeps track of the active attribute and attribute name.
Definition at line 439 of file gcmainwindow.cpp.
void GCMainWindow::attributeValueChanged | ( | const QString & | value | ) | [private, slot] |
Connected to GCComboBox's "currentIndexChanged( QString )" signal.
Triggered whenever the current value of a combo box changes or when the user edits the content of a combo box. In the first scenario, the DOM will be updated to reflect the new value for the specific element and associated attribute, in the latter case, the edited/provided value will be persisted to the database as a known value against the current element and associated attribute if it was previously unknown.
Definition at line 447 of file gcmainwindow.cpp.
void GCMainWindow::closeEvent | ( | QCloseEvent * | event | ) | [protected] |
Re-implemented from QMainWindow.
Queries user to save before closing and saves the user's "Options" preferences to settings.
Definition at line 165 of file gcmainwindow.cpp.
void GCMainWindow::closeXMLFile | ( | ) | [private, slot] |
Triggered whenever the user explicitly wishes to close the current document.
Definition at line 694 of file gcmainwindow.cpp.
void GCMainWindow::collapseOrExpandTreeWidget | ( | bool | checked | ) | [private, slot] |
Connectd to the "Expand All" checkbox's "clicked( bool )" signal.
This slot toggles the expansion and collapse of the UI tree widget.
Definition at line 1102 of file gcmainwindow.cpp.
void GCMainWindow::commentOut | ( | const QList< int > & | indices, |
const QString & | comment | ||
) | [private, slot] |
Connected to GCPlainTextEdit's "commentOut" signal.
Removes the items with indices matching those in the parameter list from the tree as well as from the DOM document and replaces their XML with that of a comment node containing the (well-formed) "comment" string.
Definition at line 1070 of file gcmainwindow.cpp.
GCDBSessionManager * GCMainWindow::createDBSessionManager | ( | ) | [private] |
Creates a new GCDBSessionManager and connects its signals to the relevant slots.
Definition at line 1318 of file gcmainwindow.cpp.
void GCMainWindow::createSpinner | ( | ) | [private, slot] |
Creates and displays a "loading" style spinner for use during expensive operations.
The calling function is responsible for clean-up (preferably through calling deleteSpinner() ).
Definition at line 1130 of file gcmainwindow.cpp.
void GCMainWindow::deleteSpinner | ( | ) | [private] |
Deletes the "busy loading" spinner.
Definition at line 1150 of file gcmainwindow.cpp.
void GCMainWindow::deleteTempFile | ( | ) | [private] |
Delete the auto-recover temporary file every time the user changes or explicitly saves the active file.
Definition at line 1573 of file gcmainwindow.cpp.
void GCMainWindow::elementChanged | ( | GCTreeWidgetItem * | item, |
int | column | ||
) | [private, slot] |
Connected to the UI tree widget's "gcCurrentItemChanged( GCTreeWidgetItem*, int )" signal.
Definition at line 219 of file gcmainwindow.cpp.
void GCMainWindow::elementSelected | ( | GCTreeWidgetItem * | item, |
int | column | ||
) | [private, slot] |
Connected to the UI tree widget's "gcCurrentItemSelected( GCTreeWidgetItem*, int )" signal.
The trigger will populate the table widget with the names of the attributes associated with the selected item's element as well as combo boxes containing their known values. This function will also create "empty" cells and combo boxes so that the user may add new attribute names. The addition of new attributes and values will automatically be persisted to the active database.
Definition at line 234 of file gcmainwindow.cpp.
void GCMainWindow::forgetMessagePreferences | ( | ) | [private, slot] |
Connected to the "Forget Message Preferences" UI action.
This slot will reset all saved user preferences regarding user input via message dialogs and prompts.
Definition at line 1123 of file gcmainwindow.cpp.
void GCMainWindow::goToSite | ( | ) | [private, slot] |
Opens this application's website.
Definition at line 1276 of file gcmainwindow.cpp.
void GCMainWindow::highlightTextElement | ( | GCTreeWidgetItem * | item | ) | [private] |
Highlights the currently active DOM element in the text edit area.
Definition at line 1374 of file gcmainwindow.cpp.
void GCMainWindow::importXMLFromFile | ( | ) | [private, slot] |
Triggered by the "Import XML to Profile" UI action.
Definition at line 704 of file gcmainwindow.cpp.
bool GCMainWindow::importXMLToDatabase | ( | ) | [private] |
Imports the DOM content to the active database.
Definition at line 754 of file gcmainwindow.cpp.
void GCMainWindow::initialise | ( | ) | [private, slot] |
Triggered as soon as the main event loop is entered (via a connection to a single shot timer in the constructor).
This function ensures that GCDataBaseInterface is successfully initialised and prompts the user to select a database for the current session.
Definition at line 193 of file gcmainwindow.cpp.
void GCMainWindow::insertEmptyTableRow | ( | ) | [private] |
Creates an additional empty table row each time the table widget is populated so that the user may add new attributes to the active element.
Definition at line 1386 of file gcmainwindow.cpp.
void GCMainWindow::insertSnippet | ( | GCTreeWidgetItem * | treeItem, |
QDomElement | element | ||
) | [private, slot] |
Connected to the GCAddSnippetsForm's "snippetAdded()" signal.
This function updates the GUI whenever new snippets are added to the active document.
Definition at line 985 of file gcmainwindow.cpp.
void GCMainWindow::itemFound | ( | GCTreeWidgetItem * | item | ) | [private, slot] |
Connected to GCSearchForm's "foundItem" signal.
This slot sets the found item as active.
Definition at line 1061 of file gcmainwindow.cpp.
void GCMainWindow::newXMLFile | ( | ) | [private, slot] |
Triggered whenever the user decides to create a new XML file.
Definition at line 619 of file gcmainwindow.cpp.
bool GCMainWindow::openXMLFile | ( | ) | [private, slot] |
Triggered whenever the user decides to open an XML file.
Definition at line 483 of file gcmainwindow.cpp.
void GCMainWindow::processDOMDoc | ( | ) | [private] |
Kicks off a recursive DOM tree traversal to populate the tree widget and element maps with the information contained in the active DOM document.
Definition at line 1329 of file gcmainwindow.cpp.
bool GCMainWindow::queryResetDOM | ( | const QString & | resetReason | ) | [private] |
Called whenever an action may or will reset the DOM document and prompts the user to confirm that it's OK to do so (if not, the action won't be completed).
Definition at line 1195 of file gcmainwindow.cpp.
void GCMainWindow::queryRestoreFiles | ( | ) | [private] |
If temporary files exist, it may be that the application (unlikely) or Windows (more likely) crashed while the user was working on a file.
In this case, ask the user if he/she would like to recover their work.
Definition at line 1526 of file gcmainwindow.cpp.
void GCMainWindow::querySetActiveSession | ( | QString | reason | ) | [private] |
Prompts the user to select a DB for the current session.
This function is called whenever it is determined that no active session exists and will keep prompting the user until a database (profile) is selected as active.
Definition at line 1480 of file gcmainwindow.cpp.
void GCMainWindow::readSettings | ( | ) | [private] |
Reads the saved window state, geometry and theme settings from the registry/XML/ini file.
Definition at line 1493 of file gcmainwindow.cpp.
void GCMainWindow::rebuild | ( | ) | [private, slot] |
Connected to GCPlainTextEdit's "manualEditAccepted()" signal.
Rebuilds the XML hierarchy for the special occasions where a manual user edit is allowed.
Definition at line 1078 of file gcmainwindow.cpp.
void GCMainWindow::removeDatabase | ( | ) | [private, slot] |
Triggered by the "Remove Profile" UI action.
Definition at line 820 of file gcmainwindow.cpp.
void GCMainWindow::removeItemsFromDB | ( | ) | [private, slot] |
Triggered by the "Remove Items" UI action.
This function creates and displays an instance of GCRemoveItemsForm to allow the user to remove elements and/or attributes from the active database.
Definition at line 996 of file gcmainwindow.cpp.
void GCMainWindow::resetDOM | ( | ) | [private, slot] |
Resets the DOM and DOM related flags and cleans and clears all maps containing DOM element information.
Definition at line 1167 of file gcmainwindow.cpp.
void GCMainWindow::resetTableWidget | ( | ) | [private] |
Cleans up and clears the table widget.
Definition at line 1414 of file gcmainwindow.cpp.
void GCMainWindow::saveSettings | ( | ) | [private] |
Saves the window state, geometry and theme settings to the registry/XML/ini file.
Definition at line 1508 of file gcmainwindow.cpp.
void GCMainWindow::saveTempFile | ( | ) | [private, slot] |
Saves a temporary file at 5 min intervals (when an active file is being edited) for auto-recovery purposes.
Definition at line 1553 of file gcmainwindow.cpp.
bool GCMainWindow::saveXMLFile | ( | ) | [private, slot] |
Triggered whenever the user explicitly saves the current document and also for scenarios where saving the file is implied/logical (generally preceded by a query to the user to confirm the file save operation).
Definition at line 633 of file gcmainwindow.cpp.
bool GCMainWindow::saveXMLFileAs | ( | ) | [private, slot] |
Triggered whenever the user explicitly wishes to save the current document with a specific name and also whenever the file save operation is requested without an active document name.
Returns "false" when the file save operation is unsuccessful OR cancelled.
Definition at line 668 of file gcmainwindow.cpp.
void GCMainWindow::searchDocument | ( | ) | [private, slot] |
Connected to the "Find in Document" UI action.
This function creates and displays an instance of GCSearchForm to allow the user to search for specific strings in the current document.
Definition at line 1051 of file gcmainwindow.cpp.
void GCMainWindow::setCurrentComboBox | ( | QWidget * | combo | ) | [private, slot] |
Connected to the signal mapper's "mapped( QWidget* )" signal which is emitted every time a GCComboBox is activated (whenever the user enters or otherwise activates a combo box).
The active combo box is used to determine the row of the associated attribute (in the table widget), which in turn is required to determine which attribute must be updated when an attribute value changes.
Definition at line 476 of file gcmainwindow.cpp.
void GCMainWindow::setShowHelpButtons | ( | bool | show | ) | [private, slot] |
Decides whether or not to display help buttons throughout the entire application.
Definition at line 1302 of file gcmainwindow.cpp.
void GCMainWindow::setShowTreeItemsVerbose | ( | bool | verbose | ) | [private, slot] |
Decides whether or not to display tree items' elements "verbose" throughout the entire application.
Definition at line 1310 of file gcmainwindow.cpp.
void GCMainWindow::setStatusBarMessage | ( | const QString & | message | ) | [private] |
Displays a message in the status bar.
Definition at line 1357 of file gcmainwindow.cpp.
void GCMainWindow::setTextEditContent | ( | GCTreeWidgetItem * | item = 0 | ) | [private] |
Displays the DOM document's content in the text edit area.
Definition at line 1365 of file gcmainwindow.cpp.
void GCMainWindow::showElementHelp | ( | ) | [private, slot] |
Displays a brief message about adding elements to a document.
Definition at line 1238 of file gcmainwindow.cpp.
void GCMainWindow::showEmptyProfileHelp | ( | ) | [private, slot] |
Triggered when the "empty profile help" button is clicked.
This button is only shown when the active profile is empty and provides information that will help the user populate the active profile.
Definition at line 1227 of file gcmainwindow.cpp.
void GCMainWindow::showMainHelp | ( | ) | [private, slot] |
Connected to the "Help Contents" action.
Displays the main help page.
Definition at line 1254 of file gcmainwindow.cpp.
void GCMainWindow::startSaveTimer | ( | ) | [private] |
Starts the timer responsible for the automatic saving of the current document.
Definition at line 1431 of file gcmainwindow.cpp.
void GCMainWindow::switchActiveDatabase | ( | ) | [private, slot] |
Triggered by the "Switch Profile" UI action.
Definition at line 845 of file gcmainwindow.cpp.
void GCMainWindow::toggleAddElementWidgets | ( | ) | [private] |
Activates or deactivates the add element combo box and buttons when the profile is empty or when the active element doesn't have first level children.
Definition at line 1449 of file gcmainwindow.cpp.
void GCMainWindow::uncheckExpandAll | ( | ) | [private, slot] |
Unchecks the "Expand All" checkbox as soon as any of the tree items are collapsed.
Definition at line 1116 of file gcmainwindow.cpp.
void GCMainWindow::updateComment | ( | const QString & | comment | ) | [private, slot] |
Connected to the comment line edit's "textEdited" signal, this updates the active comment node's value to "comment".
This function will not execute when new comments or elements are added.
Definition at line 1095 of file gcmainwindow.cpp.
void GCMainWindow::useDarkTheme | ( | bool | dark | ) | [private, slot] |
Sets the "dark theme" style sheet on the application.
Definition at line 1283 of file gcmainwindow.cpp.