|
|
|
|
|
#include "QTimeMgrDlg.h"
|
|
|
|
|
|
#include <QStandardItemModel>
|
|
|
|
|
|
#include "timemgrctrl.h"
|
|
|
|
|
|
#include "qaddtimedlg.h"
|
|
|
|
|
|
#include <QMessageBox>
|
|
|
|
|
|
#pragma execution_character_set("utf-8")
|
|
|
|
|
|
|
|
|
|
|
|
struct CmpByValueTime {
|
|
|
|
|
|
bool operator()(const TimeStruct & lhs, const TimeStruct & rhs)
|
|
|
|
|
|
{
|
|
|
|
|
|
return lhs.m_startTime < rhs.m_startTime;
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
QTimeMgrDlg::QTimeMgrDlg(QWidget *parent)
|
|
|
|
|
|
: QDialog(parent)
|
|
|
|
|
|
{
|
|
|
|
|
|
ui.setupUi(this);
|
|
|
|
|
|
tablemodel = new QStandardItemModel();
|
|
|
|
|
|
QStringList stringList;
|
|
|
|
|
|
stringList << tr("<EFBFBD><EFBFBD><EFBFBD><EFBFBD>") << tr("<EFBFBD><EFBFBD>ʼʱ<EFBFBD><EFBFBD>") << tr("<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD>");
|
|
|
|
|
|
tablemodel->setHorizontalHeaderLabels(stringList);
|
|
|
|
|
|
connect(ui.TimeMgr_tableView, SIGNAL(clicked(const QModelIndex &)), this, SLOT(SlotcellClicked(const QModelIndex &)));
|
|
|
|
|
|
connect(ui.TimeMgr_ADD_Button, SIGNAL(clicked()), this, SLOT(onButtonClicked()));
|
|
|
|
|
|
connect(ui.TimeMgr_Del_Button, SIGNAL(clicked()), this, SLOT(onButtonClicked()));
|
|
|
|
|
|
connect(ui.TimeMgr_Mod_Button, SIGNAL(clicked()), this, SLOT(onButtonClicked()));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
QTimeMgrDlg::~QTimeMgrDlg()
|
|
|
|
|
|
{
|
|
|
|
|
|
if (tablemodel) {
|
|
|
|
|
|
while (tablemodel->rowCount())
|
|
|
|
|
|
{
|
|
|
|
|
|
QList<QStandardItem*> lptr = tablemodel->takeRow(0);
|
|
|
|
|
|
for (int n = 0; n < lptr.size(); n++)
|
|
|
|
|
|
{
|
|
|
|
|
|
delete lptr.at(n);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
tablemodel->clear();
|
|
|
|
|
|
delete tablemodel;
|
|
|
|
|
|
tablemodel = NULL;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Q_SLOT void QTimeMgrDlg::onButtonClicked()
|
|
|
|
|
|
{
|
|
|
|
|
|
QObject *obj = sender();
|
|
|
|
|
|
QString str_name = obj->objectName();
|
|
|
|
|
|
if (str_name == "TimeMgr_ADD_Button") {
|
|
|
|
|
|
QAddTimeDlg dlg(this);
|
|
|
|
|
|
dlg.setWindowTitle(tr("<EFBFBD><EFBFBD><EFBFBD>ò<EFBFBD><EFBFBD><EFBFBD>"));
|
|
|
|
|
|
dlg.setWindowIcon(QIcon(":/image/leaper"));
|
|
|
|
|
|
dlg.setFocus();
|
|
|
|
|
|
dlg.setWindowFlags(Qt::Dialog | Qt::WindowCloseButtonHint);
|
|
|
|
|
|
dlg.setWindowModality(Qt::ApplicationModal);
|
|
|
|
|
|
dlg.setAttribute(Qt::WA_ShowModal, true);
|
|
|
|
|
|
if (dlg.exec() == QDialog::Accepted)
|
|
|
|
|
|
{
|
|
|
|
|
|
TimeStruct m_Timestruct;
|
|
|
|
|
|
dlg.GetInfo(m_Timestruct);
|
|
|
|
|
|
if (m_MapTime.contains(m_Timestruct.m_name))
|
|
|
|
|
|
{
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
int nIndex = tablemodel->rowCount();
|
|
|
|
|
|
tablemodel->setItem(nIndex, 0, new QStandardItem(m_Timestruct.m_name));
|
|
|
|
|
|
QString strStart = QString("%1 %2").arg(m_Timestruct.time_start == AM ? tr("<EFBFBD><EFBFBD><EFBFBD><EFBFBD>") : tr("<EFBFBD><EFBFBD><EFBFBD><EFBFBD>")).arg(m_Timestruct.m_startTime.toString("hh:mm"));
|
|
|
|
|
|
QString strEnd = QString("%1 %2").arg(m_Timestruct.time_end == AM ? tr("<EFBFBD><EFBFBD><EFBFBD><EFBFBD>") : tr("<EFBFBD><EFBFBD><EFBFBD><EFBFBD>")).arg(m_Timestruct.m_endTime.toString("hh:mm"));
|
|
|
|
|
|
tablemodel->setItem(nIndex, 1, new QStandardItem(strStart));
|
|
|
|
|
|
tablemodel->setItem(nIndex, 2, new QStandardItem(strEnd));
|
|
|
|
|
|
m_Timestruct.m_Index = nIndex;
|
|
|
|
|
|
m_MapTime.insert(m_Timestruct.m_name, m_Timestruct);
|
|
|
|
|
|
TimeMgrCtrl *m_pTimeMgr = m_pCtrl->getTimeMgr();
|
|
|
|
|
|
m_pTimeMgr->AddNewTime(m_Timestruct);
|
|
|
|
|
|
ui.TimeMgr_label->setText("");
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (str_name == "TimeMgr_Del_Button") {
|
|
|
|
|
|
QString str_name = ui.TimeMgr_label->text();
|
|
|
|
|
|
if (str_name.isEmpty() || str_name == tr("δѡ<EFBFBD><EFBFBD>"))
|
|
|
|
|
|
{
|
|
|
|
|
|
//QMessageBox::information(NULL, QString("<22><>ʾ"), QString("δѡ<CEB4><D1A1><EFBFBD><EFBFBD><EFBFBD>Σ<EFBFBD><CEA3><EFBFBD>ѡ<EFBFBD><D1A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ġ<DEB8>"), QMessageBox::Ok);
|
|
|
|
|
|
QMessageBox infobox(QMessageBox::Information, tr("<EFBFBD><EFBFBD>ʾ"), tr("δѡ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Σ<EFBFBD><EFBFBD><EFBFBD>ѡ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ġ<EFBFBD>"), QMessageBox::Yes, this);
|
|
|
|
|
|
infobox.setWindowIcon(QIcon(":/image/leaper"));
|
|
|
|
|
|
infobox.setButtonText(QMessageBox::Yes, tr("ȷ<EFBFBD><EFBFBD>"));
|
|
|
|
|
|
infobox.exec();
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
QString str = tr("<EFBFBD><EFBFBD>ȷ<EFBFBD><EFBFBD>Ҫɾ<EFBFBD><EFBFBD> %1 <20><><EFBFBD>Σ<EFBFBD>").arg(str_name);
|
|
|
|
|
|
|
|
|
|
|
|
if (str_name.isEmpty())
|
|
|
|
|
|
return;
|
|
|
|
|
|
QMessageBox infobox(QMessageBox::Information, tr("<EFBFBD><EFBFBD>ʾ"), str, QMessageBox::Ok | QMessageBox::Cancel, this);
|
|
|
|
|
|
infobox.setWindowIcon(QIcon(":/image/leaper"));
|
|
|
|
|
|
infobox.setButtonText(QMessageBox::Ok, tr("ȷ<EFBFBD><EFBFBD>"));
|
|
|
|
|
|
infobox.setButtonText(QMessageBox::Cancel, tr("ȡ<EFBFBD><EFBFBD>"));
|
|
|
|
|
|
if (infobox.exec() == QMessageBox::Ok)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (str_name.isEmpty())
|
|
|
|
|
|
return;
|
|
|
|
|
|
QModelIndex nIndex = ui.TimeMgr_tableView->currentIndex();
|
|
|
|
|
|
int row = nIndex.row();
|
|
|
|
|
|
if (tablemodel->removeRow(nIndex.row()))
|
|
|
|
|
|
int a = 0;
|
|
|
|
|
|
else
|
|
|
|
|
|
int b = 0;
|
|
|
|
|
|
TimeStruct m_TimeStruct;
|
|
|
|
|
|
m_TimeStruct.m_name = str_name;
|
|
|
|
|
|
m_MapTime.remove(str_name);
|
|
|
|
|
|
TimeMgrCtrl *m_pTimeMgr = m_pCtrl->getTimeMgr();
|
|
|
|
|
|
m_pTimeMgr->DelOldTime(m_TimeStruct);
|
|
|
|
|
|
ui.TimeMgr_label->setText("");
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (str_name == "TimeMgr_Mod_Button") {
|
|
|
|
|
|
QString str_name = ui.TimeMgr_label->text();
|
|
|
|
|
|
if (str_name.isEmpty() || str_name == tr("δѡ<EFBFBD><EFBFBD>"))
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
QMessageBox infobox(QMessageBox::Information, tr("<EFBFBD><EFBFBD>ʾ"), tr("δѡ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Σ<EFBFBD><EFBFBD><EFBFBD>ѡ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ġ<EFBFBD>"), QMessageBox::Yes, this);
|
|
|
|
|
|
infobox.setWindowIcon(QIcon(":/image/leaper"));
|
|
|
|
|
|
infobox.setButtonText(QMessageBox::Yes, tr("ȷ<EFBFBD><EFBFBD>"));
|
|
|
|
|
|
infobox.exec();
|
|
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
QAddTimeDlg dlg;
|
|
|
|
|
|
dlg.SetInfo(m_MapTime.value(str_name));
|
|
|
|
|
|
if (dlg.exec() == QDialog::Accepted)
|
|
|
|
|
|
{
|
|
|
|
|
|
TimeStruct m_tempTime, m_newTime;
|
|
|
|
|
|
m_tempTime.m_name = str_name;
|
|
|
|
|
|
m_MapTime.remove(str_name);
|
|
|
|
|
|
dlg.GetInfo(m_newTime);
|
|
|
|
|
|
TimeMgrCtrl *m_pTimeMgr = m_pCtrl->getTimeMgr();
|
|
|
|
|
|
m_pTimeMgr->ModTime(m_tempTime, m_newTime);
|
|
|
|
|
|
m_MapTime.insert(m_newTime.m_name, m_newTime);
|
|
|
|
|
|
int nIndex = 0;
|
|
|
|
|
|
|
|
|
|
|
|
std::vector<TimeStruct> vec(m_MapTime.begin(), m_MapTime.end());
|
|
|
|
|
|
std::sort(vec.begin(), vec.end(), CmpByValueTime());
|
|
|
|
|
|
for (int n = 0; n < vec.size(); n++)
|
|
|
|
|
|
{
|
|
|
|
|
|
TimeStruct tiItem = vec.at(n);
|
|
|
|
|
|
tablemodel->setItem(nIndex, 0, new QStandardItem(tiItem.m_name));
|
|
|
|
|
|
QString strStart = QString("%1 %2").arg(tiItem.time_start == AM ? tr("<EFBFBD><EFBFBD><EFBFBD><EFBFBD>") : tr("<EFBFBD><EFBFBD><EFBFBD><EFBFBD>")).arg(tiItem.m_startTime.toString("hh:mm"));
|
|
|
|
|
|
QString strEnd = QString("%1 %2").arg(tiItem.time_end == AM ? tr("<EFBFBD><EFBFBD><EFBFBD><EFBFBD>") : tr("<EFBFBD><EFBFBD><EFBFBD><EFBFBD>")).arg(tiItem.m_endTime.toString("hh:mm"));
|
|
|
|
|
|
tablemodel->setItem(nIndex, 1, new QStandardItem(strStart));
|
|
|
|
|
|
tablemodel->setItem(nIndex, 2, new QStandardItem(strEnd));
|
|
|
|
|
|
nIndex++;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ui.TimeMgr_label->setText("");
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else if (str_name == "TimeMgr_OK_Button") {
|
|
|
|
|
|
//QDialog::accept();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Q_SLOT void QTimeMgrDlg::onSlotCellClicked(const QModelIndex& index)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (m_MapTime.size() > 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
QModelIndex nindex = tablemodel->index(index.row(), 0);
|
|
|
|
|
|
QString str = nindex.data().toString();
|
|
|
|
|
|
ui.TimeMgr_label->setText(str);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void QTimeMgrDlg::showEvent(QShowEvent *)
|
|
|
|
|
|
{
|
|
|
|
|
|
TimeMgrCtrl *m_pTimeMgr = m_pCtrl->getTimeMgr();
|
|
|
|
|
|
this->m_MapTime = m_pTimeMgr->getAllTime();
|
|
|
|
|
|
ui.TimeMgr_tableView->setModel(tablemodel);
|
|
|
|
|
|
ui.TimeMgr_tableView->setColumnWidth(0, 100);
|
|
|
|
|
|
ui.TimeMgr_tableView->setColumnWidth(1, 100);
|
|
|
|
|
|
ui.TimeMgr_tableView->setColumnWidth(2, 100);
|
|
|
|
|
|
//Ĭ<><C4AC><EFBFBD><EFBFBD>ʾ<EFBFBD><CABE>ͷ<EFBFBD><CDB7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ò<EFBFBD><C3B2><EFBFBD><EFBFBD>۵Ļ<DBB5><C4BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǿ<EFBFBD><C7BF>Խ<EFBFBD><D4BD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
//m_tableView->verticalHeader()->hide();
|
|
|
|
|
|
ui.TimeMgr_tableView->setSelectionBehavior(QAbstractItemView::SelectRows);
|
|
|
|
|
|
ui.TimeMgr_tableView->setEditTriggers(QAbstractItemView::NoEditTriggers);
|
|
|
|
|
|
//tableView->resizeColumnsToContents();
|
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>QTableView<65><77>ʹ<EFBFBD><CAB9><EFBFBD>Ҽ<EFBFBD><D2BC>˵<EFBFBD><CBB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ø<EFBFBD><C3B8><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
//tableView->setContextMenuPolicy(Qt::CustomContextMenu);
|
|
|
|
|
|
ui.TimeMgr_tableView->setWordWrap(false);
|
|
|
|
|
|
//tableView->setShowGrid(false);//<2F><>ʾ<EFBFBD><CABE><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
ui.TimeMgr_tableView->setAlternatingRowColors(true);
|
|
|
|
|
|
int nIndex = 0;
|
|
|
|
|
|
if (m_MapTime.size() <= 0)
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
std::vector<TimeStruct> vec(m_MapTime.begin(), m_MapTime.end());
|
|
|
|
|
|
std::sort(vec.begin(), vec.end(), CmpByValueTime());
|
|
|
|
|
|
for (int n = 0; n < vec.size(); n++)
|
|
|
|
|
|
{
|
|
|
|
|
|
TimeStruct tiItem = vec.at(n);
|
|
|
|
|
|
tablemodel->setItem(nIndex, 0, new QStandardItem(tiItem.m_name));
|
|
|
|
|
|
QString strStart = QString("%1 %2").arg(tiItem.time_start == AM ? tr("<EFBFBD><EFBFBD><EFBFBD><EFBFBD>") : tr("<EFBFBD><EFBFBD><EFBFBD><EFBFBD>")).arg(tiItem.m_startTime.toString("hh:mm"));
|
|
|
|
|
|
QString strEnd = QString("%1 %2").arg(tiItem.time_end == AM ? tr("<EFBFBD><EFBFBD><EFBFBD><EFBFBD>") : tr("<EFBFBD><EFBFBD><EFBFBD><EFBFBD>")).arg(tiItem.m_endTime.toString("hh:mm"));
|
|
|
|
|
|
tablemodel->setItem(nIndex, 1, new QStandardItem(strStart));
|
|
|
|
|
|
tablemodel->setItem(nIndex, 2, new QStandardItem(strEnd));
|
|
|
|
|
|
nIndex++;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|