Project Documentation Manager BRIGADOON-0002
Project Documentation Manager
Loading...
Searching...
No Matches
DatabaseManager Class Reference

Class to control the opening of the Database. More...

#include <databasemanager.h>

Inheritance diagram for DatabaseManager:
[legend]
Collaboration diagram for DatabaseManager:
[legend]

Public Slots

void ReconnectDatabase (void)
 Reconnect to the databse using the current parameters.
void LoadDefaultDBParameters (void)
 Load the default Database Paranmeters.

Signals

void SendLogEntry (REMOTE_LOG_ENTRY LogEntry)
 Send Log Entry via the Signal-Slot Method.

Public Member Functions

 DatabaseManager (Ui::MainWindow *UI_Window)
 Database Class Constructor.
 ~DatabaseManager ()
 Database Manager Deconstructor.

Private Member Functions

void LoadDatabaseDrivers (QComboBox *DriverList)
 Load the know Database Drivers.
bool Open (void)
 Open the Database witht selected parameters.
void RemoveDatabase (void)
 Remove the current active database.
bool CheckIfOpen (bool IsOpen)
 Set the Database Image based on IsOpenFlag.
void LogAdd (LOGGING_SEVERITY Severity, LOGGING_MODE Mode, QString Message)
 Send Message to the Log.

Private Attributes

Ui::MainWindow * ui
 Pointer to the Main Window.
bool is_database
 Flag to indicate if there is a database.
bool is_open
 Flag to indicate if database is open.

Detailed Description

Class to control the opening of the Database.

Definition at line 18 of file databasemanager.h.

Constructor & Destructor Documentation

◆ DatabaseManager()

DatabaseManager::DatabaseManager ( Ui::MainWindow * UI_Window)
explicit

Database Class Constructor.

Parameters
UI_WindowThe Program's main Window

Definition at line 7 of file databasemanager.cpp.

8{
9 // Save the Pointer to the Main Window & Pointer to Log
10 ui = UI_Window;
11
12 // Flag that there is no Current Database
13 is_database = false;
14 is_open = false;
15
16 // Load the Availalbe Database Drivers
17 LoadDatabaseDrivers(ui->DatabaseDriver);
18
19 // Load the Default Dataabse Parameters
21
22 QObject::connect(ui->ReconnectDatabase, SIGNAL(pressed()), this, SLOT(ReconnectDatabase()));
23 QObject::connect(ui->LoadDefaultDBParams, SIGNAL(pressed()), this, SLOT(LoadDefaultDBParameters()));
24}
void ReconnectDatabase(void)
Reconnect to the databse using the current parameters.
bool is_open
Flag to indicate if database is open.
Ui::MainWindow * ui
Pointer to the Main Window.
void LoadDatabaseDrivers(QComboBox *DriverList)
Load the know Database Drivers.
void LoadDefaultDBParameters(void)
Load the default Database Paranmeters.
bool is_database
Flag to indicate if there is a database.

References is_database, is_open, LoadDatabaseDrivers(), LoadDefaultDBParameters(), ReconnectDatabase(), and ui.

Here is the call graph for this function:

◆ ~DatabaseManager()

DatabaseManager::~DatabaseManager ( )

Database Manager Deconstructor.

Definition at line 26 of file databasemanager.cpp.

27{
28 // Remove Database, if it Exists
30
31 // Save the Database Settings, If Required
32 if (ui->SaveDBParamsOnExit->isChecked())
33 {
34 QSettings settings( "brigadoon/netprojectmanager" );
35 settings.setValue( "Database/DatabaseName", ui->DatabaseName->text());
36 settings.setValue( "Log_Setup/DatabaseHost", ui->DatabaseHost->text());
37 settings.setValue( "Log_Setup/DatabaseUser", ui->DatabaseUsername->text());
38 settings.setValue( "Log_Setup/DatabasePassword", ui->DatabasePassword->text());
39 settings.setValue( "Log_Setup/DatabaseDriver", ui->DatabaseDriver->currentText());
40 }
41}
void RemoveDatabase(void)
Remove the current active database.

References RemoveDatabase(), and ui.

Here is the call graph for this function:

Member Function Documentation

◆ CheckIfOpen()

bool DatabaseManager::CheckIfOpen ( bool IsOpen)
private

Set the Database Image based on IsOpenFlag.

Returns
Return the value of IsOpen

If the database is open, the database state image is set to green. If the database is closed, the databse state images is set to ref.

Definition at line 113 of file databasemanager.cpp.

114{
115 QString selected_image;
116
117 // Set the Database Open Graphic As Appropriate & Send a Log Message
118 if (DatabaseOpen)
119 {
120 selected_image = "Debug.png";
121 LogAdd(LOG_DEBUG, MODE_DATABASE, QString("Database %1 is OPEN.").arg(ui->DatabaseName->text()));
122 }
123 else
124 {
125 selected_image = "Alert.png";
126 LogAdd(LOG_WARNING, MODE_DATABASE, QString("Database %1 is NOT OPEN.").arg(ui->DatabaseName->text()));
127 }
128 QPixmap the_pixmap( QString(":/Resources/") + selected_image );
129 ui->DatabaseStatus->setPixmap(the_pixmap);
130
131 return(DatabaseOpen);
132}
void LogAdd(LOGGING_SEVERITY Severity, LOGGING_MODE Mode, QString Message)
Send Message to the Log.
@ LOG_WARNING
Definition logger.h:53
@ LOG_DEBUG
Definition logger.h:56
@ MODE_DATABASE
Definition logger.h:35

References LOG_DEBUG, LOG_WARNING, LogAdd(), MODE_DATABASE, and ui.

Referenced by Open(), and RemoveDatabase().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ LoadDatabaseDrivers()

void DatabaseManager::LoadDatabaseDrivers ( QComboBox * DriverList)
private

Load the know Database Drivers.

Parameters
DatabaseDriver List

Definition at line 43 of file databasemanager.cpp.

44{
45 // Obtain the List of Available Drivers
46 QStringList driver_list = QSqlDatabase::drivers();
47 DatabaseDriver->addItems(driver_list);
48
49 LogAdd(LOG_DEBUG, MODE_DATABASE, QString("%1 Database Drivers identified.").arg(QString::number(driver_list.count())));
50}

References LOG_DEBUG, LogAdd(), and MODE_DATABASE.

Referenced by DatabaseManager().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ LoadDefaultDBParameters

void DatabaseManager::LoadDefaultDBParameters ( void )
slot

Load the default Database Paranmeters.

Definition at line 52 of file databasemanager.cpp.

53{
54 // Open the Settings Data
55 QSettings settings( "brigadoon/netprojectmanager" );
56
57 QString database_driver_type = "QMARIADB";
58
59 // Load Log Setup Parameters
60 ui->DatabaseName->setText(settings.value( "Database/DatabaseName", "ProjectManager").toString());
61 ui->DatabaseHost->setText(settings.value( "Log_Setup/DatabaseHost", "localhost").toString());
62 ui->DatabaseUsername->setText(settings.value( "Log_Setup/DatabaseUser", "mark" ).toString());
63 ui->DatabasePassword->setText(settings.value( "Log_Setup/DatabasePassword", "xg27QHUx%" ).toString());
64 ui->DatabaseDriver->setCurrentText(settings.value( "Log_Setup/DatabaseDriver", database_driver_type ).toString());
65
66 QString fake_password_string = "";
67 if (ui->DatabasePassword->text().length() != 0) fake_password_string = "*******";
68 LogAdd(LOG_DEBUG, MODE_DATABASE, QString("Default Database parameters loaded:- Database: %1, Host: %2, Driver: %3, User: %4, Password: %5")
69 .arg(ui->DatabaseName->text(), ui->DatabaseHost->text(), ui->DatabaseDriver->currentText(), ui->DatabaseUsername->text(), fake_password_string) );
70}

References LOG_DEBUG, LogAdd(), MODE_DATABASE, and ui.

Referenced by DatabaseManager().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ LogAdd()

void DatabaseManager::LogAdd ( LOGGING_SEVERITY Severity,
LOGGING_MODE Mode,
QString Message )
private

Send Message to the Log.

Parameters
SeveritySeverity of the Log Message
ModeWhich part of the program does the message relate to
MessageText message to be added to the Log

Definition at line 134 of file databasemanager.cpp.

135{
136 REMOTE_LOG_ENTRY log_entry;
137 log_entry.Severity = Severity;
138 log_entry.Mode = Mode;
139 log_entry.Message = Message;
140 emit SendLogEntry(log_entry);
141}
void SendLogEntry(REMOTE_LOG_ENTRY LogEntry)
Send Log Entry via the Signal-Slot Method.
LOGGING_MODE Mode
Definition logger.h:61
QString Message
Definition logger.h:63
LOGGING_SEVERITY Severity
Definition logger.h:62

References REMOTE_LOG_ENTRY::Message, REMOTE_LOG_ENTRY::Mode, SendLogEntry(), and REMOTE_LOG_ENTRY::Severity.

Referenced by CheckIfOpen(), LoadDatabaseDrivers(), LoadDefaultDBParameters(), and RemoveDatabase().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Open()

bool DatabaseManager::Open ( void )
private

Open the Database witht selected parameters.

Definition at line 91 of file databasemanager.cpp.

92{
93 QSqlDatabase db = QSqlDatabase::addDatabase(ui->DatabaseDriver->currentText()); is_database = true;
94
95 // Pass the Parameters to the Database
96 db.setHostName(ui->DatabaseHost->text());
97 db.setDatabaseName(ui->DatabaseName->text());
98 db.setUserName(ui->DatabaseUsername->text());
99 db.setPassword(ui->DatabasePassword->text());
100
101 // Attempt to Open the Database
102 is_open = CheckIfOpen(db.open());
103 return(is_open);
104}
bool CheckIfOpen(bool IsOpen)
Set the Database Image based on IsOpenFlag.

References CheckIfOpen(), is_database, is_open, and ui.

Referenced by ReconnectDatabase().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ReconnectDatabase

void DatabaseManager::ReconnectDatabase ( void )
slot

Reconnect to the databse using the current parameters.

Definition at line 106 of file databasemanager.cpp.

107{
108 // Remove an existing Database & Attempt to Open a New One
110 Open();
111}
bool Open(void)
Open the Database witht selected parameters.

References Open(), and RemoveDatabase().

Referenced by DatabaseManager().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ RemoveDatabase()

void DatabaseManager::RemoveDatabase ( void )
private

Remove the current active database.

Definition at line 72 of file databasemanager.cpp.

73{
74 QSqlDatabase db = QSqlDatabase::database();
75
76 if (is_open)
77 {
78 db.close();
79 is_open = CheckIfOpen(false);
80 }
81
82 // Give Up if there was no Database Existing
83 if (!is_database) return;
84
85 // Get the Name of the Current Database
86 QString database_connection = db.connectionName();
87 QSqlDatabase::removeDatabase(database_connection);
88
89 LogAdd(LOG_INFO, MODE_DATABASE, "Database has been removed.");
90}
@ LOG_INFO
Definition logger.h:55

References CheckIfOpen(), is_database, is_open, LOG_INFO, LogAdd(), and MODE_DATABASE.

Referenced by ReconnectDatabase(), and ~DatabaseManager().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SendLogEntry

void DatabaseManager::SendLogEntry ( REMOTE_LOG_ENTRY LogEntry)
signal

Send Log Entry via the Signal-Slot Method.

Parameters
LogEntryStructure holding the Log Entry parameters

Referenced by LogAdd().

Here is the caller graph for this function:

Field Documentation

◆ is_database

bool DatabaseManager::is_database
private

Flag to indicate if there is a database.

Definition at line 84 of file databasemanager.h.

Referenced by DatabaseManager(), Open(), and RemoveDatabase().

◆ is_open

bool DatabaseManager::is_open
private

Flag to indicate if database is open.

Definition at line 90 of file databasemanager.h.

Referenced by DatabaseManager(), Open(), and RemoveDatabase().

◆ ui

Ui::MainWindow* DatabaseManager::ui
private

Pointer to the Main Window.

Definition at line 79 of file databasemanager.h.

Referenced by CheckIfOpen(), DatabaseManager(), LoadDefaultDBParameters(), Open(), and ~DatabaseManager().


The documentation for this class was generated from the following files: