|
|
|
|
|
#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("班次") << tr("起始时间") << tr("结束时间");
|
|
|
|
|
|
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("设置参数"));
|
|
|
|
|
|
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("当天") : tr("隔天")).arg(m_Timestruct.m_startTime.toString("hh:mm"));
|
|
|
|
|
|
QString strEnd = QString("%1 %2").arg(m_Timestruct.time_end == AM ? tr("当天") : tr("隔天")).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("未选中"))
|
|
|
|
|
|
{
|
|
|
|
|
|
//QMessageBox::information(NULL, QString("提示"), QString("未选择班次,请选择进行修改。"), QMessageBox::Ok);
|
|
|
|
|
|
QMessageBox infobox(QMessageBox::Information, tr("提示"), tr("未选择班次,请选择进行修改。"), QMessageBox::Yes, this);
|
|
|
|
|
|
infobox.setWindowIcon(QIcon(":/image/leaper"));
|
|
|
|
|
|
infobox.setButtonText(QMessageBox::Yes, tr("确认"));
|
|
|
|
|
|
infobox.exec();
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
QString str = tr("您确定要删除 %1 班次?").arg(str_name);
|
|
|
|
|
|
|
|
|
|
|
|
if (str_name.isEmpty())
|
|
|
|
|
|
return;
|
|
|
|
|
|
QMessageBox infobox(QMessageBox::Information, tr("提示"), str, QMessageBox::Ok | QMessageBox::Cancel, this);
|
|
|
|
|
|
infobox.setWindowIcon(QIcon(":/image/leaper"));
|
|
|
|
|
|
infobox.setButtonText(QMessageBox::Ok, tr("确认"));
|
|
|
|
|
|
infobox.setButtonText(QMessageBox::Cancel, tr("取消"));
|
|
|
|
|
|
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("未选中"))
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
QMessageBox infobox(QMessageBox::Information, tr("提示"), tr("未选择班次,请选择进行修改。"), QMessageBox::Yes, this);
|
|
|
|
|
|
infobox.setWindowIcon(QIcon(":/image/leaper"));
|
|
|
|
|
|
infobox.setButtonText(QMessageBox::Yes, tr("确认"));
|
|
|
|
|
|
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("当天") : tr("隔天")).arg(tiItem.m_startTime.toString("hh:mm"));
|
|
|
|
|
|
QString strEnd = QString("%1 %2").arg(tiItem.time_end == AM ? tr("当天") : tr("隔天")).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);
|
|
|
|
|
|
//默认显示行头,如果你觉得不美观的话,我们可以将隐藏
|
|
|
|
|
|
//m_tableView->verticalHeader()->hide();
|
|
|
|
|
|
ui.TimeMgr_tableView->setSelectionBehavior(QAbstractItemView::SelectRows);
|
|
|
|
|
|
ui.TimeMgr_tableView->setEditTriggers(QAbstractItemView::NoEditTriggers);
|
|
|
|
|
|
//tableView->resizeColumnsToContents();
|
|
|
|
|
|
//如果你用在QTableView中使用右键菜单,需启用该属性
|
|
|
|
|
|
//tableView->setContextMenuPolicy(Qt::CustomContextMenu);
|
|
|
|
|
|
ui.TimeMgr_tableView->setWordWrap(false);
|
|
|
|
|
|
//tableView->setShowGrid(false);//显示表格线
|
|
|
|
|
|
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("当天") : tr("隔天")).arg(tiItem.m_startTime.toString("hh:mm"));
|
|
|
|
|
|
QString strEnd = QString("%1 %2").arg(tiItem.time_end == AM ? tr("当天") : tr("隔天")).arg(tiItem.m_endTime.toString("hh:mm"));
|
|
|
|
|
|
tablemodel->setItem(nIndex, 1, new QStandardItem(strStart));
|
|
|
|
|
|
tablemodel->setItem(nIndex, 2, new QStandardItem(strEnd));
|
|
|
|
|
|
nIndex++;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|