1 支持界面的重新布局更新

2 对新增和删除方案支持
 3 支持方案的刷新
 4 增加日志支持
This commit is contained in:
work-zym\zhangyiming 2024-12-04 16:45:02 +08:00
parent 85daf3be65
commit 615e83ce3c
8 changed files with 232 additions and 140 deletions

View File

@ -1,86 +0,0 @@
{
"A1": {
"x": 2,
"y": 402
},
"A2": {
"x": 761,
"y": 402
},
"C3": {
"x": 252,
"y": 406
},
"C4": {
"x": 503,
"y": 403
},
"Cz": {
"x": 382,
"y": 404
},
"F3": {
"x": 287,
"y": 246
},
"F4": {
"x": 477,
"y": 249
},
"F7": {
"x": 189,
"y": 218
},
"F8": {
"x": 577,
"y": 222
},
"Fp1": {
"x": 300,
"y": 146
},
"Fp2": {
"x": 474,
"y": 148
},
"Fz": {
"x": 384,
"y": 259
},
"O1": {
"x": 302,
"y": 667
},
"O2": {
"x": 471,
"y": 669
},
"P3": {
"x": 288,
"y": 568
},
"P4": {
"x": 477,
"y": 568
},
"Pz": {
"x": 383,
"y": 558
},
"T3": {
"x": 129,
"y": 400
},
"T4": {
"x": 635,
"y": 403
},
"T5": {
"x": 191,
"y": 594
},
"T6": {
"x": 574,
"y": 595
}
}

Binary file not shown.

View File

@ -6,6 +6,7 @@
#include "operatorjson.h"
#include <QApplication>
#include <QScrollArea>
#include "logger.h"
LeadScheme::LeadScheme(QWidget * parent ):QWidget (parent)
{
init();
@ -101,26 +102,27 @@ bool LeadScheme::initconnect()
bCon = connect(&m_btnOK,SIGNAL(clicked(bool)),this,SLOT(slotSave()));
if(!bCon)
{
qDebug()<<"connect failed"<<endl;
logError()<<"connect failed"<<endl;
return bCon;
}
bCon = connect(&m_btnNew,SIGNAL(clicked(bool)),this,SLOT(slotNew()));
if(!bCon)
{
qDebug()<<"connect failed"<<endl;
logError()<<"connect failed"<<endl;
return bCon;
}
bCon = connect(&m_btndelete,SIGNAL(clicked(bool)),this,SLOT(slotDelete()));
if(!bCon)
{
qDebug()<<"connect failed"<<endl;
logError()<<"connect failed"<<endl;
return bCon;
}
return bCon;
}
void LeadScheme::initLay()
{
#if 0
@ -216,7 +218,7 @@ void LeadScheme::initLay()
"T3"<<"T4"<<"T5"<<"T6";
strList3<<"A1"<<"A2"<<"A1"<<"A1"<<"A2"<<"A1"<<"A2"<<"A1"<<"A2"<<"A1"<<"A2"<<"A1"<<
"A1"<<"A2"<<"A1"<<"A2";
QButtonGroup *pButtonGroup0 = new QButtonGroup(this);
pButtonGroup0 = new QButtonGroup(this);
QButtonGroup *pButtonGroup1 = new QButtonGroup(this);
// 设置互斥
@ -259,12 +261,14 @@ void LeadScheme::initLay()
for (int i= 0 ; i<Sches.size();i++)
{
QPushButton * btn = new QPushButton(Sches.at(i));
connect(btn,SIGNAL(clicked(bool)),this,SLOT(slotUpdateCurScheme()));
btn->setMaximumHeight(40);
btn->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
pButtonGroup0->addButton(btn);
//gridShech->addWidget( btn,i+1,0);
m_vlayHH->addWidget(btn);
btn->setCheckable(true);
m_listBtnsSchemes.append(btn);
}
m_vlayHH->addStretch();
@ -359,7 +363,8 @@ void LeadScheme::initLay()
QJsonObject json;
OperatorJson Ojson;
Ojson.readJson(QApplication::applicationDirPath()+"/0.json",json);
Ojson.readJson(QApplication::applicationDirPath()+"/Scheme/0.json",json);
qDebug()<<"hahaha"<<json<<endl;
@ -407,22 +412,6 @@ void LeadScheme::reLay()
//删除布局
//删除布局
QWidget * w = child->widget();
if(w->inherits("QAbstractButton"))
{
QPushButton * btn = static_cast<QPushButton *>(w);
if(btn)
{
bool ok = btn->text().compare("8通道")== 0 ||btn->text().compare("16通道")== 0 ||btn->text().compare("64通道")== 0 ;
if(ok)
{
continue;
}
}
}
m_vlayHH->removeWidget(child->widget());
child->widget()->setParent(0);
if (w)
@ -431,6 +420,87 @@ void LeadScheme::reLay()
}
}
}
void LeadScheme::slotUpdateCurScheme()
{
//1获取方案名称
QPushButton *btn = static_cast<QPushButton*>( sender());
if(btn)
{
m_CurScheme = btn->text();
}
//2检查对应的方案名称是否存在
//2.1)存在就加载原来的
QString sFileName = QApplication::applicationDirPath()+"/Scheme/"+m_CurScheme+".json";
if(QFile::exists(sFileName))
{
int radius = 50;
QJsonObject json;
OperatorJson Ojson;
Ojson.readJson(sFileName,json);
for(int i = 0 ; i< json.keys().size();i++)
{
for(int j =0 ;j < m_listMoveBtns.size();j++)
{
if(m_listMoveBtns.at(j)->getText().compare(json.keys().at(i)) ==0)
{
MoveButton * btn = m_listMoveBtns.at(j);
int x =json[json.keys().at(i)].toObject()["x"].toInt();
int y = json[json.keys().at(i)].toObject()["y"].toInt();
btn->setGeometry(x,y, radius, radius);
}
}
}
}
else // (2.2)不存在就加载模版
{
int radius = 50;
QJsonObject json;
OperatorJson Ojson;
Ojson.readJson(QApplication::applicationDirPath()+"/Scheme/0.json",json);
for(int i = 0 ; i< json.keys().size();i++)
{
for(int j =0 ;j < m_listMoveBtns.size();j++)
{
if(m_listMoveBtns.at(j)->getText().compare(json.keys().at(i)) ==0)
{
MoveButton * btn = m_listMoveBtns.at(j);
int x =json[json.keys().at(i)].toObject()["x"].toInt();
int y = json[json.keys().at(i)].toObject()["y"].toInt();
btn->setGeometry(x,y, radius, radius);
}
}
}
}
//保存最新的位置
QJsonObject jsonSave;
for(int i = 0;i< m_listMoveBtns.size();i++ )
{
auto btn = m_listMoveBtns.at(i);
QString text = btn->getText();
int x = btn->x();
int y = btn->y();
QJsonObject perJson;
perJson.insert("x",x);
perJson.insert("y",y);
jsonSave.insert(text,perJson);
qDebug()<<QString("名称:%1\tx:%2\ty:%3").arg(text).arg(x).arg(y)<<endl;
}
OperatorJson json;
json.savaJson(jsonSave,QApplication::applicationDirPath()+"/Scheme/"+m_CurScheme+".json");
}
void LeadScheme::slotSave()
{
@ -448,15 +518,83 @@ void LeadScheme::slotSave()
jsonSave.insert(text,perJson);
qDebug()<<QString("名称:%1\tx:%2\ty:%3").arg(text).arg(x).arg(y)<<endl;
}
OperatorJson json;
json.savaJson(jsonSave,QApplication::applicationDirPath()+"/0.json");
reLay();
json.savaJson(jsonSave,QApplication::applicationDirPath()+"/Scheme/"+m_CurScheme+".json");
}
void LeadScheme::slotNew()
{
//1 新建方案名称不为空 且不重复
QString schemeName = m_editShecName.text();
if(schemeName.isEmpty())
{
logError()<<"Shech Name is empty!"<<endl;
return ;
}
//2 判断名称是否有重复
QStringList listNames;
schemeName = schemeName.trimmed();
for(int i = 0 ; i< m_listBtnsSchemes.size();i++)
{
QString name = m_listBtnsSchemes.at(i)->text();
if(name.compare(schemeName)== 0)
{
logError()<<"Shech Name is repeated!"<<endl;
return ;
}
listNames.append(name);
}
listNames.append(schemeName);
//3 获取当前所有方案名称
m_listBtnsSchemes.clear();
reLay();
//4 重新布局
for (int i= 0 ; i<listNames.size();i++)
{
QPushButton * btn = new QPushButton(listNames.at(i));
connect(btn,SIGNAL(clicked(bool)),this,SLOT(slotUpdateCurScheme()));
btn->setMaximumHeight(40);
btn->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
pButtonGroup0->addButton(btn);
//gridShech->addWidget( btn,i+1,0);
m_vlayHH->addWidget(btn);
btn->setCheckable(true);
m_listBtnsSchemes.append(btn);
}
m_vlayHH->addStretch();
}
void LeadScheme::slotDelete()
{
//1 获取当前列表,从当前列表中获取出被选中的要删除的
QString sDeleName;
QStringList listNames;
for(int i = 0 ; i< m_listBtnsSchemes.size();i++)
{
if(m_listBtnsSchemes.at(i)->isChecked())
{
//logError()<<"delete:"<<m_listBtnsSchemes.at(i)->text()<<endl;
sDeleName=m_listBtnsSchemes.at(i)->text();
continue;
}
listNames.append(m_listBtnsSchemes.at(i)->text());
}
//2 重新布局
m_listBtnsSchemes.clear();
reLay();
//3
for (int i= 0 ; i<listNames.size();i++)
{
QPushButton * btn = new QPushButton(listNames.at(i));
connect(btn,SIGNAL(clicked(bool)),this,SLOT(slotUpdateCurScheme()));
btn->setMaximumHeight(40);
btn->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
pButtonGroup0->addButton(btn);
//gridShech->addWidget( btn,i+1,0);
m_vlayHH->addWidget(btn);
btn->setCheckable(true);
m_listBtnsSchemes.append(btn);
}
m_vlayHH->addStretch();
}

View File

@ -10,6 +10,7 @@
#include <QLineEdit>
#include "operatorjson.h"
#include <QApplication>
#include <QButtonGroup>
class LeadScheme:public QWidget
{
Q_OBJECT
@ -26,7 +27,9 @@ private slots:
void slotSave();
void slotNew();
void slotDelete();
void slotUpdateCurScheme();
private:
QString m_CurScheme;
QPushButton m_btnNew;
QPushButton m_btndelete;
QPushButton m_btnCancel;
@ -34,5 +37,7 @@ private:
QVBoxLayout * m_vlayHH ;
QList<MoveButton*> m_listMoveBtns;
QLineEdit m_editShecName;
QList<QPushButton *> m_listBtnsSchemes;
QButtonGroup *pButtonGroup0;
};
#endif // LEADSCHEME_H

View File

@ -0,0 +1,35 @@
#include "logger.h"
void MessageHandler(QtMsgType type, const QMessageLogContext &context, const QString &msg)
{
QString txt;
#if 0
switch (type)
{
case QtDebugMsg:
txt = QString("Debug: %1").arg(msg);//调试信息
break;
case QtInfoMsg:
txt = QString("Info: %1").arg(msg);//一般信息
break;
case QtWarningMsg:
txt = QString("Warning: %1").arg(msg);//警告信息
break;
case QtCriticalMsg:
txt = QString("Critical: %1").arg(msg);//严重错误信息
break;
case QtFatalMsg:
txt = QString("Fatal: %1").arg(msg);//致命错误信息
break;
}
#endif
if(type != QtCriticalMsg )
{
return ;
}
txt =msg;// txt + QString(" line:%1").arg(context.line);
QFile logFile("log.txt");
logFile.open(QIODevice::WriteOnly | QIODevice::Append);
QTextStream in(&logFile);
in << txt << endl;
}

21
xyylMCWEACSystem/logger.h Normal file
View File

@ -0,0 +1,21 @@
#ifndef LOGGER_H
#define LOGGER_H
#include <QApplication>
#include <QFile>
#include <QDebug>
#include <QThread>
#include <iostream>
#ifndef logData
#define logData "["<< __TIME__ <<"]"<<"[line:"<<__LINE__<<"]"<<"[fuction:"<<__FUNCTION__<<"]"<<"[ID:"<<QThread::currentThreadId()<<"]"// "["<<__TIME__ <<"]"<< "["<<__FILE__ <<"]"<< "[line:"<<__LINE__<<"]"<<__FUNCTION__<<"[threadID:"<<QThread::currentThreadId()<<"]"
//#define logData "["<<__DATE__<< __TIME__ <<"]"<< "["<<__FILE__ <<"]"<< "[line:"<<__LINE__<<"]"<<__FUNCTION__
#define logDebug() qDebug()<<logData<<"logDebug:"
#define logWarning() qWarning()<<logData<<"logWarning:"
#define logError() qCritical()<<logData<<"logError:"
#define logInfo() qInfo()<<logData<<"logInfo:"
#endif
void MessageHandler(QtMsgType type, const QMessageLogContext &context, const QString &msg);
#endif // LOGGER_H

View File

@ -1,22 +1,5 @@
#include "widget.h"
#include <QApplication>
#include "regwidget.h"
#include "loginwidget.h"
#include "medicalrecordwidget.h"
#include "medicalrecordmanager.h"
#include "hospitalinfo.h"
#include <QWidget>
#include <QGraphicsView>
#include <QGraphicsScene>
#include <QGraphicsPathItem>
#include <QGraphicsPolygonItem>
#include <QGraphicsTextItem>
#include <QPainterPath>
#include <QFont>
#include <QColor>
#include <QPen>
#include <QApplication>
#include <QWidget>
@ -26,27 +9,22 @@
#include <QGraphicsTextItem>
#include <QFont>
#include <qmath.h>
#include "curchatwidget.h"
#include "DevConWidget.h"
#include "framewindow.h"
#include <QStackedWidget>
#include "navlistwidget.h"
#include "framelesswindow.h"
#include "medicalrecordmanager.h"
#include "parametersettingswidget.h"
#include <QCalendarWidget>
#include "datamanager.h"
#include "leadscheme.h"
#include <QTextCodec>
#include "MoveButton.h"
#include "operatorjson.h"
#include "logger.h"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
qInstallMessageHandler(MessageHandler);
QTextCodec *codec = QTextCodec::codecForName("GBK");
QTextCodec::setCodecForLocale(codec);
QTextCodec::setCodecForLocale(codec);
FrameWindow *mainw = new FrameWindow;
// FramelessWindow *window = new FramelessWindow(mainw);
//window->resize(300, 400);

View File

@ -40,6 +40,7 @@ SOURCES += \
framewindow.cpp \
hospitalinfo.cpp \
leadscheme.cpp \
logger.cpp \
loginwidget.cpp \
main.cpp \
mainwindow.cpp \
@ -68,11 +69,11 @@ HEADERS += \
framewindow.h \
hospitalinfo.h \
leadscheme.h \
logger.h \
loginwidget.h \
mainwindow.h \
medicalrecordmanager.h \
medicalrecordwidget.h \
mrmanagement.h \
navlistwidget.h \
operatorjson.h \
parametersettingswidget.h \