diff --git a/DataBaseLMS/databaselms.cpp b/DataBaseLMS/databaselms.cpp index b1a0771..de735f3 100644 --- a/DataBaseLMS/databaselms.cpp +++ b/DataBaseLMS/databaselms.cpp @@ -9,9 +9,9 @@ const QString DataBaseLMS::TypeUserDBInstructor = "instructor"; const QString DataBaseLMS::TypeUserDBTrainee = "trainee"; -DataBaseLMS::DataBaseLMS(QWidget *ownerWidget): +DataBaseLMS::DataBaseLMS(QWidget *ownerWidget, QObject *parent): + QObject(parent), db(nullptr), - transactionBegined(false), ownerWidget(ownerWidget) { @@ -22,6 +22,12 @@ DataBaseLMS::~DataBaseLMS() deleteConnection(); } +void DataBaseLMS::slot_LanguageChanged(QString language) +{ + qtLanguageTranslator.load(QString(QStringLiteral("translations/DataBaseLMS_")) + language, QStringLiteral(".")); + QCoreApplication::installTranslator(&qtLanguageTranslator); +} + bool DataBaseLMS::createConnection() { dbSettings = getDataBaseSettings(); @@ -52,9 +58,6 @@ bool DataBaseLMS::createConnection() void DataBaseLMS::deleteConnection() { - if(transactionBegined) - QSqlDatabase::database().rollback(); - if(db != nullptr) { if(db->isOpen()) @@ -87,7 +90,7 @@ DataBaseSettings DataBaseLMS::getDataBaseSettings() QFile file("config/settings.xml"); if(!file.open(QIODevice::ReadOnly)) { - QMessageBox::critical(ownerWidget, "Attention!", "The file could not be opened: config/settings.xml"); + QMessageBox::critical(ownerWidget, tr("Attention!"), tr("The file could not be opened:") + "config/settings.xml"); return settings; } QXmlStreamReader xmlReader(&file); diff --git a/DataBaseLMS/databaselms.h b/DataBaseLMS/databaselms.h index a1dbc0b..344f6dd 100644 --- a/DataBaseLMS/databaselms.h +++ b/DataBaseLMS/databaselms.h @@ -4,6 +4,7 @@ #include #include #include +#include #include "instructor.h" #include "trainee.h" @@ -23,12 +24,17 @@ public: int dbPort = 5432; }; -class DataBaseLMS +class DataBaseLMS : public QObject { + Q_OBJECT + public: - DataBaseLMS(QWidget *ownerWidget); + DataBaseLMS(QWidget *ownerWidget, QObject *parent = nullptr); ~DataBaseLMS(); +public Q_SLOTS: + void slot_LanguageChanged(QString language); + public: static const QString TypeUserDBInstructor; static const QString TypeUserDBTrainee; @@ -110,9 +116,9 @@ private: protected: QSqlDatabase* db; DataBaseSettings dbSettings; + QTranslator qtLanguageTranslator; private: - bool transactionBegined; QWidget* ownerWidget; }; diff --git a/DataBaseLMS/interfacedatabaselms.cpp b/DataBaseLMS/interfacedatabaselms.cpp index 4be22c3..5e15677 100644 --- a/DataBaseLMS/interfacedatabaselms.cpp +++ b/DataBaseLMS/interfacedatabaselms.cpp @@ -6,25 +6,19 @@ #include "interfacedatabaselms.h" InterfaceDataBaseLMS::InterfaceDataBaseLMS(QWidget *ownerWidget, QObject *parent): - QObject(parent), - DataBaseLMS(ownerWidget), + //QObject(parent), + DataBaseLMS(ownerWidget, parent), ownerWidget(ownerWidget) { } -void InterfaceDataBaseLMS::slot_LanguageChanged(QString language) -{ - qtLanguageTranslator.load(QString(QStringLiteral("translations/DataBaseLMS_")) + language, QStringLiteral(".")); - QCoreApplication::installTranslator(&qtLanguageTranslator); -} - bool InterfaceDataBaseLMS::connectionToDB() { //QMutexLocker mtxLocker(&mtxAccess); if(!createConnection()) { - QMessageBox::critical(ownerWidget, dbSettings.dbName, tr("Connection error: ") + db->lastError().text()); + QMessageBox::critical(ownerWidget, dbSettings.dbName, tr("Connection error") /*+ db->lastError().text()*/); return false; } else diff --git a/DataBaseLMS/interfacedatabaselms.h b/DataBaseLMS/interfacedatabaselms.h index 6668637..a5b7504 100644 --- a/DataBaseLMS/interfacedatabaselms.h +++ b/DataBaseLMS/interfacedatabaselms.h @@ -8,16 +8,13 @@ #include "DataBaseLMS_global.h" #include "databaselms.h" -class DATABASELMS_EXPORT InterfaceDataBaseLMS : public QObject, DataBaseLMS +class DATABASELMS_EXPORT InterfaceDataBaseLMS : public /*QObject,*/ DataBaseLMS { - Q_OBJECT + //Q_OBJECT public: InterfaceDataBaseLMS(QWidget *ownerWidget, QObject *parent = nullptr); -public Q_SLOTS: - void slot_LanguageChanged(QString language); - public: //Соединение bool connectionToDB(); @@ -102,8 +99,7 @@ public: int changeStatusTaskFIM(int id_task, QString status); int changeStatusTaskAMM(int id_task, QString status); -private: - QTranslator qtLanguageTranslator; +private: QWidget* ownerWidget; //QMutex mtxAccess; }; diff --git a/ServerLMS/providerdblms.cpp b/ServerLMS/providerdblms.cpp index f4e82eb..0359d0b 100644 --- a/ServerLMS/providerdblms.cpp +++ b/ServerLMS/providerdblms.cpp @@ -1,12 +1,14 @@ #include "providerdblms.h" #include +#include ProviderDBLMS::ProviderDBLMS(QWidget *parentWidget, QObject *parent) : QObject(parent), - dbLMS(nullptr) + dbLMS(nullptr), + parentWidget(parentWidget) { - dbLMS = new InterfaceDataBaseLMS(/*parentWidget*/nullptr); + dbLMS = new InterfaceDataBaseLMS(parentWidget); //ConnectionToDB(); } diff --git a/ServerLMS/providerdblms.h b/ServerLMS/providerdblms.h index 58835b3..b5e9f7b 100644 --- a/ServerLMS/providerdblms.h +++ b/ServerLMS/providerdblms.h @@ -81,6 +81,7 @@ public: private: InterfaceDataBaseLMS* dbLMS; QMutex mtxAccess; + QWidget *parentWidget; }; #endif // PROVIDERDBLMS_H diff --git a/ServerLMS/serverlmswidget.h b/ServerLMS/serverlmswidget.h index 77b8357..e958583 100644 --- a/ServerLMS/serverlmswidget.h +++ b/ServerLMS/serverlmswidget.h @@ -67,7 +67,7 @@ public slots: void slot_LanguageChanged(QString language); void slotUpdateListClients(); void slot_BlockAutorization(bool block); - void addToLog(QString message); + void addToLog(QString message); public: void removeClient(int socketId);