//#include"ui_lineswin.h" //#include"ui_detailinfowin.h" TrainLinePanel::TrainLinePanel(QWidget *parent) : QWidget(parent), ui(new Ui::TrainLinePanel) { f_updataDB = true; setWindowFlags(Qt::FramelessWindowHint|(windowFlags() & (~Qt::WindowCloseButtonHint))); ui->setupUi(this); // keyboard = new Soft_Keyboard; // connect(ui->listWidget,SIGNAL(doubleClicked(QModelIndex)),keyboard,SLOT(show(QModelIndex))); // connect(ui->train_id_lineEdit,SIGNAL(clicked()),keyboard,SLOT(show())); // connect(ui->line_name_lineEdit,SIGNAL(clicked()),keyboard,SLOT(show())); int trainId = GlobalInfo_t::getCurrentTrainIdFromLocalFile(); QString sql = QString("select line_name from tb_lines_info where train_id=%1").arg(trainId); ResultSet set = GlobalInfo_t::getInstance()->db->query(sql); if(set.count()!=0) { QString lineName = set[0].getPara("line_name"); ui->currentLineLabel->setText(lineName); } initLineList(); initTable(); ui->stackedWidget->setCurrentIndex(1); ui->hideBtn1->setStyleSheet("border:none;background-color: rgba(255, 255, 255, 0);"); ui->hideBtn2->setStyleSheet("border:none;background-color: rgba(255, 255, 255, 0);"); }
void TrainLinePanel::initLineList() { list_table_map.clear(); for(int i = 2; i < ui->stackedWidget->count();i++) { QWidget* widget = ui->stackedWidget->widget(i); ui->stackedWidget->removeWidget(widget); delete widget; } ui->listWidget->clear(); ResultSet set = GlobalInfo_t::getInstance()->db->query("select train_id,line_name from tb_lines_info"); for(int i = 0; i < set.count();i++) { char tmp[5]; int i_train_id = set[i].getPara("train_id").toInt(); sprintf(tmp,"%02d",i_train_id); QListWidgetItem* listItem = new QListWidgetItem(QString::fromAscii(tmp)+":"+set[i].getPara("line_name"),ui->listWidget); ui->listWidget->addItem(listItem); } }
void WorkThread::onSendSysBroadcast() { QTime t; double dist = 0; ResultSet& _lineInfoSet = GlobalInfo::getInstance()->lineInfoSet; //GlobalInfo::getInstance()->debugStack.appendStack(QThread::currentThreadId(),"ready entry onSendSysBroadcast"); // qDebug("entry file:%s line:%d func:%s thread:%ld",__FILE__,__LINE__,__FUNCTION__,QThread::currentThreadId()); ResultSet lineInfos = GlobalInfo::getInstance()->lineInfoSet; ZTPprotocol ztp; ztp.addPara("T","G_INFO"); //消息类型 ztp.addPara("TrainNum",QString::number(GlobalInfo::getInstance()->train_id)); //发送者身份标识 ztp.addPara("DateTime",rmc.dateTime.toString("yy-MM-dd hh:mm:ss")); if(rmc.speed < 2.5) ztp.addPara("Speed",QString::number(0)); else ztp.addPara("Speed",QString::number(rmc.speed)); int curIndex = GlobalInfo::getInstance()->curStationIndex; if(GlobalInfo::getInstance()->lineInfoSet.count() == 0) { QString startStationEN = "START"; QString startStationThai = QString::fromUtf8("เริ่มต้นที่สถานี"); QString endStationEN = "END"; QString endStationThai = QString::fromUtf8("สุดท้ายยืน"); ztp.addPara("CurrentStationEn","--"); ztp.addPara("CurrentStationTh","--"); ztp.addPara("StartStation",startStationEN);//始发站 ztp.addPara("StartStation_th",startStationThai); ztp.addPara("EndStation",endStationEN);//终点站 ztp.addPara("EndStation_th",endStationThai); ztp.addPara("NextStation","--"); ztp.addPara("NextStation_th","--"); ztp.addPara("NextStationTime","--"); ztp.addPara("PreStation","--"); ztp.addPara("PreStation_th","--"); goto label; } if(curIndex < 0) return; //仅当当前位置在当前站点500米范围内时才显示当前站。 dist = BhcTool::geogToDistance(rmc.longitude_nh,rmc.latitude_nh,_lineInfoSet[curIndex].getParaDouble("lng"),_lineInfoSet[curIndex].getParaDouble("lat")); if( dist < 0.5 ) { t = QTime::fromString(_lineInfoSet[curIndex].getPara("start_time"),"hh:mm"); if(t.isValid()) { int secs_off = t.secsTo(QTime::currentTime()); if(secs_off/60/60 < 16)//如果当前时间比起时刻表提前超过16小时,则认为是时间回滚,需要时刻表时间+1天 { secs_off += 60*60*24; } if(secs_off/60 > 1) //迟出发1分钟以上 GlobalInfo::getInstance()->secs_off = secs_off; } else { t = QTime::fromString(_lineInfoSet[curIndex].getPara("arrive_time"),"hh:mm"); if(t.isValid()) { int secs_off = t.secsTo(QTime::currentTime()); if(secs_off/60/60 < 16)//如果当前时间比起时刻表提前超过16小时,则认为是时间回滚,需要时刻表时间+1天 { secs_off += 60*60*24; } if(secs_off/60 > 10) //呆在本站1分钟以上 GlobalInfo::getInstance()->secs_off = secs_off; } } ztp.addPara("SECS_OFF",QString::number(GlobalInfo::getInstance()->secs_off)); ztp.addPara("CurrentStationEn",lineInfos[curIndex].getPara("station_name_en")); ztp.addPara("CurrentStationTh",lineInfos[curIndex].getPara("station_name_th")); } else { // curStationEmpty = true; // qDebug()<<"xxxxxxxxxxxxxxxxxxxx "<<rmc.longitude_nh<<" "<<rmc.latitude_nh<<" "<<dist; ztp.addPara("CurrentStationEn","--"); ztp.addPara("CurrentStationTh","--"); } ztp.addPara("ArriveTime",lineInfos[GlobalInfo::getInstance()->lineInfoSet.count()-1].getPara("arrive_time"));//终点站到站时间 t =QTime::fromString(lineInfos[GlobalInfo::getInstance()->lineInfoSet.count()-1].getPara("arrive_time"),"hh:mm"); if(t.isValid())//如果满足时间条件 则覆盖ArriveTime { t = t.addSecs(GlobalInfo::getInstance()->secs_off); ztp.addPara("ArriveTime",t.toString("hh:mm")); } // ztp.addPara("StartStation",lineInfos[0].getPara("station_name_en"));//始发站 ztp.addPara("StartStation_th",QString::fromUtf8(lineInfos[0].getPara("station_name_th").toUtf8())); ztp.addPara("EndStation",lineInfos[GlobalInfo::getInstance()->lineInfoSet.count()-1].getPara("station_name_en"));//终点站 ztp.addPara("EndStation_th",QString::fromUtf8(lineInfos[GlobalInfo::getInstance()->lineInfoSet.count()-1].getPara("station_name_th").toUtf8())); // QString str = ztp.getPara("StartStation_th"); // str = str.toUtf8(); // //QString str = "นึ่รู้รู้รู้"; // QByteArray bytes = ZTools::str2unicode(str); // //qDebug()<<str; // for(int i = 0; i< bytes.length();i++) // { // qDebug("%d : %x",i,bytes.data()[i]); // } if(curIndex == 0) { ztp.addPara("PreStation","--"); ztp.addPara("PreStation_th","--"); if(lineInfos.count() > 1) { ztp.addPara("NextStation",lineInfos[curIndex+1].getPara("station_name_en")); ztp.addPara("NextStation_th",lineInfos[curIndex+1].getPara("station_name_th")); ztp.addPara("NextStationTime",lineInfos[curIndex+1].getPara("arrive_time")); QTime t =QTime::fromString(lineInfos[curIndex+1].getPara("arrive_time"),"hh:mm"); if(t.isValid()) { t = t.addSecs(GlobalInfo::getInstance()->secs_off); ztp.addPara("NextStationTime",t.toString("hh:mm")); } } else { ztp.addPara("NextStation","--"); ztp.addPara("NextStation_th","--"); ztp.addPara("NextStationTime","--"); } } else if(curIndex < GlobalInfo::getInstance()->lineInfoSet.count() - 1) { ztp.addPara("PreStation",lineInfos[curIndex-1].getPara("station_name_en")); ztp.addPara("PreStation_th",lineInfos[curIndex-1].getPara("station_name_th")); if(lineInfos.count() > 1) { ztp.addPara("NextStation",lineInfos[curIndex+1].getPara("station_name_en")); ztp.addPara("NextStation_th",lineInfos[curIndex+1].getPara("station_name_th")); ztp.addPara("NextStationTime",lineInfos[curIndex+1].getPara("arrive_time")); QTime t =QTime::fromString(lineInfos[curIndex+1].getPara("arrive_time"),"hh:mm"); if(t.isValid()) { t = t.addSecs(GlobalInfo::getInstance()->secs_off); ztp.addPara("NextStationTime",t.toString("hh:mm")); } } else { ztp.addPara("NextStation","--"); ztp.addPara("NextStation_th","--"); ztp.addPara("NextStationTime","--"); } } else { ztp.addPara("PreStation",lineInfos[curIndex-1].getPara("station_name_en")); ztp.addPara("PreStation_th",lineInfos[curIndex-1].getPara("station_name_th")); ztp.addPara("NextStation","--"); ztp.addPara("NextStation_th","--"); ztp.addPara("NextStationTime","--"); } label: ztpm->SendOneZtp(ztp,QHostAddress(BROADCAST_IP),8311); //GlobalInfo::getInstance()->debugStack.appendStack(QThread::currentThreadId(),"leave onSendSysBroadcast"); }
void TrainLinePanel::initTable() { __initTableHeader(); int listLineCount = ui->listWidget->count(); f_updataDB = false; if(listLineCount + 2 < ui->stackedWidget->count()) { qDebug("listLineCount is not match stackedWidget count!!"); return; } for(int i = 0 ;i < listLineCount;i++) { int trainId = ui->listWidget->item(i)->text().split(QChar(':'))[0].toInt(); QString sql = QString("select rowid,indexNu,station_id,station_name_en,station_name_th,start_time,arrive_time,lat,lng,sea_level from tb_station_info where train_id=%1 order by indexNu").arg(trainId); ResultSet rowSet = GlobalInfo_t::getInstance()->db->query(sql); QTableWidget *tableWidget = dynamic_cast<QTableWidget*>( ui->stackedWidget->widget(i+2)); if(tableWidget == NULL) { qDebug("tableWidget %d is null !",i); return; } tableWidget->setRowCount(rowSet.count()); for(int i = 0;i < rowSet.count();i++) { QTableWidgetItem* item = NULL; item = tableWidget->item(i,0); if(item == NULL) { item = new QTableWidgetItem; item->setTextAlignment(Qt::AlignHCenter); tableWidget->setItem(i,0,item); } item->setText(rowSet[i].getPara("indexNu")); item = tableWidget->item(i,1); if(item == NULL) { item = new QTableWidgetItem; item->setTextAlignment(Qt::AlignHCenter); tableWidget->setItem(i,1,item); } item->setText(rowSet[i].getPara("station_id")); item = tableWidget->item(i,2); if(item == NULL) { item = new QTableWidgetItem; item->setTextAlignment(Qt::AlignHCenter); tableWidget->setItem(i,2,item); } item->setText(rowSet[i].getPara("station_name_en")); item = tableWidget->item(i,3); if(item == NULL) { item = new QTableWidgetItem; item->setTextAlignment(Qt::AlignHCenter); tableWidget->setItem(i,3,item); } item->setText(rowSet[i].getPara("station_name_th")); item = tableWidget->item(i,4); if(item == NULL) { item = new QTableWidgetItem; item->setTextAlignment(Qt::AlignHCenter); tableWidget->setItem(i,4,item); } item->setText(rowSet[i].getPara("start_time")); item = tableWidget->item(i,5); if(item == NULL) { item = new QTableWidgetItem; item->setTextAlignment(Qt::AlignHCenter); tableWidget->setItem(i,5,item); } item->setText(rowSet[i].getPara("arrive_time")); item = tableWidget->item(i,6); if(item == NULL) { item = new QTableWidgetItem; item->setTextAlignment(Qt::AlignHCenter); tableWidget->setItem(i,6,item); } item->setText(rowSet[i].getPara("lng")); item = tableWidget->item(i,7); if(item == NULL) { item = new QTableWidgetItem; item->setTextAlignment(Qt::AlignHCenter); tableWidget->setItem(i,7,item); } item->setText(rowSet[i].getPara("lat")); item = tableWidget->item(i,8); if(item == NULL) { item = new QTableWidgetItem; item->setTextAlignment(Qt::AlignHCenter); tableWidget->setItem(i,8,item); } item->setText(rowSet[i].getPara("sea_level")); item = tableWidget->item(i,9); if(item == NULL) { item = new QTableWidgetItem; item->setTextAlignment(Qt::AlignHCenter); tableWidget->setItem(i,9,item); } item->setText(rowSet[i].getPara("rowid")); } } f_updataDB = true; if(ui->stackedWidget->currentIndex() != 1) ui->stackedWidget->setCurrentIndex(1); }