WidgetTools::closeAllChildWidgets

This commit is contained in:
2025-11-30 21:29:32 +03:00
parent d129fbded0
commit d30e6b4927
10 changed files with 53 additions and 48 deletions

View File

@@ -27,8 +27,6 @@ add_library(InstructorsAndTrainees SHARED
specialmessagebox/specialmessagebox.cpp specialmessagebox/specialmessagebox.cpp
specialmessagebox/specialmessagebox.h specialmessagebox/specialmessagebox.h
specialmessagebox/specialmessagebox.ui specialmessagebox/specialmessagebox.ui
specialmessagebox/notifycontroller.cpp
specialmessagebox/notifycontroller.h
authorization/dialogauthorization.cpp authorization/dialogauthorization.cpp
authorization/dialogauthorization.h authorization/dialogauthorization.h
@@ -141,6 +139,8 @@ add_library(InstructorsAndTrainees SHARED
widgets/waitanimationwidget.cpp widgets/waitanimationwidget.cpp
widgets/waitanimationwidget.h widgets/waitanimationwidget.h
widgets/waitanimationwidget.ui widgets/waitanimationwidget.ui
widgets/widgettools.cpp
widgets/widgettools.h
InstructorsAndTrainees.qrc InstructorsAndTrainees.qrc
) )

View File

@@ -1,9 +1,8 @@
#include "connectortoserver.h" #include "connectortoserver.h"
#include <QThread> #include <QThread>
ConnectorToServer::ConnectorToServer(QWidget* parentWidget, QObject *parent) : ConnectorToServer::ConnectorToServer(QObject *parent) :
QObject(parent), QObject(parent),
parentWidget(parentWidget),
connectionThread(nullptr), connectionThread(nullptr),
client(nullptr), client(nullptr),
dataParser(nullptr), dataParser(nullptr),

View File

@@ -14,7 +14,6 @@
#include "computer.h" #include "computer.h"
#include "classroom.h" #include "classroom.h"
#include "Datas.h" #include "Datas.h"
#include "notifycontroller.h"
#include "streamingversiondata.h" #include "streamingversiondata.h"
class ConnectorToServer : public QObject class ConnectorToServer : public QObject
@@ -22,7 +21,7 @@ class ConnectorToServer : public QObject
Q_OBJECT Q_OBJECT
public: public:
explicit ConnectorToServer(QWidget* parentWidget, QObject *parent = nullptr); explicit ConnectorToServer(QObject *parent = nullptr);
~ConnectorToServer(); ~ConnectorToServer();
public: public:
@@ -167,7 +166,6 @@ private:
void createObjects(); void createObjects();
private: private:
QWidget* parentWidget;
QThread *connectionThread; QThread *connectionThread;
TCPClient *client; TCPClient *client;
DataParser *dataParser; DataParser *dataParser;

View File

@@ -7,6 +7,7 @@
#include "dialogsettings.h" #include "dialogsettings.h"
#include "specialmessagebox.h" #include "specialmessagebox.h"
#include "hashtools.h" #include "hashtools.h"
#include "widgettools.h"
const QString InstructorsAndTraineesWidget::languageENG = "en_EN"; const QString InstructorsAndTraineesWidget::languageENG = "en_EN";
@@ -50,7 +51,7 @@ InstructorsAndTraineesWidget::InstructorsAndTraineesWidget(QWidget *parent) :
setLanguageInterfase(); setLanguageInterfase();
connectorToServer = new ConnectorToServer(this); connectorToServer = new ConnectorToServer();
connect(connectorToServer, &ConnectorToServer::sigLoginResult, this, &InstructorsAndTraineesWidget::slot_checkLoginResult); connect(connectorToServer, &ConnectorToServer::sigLoginResult, this, &InstructorsAndTraineesWidget::slot_checkLoginResult);
connect(connectorToServer, &ConnectorToServer::sigDeLoginResult, this, &InstructorsAndTraineesWidget::slot_checkDeLoginResult); connect(connectorToServer, &ConnectorToServer::sigDeLoginResult, this, &InstructorsAndTraineesWidget::slot_checkDeLoginResult);
connect(connectorToServer, &ConnectorToServer::sigServerBlocked, this, &InstructorsAndTraineesWidget::slot_ServerBlocked); connect(connectorToServer, &ConnectorToServer::sigServerBlocked, this, &InstructorsAndTraineesWidget::slot_ServerBlocked);
@@ -406,7 +407,10 @@ void InstructorsAndTraineesWidget::slot_ConnectedToServer(bool state)
if(!flSettingsServerIsChanged) if(!flSettingsServerIsChanged)
{ {
if(!flTryConnectToServer) if(!flTryConnectToServer)
{
WidgetTools::closeAllChildWidgets(this, "SpecMsgBox");
SpecMsgBox::WarningClose(this, tr("The server is not available!")); SpecMsgBox::WarningClose(this, tr("The server is not available!"));
}
} }
else else
flSettingsServerIsChanged = false; flSettingsServerIsChanged = false;

View File

@@ -1,19 +0,0 @@
#include <QMessageBox>
#include "notifycontroller.h"
#include "specialmessagebox.h"
NotifyController::NotifyController(QWidget *parentWidget, QObject *parent) :
QObject(parent),
parentWidget(parentWidget)
{
}
void NotifyController::showWarning(QString text, QWidget *parentWidget)
{
if(parentWidget)
SpecMsgBox::WarningClose(parentWidget, text);
else
SpecMsgBox::WarningClose(this->parentWidget, text);
}

View File

@@ -1,20 +0,0 @@
#ifndef NOTIFYCONTROLLER_H
#define NOTIFYCONTROLLER_H
#include <QObject>
#include <QWidget>
class NotifyController : public QObject
{
Q_OBJECT
public:
explicit NotifyController(QWidget *parentWidget = nullptr, QObject *parent = nullptr);
void showWarning(QString text, QWidget *parentWidget = nullptr);
private:
QWidget *parentWidget;
};
#endif // NOTIFYCONTROLLER_H

View File

@@ -8,6 +8,8 @@ SpecMsgBox::SpecMsgBox(QWidget *parent, TypeSpecMsgBox type, const QString& text
{ {
ui->setupUi(this); ui->setupUi(this);
this->setObjectName("SpecMsgBox");
this->setWindowFlags(this->windowFlags() & ~Qt::WindowContextHelpButtonHint); this->setWindowFlags(this->windowFlags() & ~Qt::WindowContextHelpButtonHint);
if(type == TypeSpecMsgBox::warningYesNo) if(type == TypeSpecMsgBox::warningYesNo)

View File

@@ -9,6 +9,7 @@
#include "ui_ammtaskswidget.h" #include "ui_ammtaskswidget.h"
#include "checkertask.h" #include "checkertask.h"
#include "specialmessagebox.h" #include "specialmessagebox.h"
#include "widgettools.h"
AMMtasksWidget::AMMtasksWidget(ConnectorToServer* connectorToServer, TypeListTreeAMMFIM type, QWidget *parent) : AMMtasksWidget::AMMtasksWidget(ConnectorToServer* connectorToServer, TypeListTreeAMMFIM type, QWidget *parent) :
QWidget(parent), QWidget(parent),

View File

@@ -0,0 +1,24 @@
#include "widgettools.h"
WidgetTools::WidgetTools()
{
}
// Рекурсивная функция для закрытия всех дочерних виджетов
void WidgetTools::closeAllChildWidgets(QWidget *parent, QString objName)
{
// Ищем всех дочерних виджетов типа QWidget
QObjectList children = parent->children();
foreach(auto obj, children)
{
if (auto wgt = qobject_cast<QWidget*>(obj))
{ // Проверяем имя объекта
if(wgt->objectName() == objName)
{
wgt->close(); // Закрываем виджет
}
closeAllChildWidgets(wgt, objName); // Рекурсия для возможных внучатых виджетов
}
}
}

View File

@@ -0,0 +1,16 @@
#ifndef WIDGETTOOLS_H
#define WIDGETTOOLS_H
#include <QWidget>
class WidgetTools
{
public:
WidgetTools();
public:
static void closeAllChildWidgets(QWidget* parent, QString objName);
};
#endif // WIDGETTOOLS_H