Changement de l'interface pour l'heure Modbus

This commit is contained in:
zonetest
2017-07-19 14:44:15 -04:00
parent ffd2a4383d
commit a3cde7b718
7 changed files with 107 additions and 29 deletions
+49 -24
View File
@@ -35,11 +35,12 @@
#include <QDateTime>
#include <QFont>
#include <QGraphicsProxyWidget>
#include <sys/time.h>
//#include <sys/time.h>
#include "ZTLog.h"
CGeneralSettingsPage::CGeneralSettingsPage(QGraphicsWidget *Parent)
{
Q_UNUSED(Parent)
@@ -78,6 +79,12 @@ CGeneralSettingsPage::CGeneralSettingsPage(QGraphicsWidget *Parent)
mTimeEdit->setTime(QTime::currentTime());
mTimeEdit->setDisplayFormat("hh:mm");
mUseNetworkTimeChkBx = new QCheckBox("Utiliser l'heure réseau");
Proxy = new QGraphicsProxyWidget(this);
Proxy->setWidget(mUseNetworkTimeChkBx);
Proxy->setPos(450,220);
connect(mUseNetworkTimeChkBx,SIGNAL(stateChanged(int)),this,SLOT(NetworkTimeChkBxClicked(int)));
mApplyDateTimeBtn = new CTextButtonWidget("Changer date & heure");
mApplyDateTimeBtn->setParentItem(this);
mApplyDateTimeBtn->setPos(450,250);
@@ -135,31 +142,37 @@ void CGeneralSettingsPage::ButtonClicked(CTextButtonWidget *BtnPtr)
else if(BtnPtr == mApplyDateTimeBtn)
{
time_t time_data = time(0);
struct tm* tm_ptr = localtime(&time_data);
QDateTime DateTime;
DateTime.setTime(mTimeEdit->time());
DateTime.setDate(mCalendarWidget->selectedDate());
mProgramHandle->SetSystemDateTime(&DateTime);
tm_ptr->tm_min = mTimeEdit->time().minute();
tm_ptr->tm_hour = mTimeEdit->time().hour();
tm_ptr->tm_mday = mCalendarWidget->selectedDate().day();
tm_ptr->tm_mon = mCalendarWidget->selectedDate().month()-1;
tm_ptr->tm_year = mCalendarWidget->selectedDate().year()-1900;
const struct timeval tv = {mktime(tm_ptr),0};
if(settimeofday(&tv,0) < 0)
{
qDebug("Settimeofday failed");
CZTLog::instance()->AddLogString("Échec du changement de la date & de l'heure",true);
}
else
{
if ( system("/sbin/hwclock --systohc") < 0 )
{
//qDebug("hwclock sync failed");
CZTLog::instance()->AddLogString("Échec du changement de la date & de l'heure (hwsync failure)",true);
}
else
CZTLog::instance()->AddLogString(QString().sprintf("Changement de date & heure: %s %s",mCalendarWidget->selectedDate().toString("yyyy/MM/dd").toUtf8().data(),mTimeEdit->time().toString("hh:mm").toUtf8().data()),true);
}
// time_t time_data = time(0);
// struct tm* tm_ptr = localtime(&time_data);
// tm_ptr->tm_min = mTimeEdit->time().minute();
// tm_ptr->tm_hour = mTimeEdit->time().hour();
// tm_ptr->tm_mday = mCalendarWidget->selectedDate().day();
// tm_ptr->tm_mon = mCalendarWidget->selectedDate().month()-1;
// tm_ptr->tm_year = mCalendarWidget->selectedDate().year()-1900;
// const struct timeval tv = {mktime(tm_ptr),0};
// if(settimeofday(&tv,0) < 0)
// {
// qDebug("Settimeofday failed");
// CZTLog::instance()->AddLogString("Échec du changement de la date & de l'heure",true);
// }
// else
// {
// if ( system("/sbin/hwclock --systohc") < 0 )
// {
// //qDebug("hwclock sync failed");
// CZTLog::instance()->AddLogString("Échec du changement de la date & de l'heure (hwsync failure)",true);
// }
// else
// CZTLog::instance()->AddLogString(QString().sprintf("Changement de date & heure: %s %s",mCalendarWidget->selectedDate().toString("yyyy/MM/dd").toUtf8().data(),mTimeEdit->time().toString("hh:mm").toUtf8().data()),true);
// }
}
else if(BtnPtr == mPGValueSetBtn)
{
@@ -177,6 +190,18 @@ void CGeneralSettingsPage::showEvent(QShowEvent *event)
mPGTresholdValueSpinBox->setValue(mProgramHandle->GetPGTreshold());
}
void CGeneralSettingsPage::NetworkTimeChkBxClicked(int state)
{
if(state == Qt::Checked)
{
mApplyDateTimeBtn->hide();
}
else
{
mApplyDateTimeBtn->show();
}
}
//Grab the mouse if the user clicks outside buttons
void CGeneralSettingsPage::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
@@ -39,6 +39,7 @@
#include <QCalendarWidget>
#include <QTimeEdit>
#include <QSpinBox>
#include <QCheckBox>
class CZoneTest;
@@ -69,10 +70,12 @@ private:
QSpinBox *mPGTresholdValueSpinBox;
CTextButtonWidget *mPGValueSetBtn;
QGraphicsTextItem *mActualPGTresholdValueText;
QCheckBox *mUseNetworkTimeChkBx;
public slots:
void ButtonClicked(CTextButtonWidget *);
void NetworkTimeChkBxClicked(int);
};