Open Simulator Terrain Editor BRIGADOON-0007
Edit Terrain Files for Open Simulator Regions
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 // Define the Connections
23 QObject::connect(ui->ReconnectDatabase, SIGNAL(pressed()), this, SLOT(ReconnectDatabase()));
24 QObject::connect(ui->LoadDefaultDBParams, SIGNAL(pressed()), this, SLOT(LoadDefaultDBParameters()));
25}
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 27 of file databasemanager.cpp.

28{
29 // Remove Database, if it Exists
31
32 // Save the Database Settings, If Required
33 if (ui->SaveDBParamsOnExit->isChecked())
34 {
35
36 QSettings settings;
37 settings.setValue( "Database/DatabaseName", ui->DatabaseName->text());
38 settings.setValue( "Database/DatabaseHost", ui->DatabaseHost->text());
39 settings.setValue( "Database/DatabaseUser", ui->DatabaseUsername->text());
40 settings.setValue( "Database/DatabasePassword", ui->DatabasePassword->text());
41 settings.setValue( "Database/DatabaseDriver", ui->DatabaseDriver->currentText());
42 }
43}
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 116 of file databasemanager.cpp.

117{
118 QString selected_image;
119
120 // Set the Database Open Graphic As Appropriate & Send a Log Message
121 if (DatabaseOpen)
122 {
123 selected_image = "Debug.png";
124 LogAdd(LOG_DEBUG, MODE_DATABASE, QString("Database %1 is OPEN.").arg(ui->DatabaseName->text()));
125 }
126 else
127 {
128 selected_image = "Alert.png";
129 LogAdd(LOG_WARNING, MODE_DATABASE, QString("Database %1 is NOT OPEN.").arg(ui->DatabaseName->text()));
130 }
131 QPixmap the_pixmap( QString(":/Resources/") + selected_image );
132 ui->DatabaseStatus->setPixmap(the_pixmap);
133
134 return(DatabaseOpen);
135}
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 45 of file databasemanager.cpp.

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

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 54 of file databasemanager.cpp.

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

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 137 of file databasemanager.cpp.

138{
139 REMOTE_LOG_ENTRY log_entry;
140 log_entry.Severity = Severity;
141 log_entry.Mode = Mode;
142 log_entry.Message = Message;
143 emit SendLogEntry(log_entry);
144}
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 94 of file databasemanager.cpp.

95{
96 QSqlDatabase db = QSqlDatabase::addDatabase(ui->DatabaseDriver->currentText()); is_database = true;
97
98 // Pass the Parameters to the Database
99 db.setHostName(ui->DatabaseHost->text());
100 db.setDatabaseName(ui->DatabaseName->text());
101 db.setUserName(ui->DatabaseUsername->text());
102 db.setPassword(ui->DatabasePassword->text());
103
104 // Attempt to Open the Database
105 is_open = CheckIfOpen(db.open());
106 return(is_open);
107}
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 109 of file databasemanager.cpp.

110{
111 // Remove an existing Database & Attempt to Open a New One
113 Open();
114}
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 75 of file databasemanager.cpp.

76{
77 QSqlDatabase db = QSqlDatabase::database();
78
79 if (is_open)
80 {
81 db.close();
82 is_open = CheckIfOpen(false);
83 }
84
85 // Give Up if there was no Database Existing
86 if (!is_database) return;
87
88 // Get the Name of the Current Database
89 QString database_connection = db.connectionName();
90 QSqlDatabase::removeDatabase(database_connection);
91
92 LogAdd(LOG_INFO, MODE_DATABASE, "Database has been removed.");
93}
@ 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: