UI: Move ZoneListModel to IocContainer.

This commit is contained in:
Nodir Temirkhodjaev 2021-06-02 16:30:08 +03:00
parent 6fbe782b61
commit 03ba22436a
10 changed files with 24 additions and 23 deletions

View File

@ -5,6 +5,7 @@
#include "../../driver/drivermanager.h"
#include "../../fortmanager.h"
#include "../../fortsettings.h"
#include "../../model/zonelistmodel.h"
#include "../../task/taskmanager.h"
#include "../../translationmanager.h"
#include "../../util/ioc/ioccontainer.h"
@ -69,7 +70,7 @@ TranslationManager *OptionsController::translationManager() const
ZoneListModel *OptionsController::zoneListModel() const
{
return fortManager()->zoneListModel();
return IoC<ZoneListModel>();
}
void OptionsController::setOptEdited()

View File

@ -3,6 +3,8 @@
#include "../../conf/confmanager.h"
#include "../../conf/firewallconf.h"
#include "../../fortmanager.h"
#include "../../model/zonelistmodel.h"
#include "../../task/taskmanager.h"
#include "../../translationmanager.h"
#include "../../util/ioc/ioccontainer.h"
@ -37,9 +39,14 @@ IniUser *ZonesController::iniUser() const
return confManager()->iniUser();
}
TaskManager *ZonesController::taskManager() const
{
return IoC<TaskManager>();
}
ZoneListModel *ZonesController::zoneListModel() const
{
return fortManager()->zoneListModel();
return IoC<ZoneListModel>();
}
TranslationManager *ZonesController::translationManager() const

View File

@ -8,6 +8,7 @@ class FirewallConf;
class FortManager;
class IniOptions;
class IniUser;
class TaskManager;
class TranslationManager;
class ZoneListModel;
@ -23,6 +24,7 @@ public:
FirewallConf *conf() const;
IniOptions *ini() const;
IniUser *iniUser() const;
TaskManager *taskManager() const;
ZoneListModel *zoneListModel() const;
TranslationManager *translationManager() const;

View File

@ -66,12 +66,12 @@ IniUser *ZonesWindow::iniUser() const
TaskManager *ZonesWindow::taskManager() const
{
return IoC<TaskManager>();
return ctrl()->taskManager();
}
ZoneListModel *ZonesWindow::zoneListModel() const
{
return fortManager()->zoneListModel();
return ctrl()->zoneListModel();
}
void ZonesWindow::saveWindowState()

View File

@ -99,7 +99,6 @@ void FortManager::initialize()
setupConfManager();
setupQuotaManager();
setupTaskManager();
setupModels();
setupDriver();
loadConf();
@ -183,6 +182,8 @@ void FortManager::createManagers()
ioc->setService(new NativeEventFilter());
ioc->setService(new HotKeyManager());
ioc->setService(new ZoneListModel());
if (!settings->isService()) {
ioc->setService(new UserSettings());
ioc->setService(new TranslationManager());
@ -295,12 +296,6 @@ void FortManager::setupTaskManager()
IoC<ConfManager>(), &ConfManager::updateDriverZones);
}
void FortManager::setupModels()
{
m_zoneListModel = new ZoneListModel(this);
zoneListModel()->initialize();
}
void FortManager::setupTranslationManager()
{
IoC<TranslationManager>()->switchLanguageByName(IoC<UserSettings>()->iniUser().language());

View File

@ -12,7 +12,6 @@ class OptionsWindow;
class ProgramsWindow;
class StatisticsWindow;
class TrayIcon;
class ZoneListModel;
class ZonesWindow;
class FortManager : public QObject
@ -34,8 +33,6 @@ public:
ZonesWindow *zoneWindow() const { return m_zoneWindow; }
GraphWindow *graphWindow() const { return m_graphWindow; }
ZoneListModel *zoneListModel() const { return m_zoneListModel; }
bool checkRunningInstance();
void initialize();
@ -105,8 +102,6 @@ private:
void setupQuotaManager();
void setupTaskManager();
void setupModels();
void setupTranslationManager();
void setupMainWindow();
@ -149,8 +144,6 @@ private:
StatisticsWindow *m_statWindow = nullptr;
ZonesWindow *m_zoneWindow = nullptr;
GraphWindow *m_graphWindow = nullptr;
ZoneListModel *m_zoneListModel = nullptr;
};
#endif // FORTMANAGER_H

View File

@ -26,7 +26,7 @@ SqliteDb *ZoneListModel::sqliteDb() const
return confManager()->sqliteDb();
}
void ZoneListModel::initialize()
void ZoneListModel::setUp()
{
setupZoneTypes();
setupZoneSources();

View File

@ -3,6 +3,7 @@
#include <QDateTime>
#include "../util/ioc/iocservice.h"
#include "../util/model/tablesqlmodel.h"
class ConfManager;
@ -32,7 +33,7 @@ struct ZoneRow : TableRow
QDateTime lastSuccess;
};
class ZoneListModel : public TableSqlModel
class ZoneListModel : public TableSqlModel, public IocService
{
Q_OBJECT
@ -42,7 +43,7 @@ public:
ConfManager *confManager() const;
SqliteDb *sqliteDb() const override;
void initialize();
void setUp() override;
int columnCount(const QModelIndex &parent = QModelIndex()) const override;

View File

@ -24,7 +24,7 @@ TaskZoneDownloader *TaskInfoZoneDownloader::zoneDownloader() const
ZoneListModel *TaskInfoZoneDownloader::zoneListModel() const
{
return IoC<FortManager>()->zoneListModel();
return IoC<ZoneListModel>();
}
bool TaskInfoZoneDownloader::processResult(bool success)

View File

@ -1,6 +1,7 @@
#include "taskmanager.h"
#include "../conf/confmanager.h"
#include "../model/zonelistmodel.h"
#include "../util/dateutil.h"
#include "../util/ioc/ioccontainer.h"
#include "taskinfoupdatechecker.h"
@ -32,10 +33,11 @@ TaskInfo *TaskManager::taskInfoAt(int row) const
void TaskManager::setUp()
{
IoC()->setUpDependency<ConfManager>();
IoC()->setUpDependency<ZoneListModel>();
loadSettings();
QMetaObject::invokeMethod(this, &TaskManager::setupScheduler, Qt::QueuedConnection);
setupScheduler();
}
void TaskManager::setupScheduler()