mirror of
https://github.com/qelectrotech/qelectrotech-source-mirror.git
synced 2025-12-17 20:50:34 +01:00
Make MachineInfo a singleton class
Because on windows MachineInfo take a little time to init, we make it to a singleton. MachineInfo is build the first time in main.cpp. Now all other places where we use MachineInfo (aboutqetdialog and configdialog) gui don't hang anymore in waiting to MachineInfo finish to build.
This commit is contained in:
@@ -35,7 +35,7 @@ ConfigDialog::ConfigDialog(QWidget *parent) : QDialog(parent) {
|
||||
// liste des pages
|
||||
pages_list = new QListWidget();
|
||||
pages_list -> setViewMode(QListView::IconMode);
|
||||
if(MachineInfo::i_max_screen_height()<1000){
|
||||
if(MachineInfo::instance()->i_max_screen_height()<1000){
|
||||
pages_list -> setIconSize(QSize(64, 64));
|
||||
} else {
|
||||
pages_list -> setIconSize(QSize(128, 128));
|
||||
@@ -79,7 +79,8 @@ ConfigDialog::ConfigDialog(QWidget *parent) : QDialog(parent) {
|
||||
connect(pages_list, SIGNAL(currentRowChanged(int)),
|
||||
pages_widget, SLOT(setCurrentIndex(int)));
|
||||
|
||||
setMaximumSize(MachineInfo::i_max_screen_width(), MachineInfo::i_max_screen_height());
|
||||
setMaximumSize(MachineInfo::instance()->i_max_screen_width(),
|
||||
MachineInfo::instance()->i_max_screen_height());
|
||||
resize(1400,1000);
|
||||
|
||||
#ifdef Q_OS_MACOS
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
#endif
|
||||
#include "qet.h"
|
||||
|
||||
MachineInfo *MachineInfo::m_instance = nullptr;
|
||||
/**
|
||||
@brief MachineInfo::MachineInfo
|
||||
@param parent
|
||||
@@ -320,48 +321,16 @@ void MachineInfo::init_get_cpu_info_macos()
|
||||
@brief MachineInfo::i_max_screen_width
|
||||
@return max screen width
|
||||
*/
|
||||
int32_t MachineInfo::i_max_screen_width()
|
||||
{
|
||||
const auto screens = qApp->screens();
|
||||
auto screen_count = screens.count();
|
||||
|
||||
int32_t width_[10];
|
||||
int32_t Max_width = 0;
|
||||
|
||||
for (int ii = 0; ii < screen_count; ++ii)
|
||||
{
|
||||
width_[ii]=
|
||||
screens[ii]->geometry().width()
|
||||
* screens[ii]->devicePixelRatio();
|
||||
if(Max_width < width_[ii])
|
||||
Max_width = width_[ii];
|
||||
}
|
||||
|
||||
return Max_width;
|
||||
int32_t MachineInfo::i_max_screen_width() {
|
||||
return pc.screen.Max_width;
|
||||
}
|
||||
|
||||
/**
|
||||
@brief MachineInfo::i_max_screen_height
|
||||
@return max screen height
|
||||
*/
|
||||
int32_t MachineInfo::i_max_screen_height()
|
||||
{
|
||||
const auto screens = qApp->screens();
|
||||
auto screen_count = screens.count();
|
||||
|
||||
int32_t height_[10];
|
||||
int32_t Max_height = 0;
|
||||
|
||||
for (int ii = 0; ii < screen_count; ++ii)
|
||||
{
|
||||
height_[ii]=
|
||||
screens[ii]->geometry().height()
|
||||
* screens[ii]->devicePixelRatio();
|
||||
if(Max_height<height_[ii])
|
||||
Max_height = height_[ii];
|
||||
}
|
||||
|
||||
return Max_height;
|
||||
int32_t MachineInfo::i_max_screen_height() {
|
||||
return pc.screen.Max_height;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
#define MACHINE_INFO_H
|
||||
|
||||
#include <QThread>
|
||||
#include <QMutex>
|
||||
|
||||
/**
|
||||
@brief The MachineInfo class
|
||||
@@ -26,19 +27,48 @@
|
||||
*/
|
||||
class MachineInfo
|
||||
{
|
||||
static MachineInfo *m_instance;
|
||||
public:
|
||||
explicit MachineInfo();
|
||||
static int32_t i_max_screen_width();
|
||||
static int32_t i_max_screen_height();
|
||||
static MachineInfo *instance()
|
||||
{
|
||||
static QMutex mutex;
|
||||
if (!m_instance)
|
||||
{
|
||||
mutex.lock();
|
||||
if (!m_instance) {
|
||||
m_instance = new MachineInfo();
|
||||
}
|
||||
mutex.unlock();
|
||||
}
|
||||
|
||||
return m_instance;
|
||||
}
|
||||
|
||||
static void dropInstance()
|
||||
{
|
||||
static QMutex mutex;
|
||||
if (m_instance) {
|
||||
mutex.lock();
|
||||
delete m_instance;
|
||||
m_instance = nullptr;
|
||||
mutex.unlock();
|
||||
}
|
||||
}
|
||||
|
||||
int32_t i_max_screen_width();
|
||||
int32_t i_max_screen_height();
|
||||
QString compilation_info();
|
||||
void send_info_to_debug();
|
||||
|
||||
|
||||
private:
|
||||
MachineInfo();
|
||||
void init_get_Screen_info();
|
||||
void init_get_cpu_info();
|
||||
void init_get_cpu_info_linux();
|
||||
void init_get_cpu_info_winnt();
|
||||
void init_get_cpu_info_macos();
|
||||
|
||||
struct Pc
|
||||
{
|
||||
struct Screen
|
||||
|
||||
@@ -208,8 +208,7 @@ int main(int argc, char **argv)
|
||||
qInfo("Start-up");
|
||||
// delete old log files of max 7 days old.
|
||||
delete_old_log_files(7);
|
||||
MachineInfo ma;
|
||||
ma.send_info_to_debug();
|
||||
MachineInfo::instance()->send_info_to_debug();
|
||||
});
|
||||
return app.exec();
|
||||
}
|
||||
|
||||
@@ -35,6 +35,7 @@
|
||||
#include "titleblocktemplate.h"
|
||||
#include "ui/aboutqetdialog.h"
|
||||
#include "ui/configpage/generalconfigurationpage.h"
|
||||
#include "machine_info.h"
|
||||
|
||||
#include <cstdlib>
|
||||
#include <iostream>
|
||||
@@ -146,6 +147,7 @@ QETApp::~QETApp()
|
||||
|
||||
ElementFactory::dropInstance();
|
||||
ElementPictureFactory::dropInstance();
|
||||
MachineInfo::dropInstance();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -152,8 +152,7 @@ void AboutQETDialog::setVersion()
|
||||
QString str = "<span style=\"font-weight:bold;font-size:16pt;\">QElectroTech V "
|
||||
+ QET::displayedVersion
|
||||
+ "</span>";
|
||||
MachineInfo mi_;
|
||||
ui->m_version_label->setText(str + mi_.compilation_info());
|
||||
ui->m_version_label->setText(str + MachineInfo::instance()->compilation_info());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user