⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 track.cpp

📁 给予QT的qps开源最新源码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
   lMenuB = new MenuButton(thickList, lBox);
   lMenuB->select(trackOptions.track_thick - 1);
   connect(lMenuB, SIGNAL(selected(int)), SLOT(lMenuBChanged(int)));
#endif

#if 0
   // CF GPS period
   cBox = new QHBox(mainBox); 
   // cBox->setMargin(2);
   cLabel = new QLabel(tr("CF GPS period [s] "),cBox);
   cLE = new QLineEdit(cBox);
   connect(cLE,SIGNAL(returnPressed()),SLOT(cLEChanged()));
#endif
   mapLatLonCB->setFocus();
}

Track::~Track()
{
   if ( wDo ) {
      Write(wLog->currentText());
   }
}

/*
 * update comboboxes with log names
 */
void Track::updateFileList()
{
   // keep old selected filenames
   QString wOld = wLog->currentText(), rOld = rLog->currentText();
   // remove old files
   wLog->clear();
   rLog->clear();

   // if trackPathStr exists, change logdir to it
   if (!trackOptions.trackPathStr.isNull() && 
         logdir->exists(trackOptions.trackPathStr) ) {
      logdir->setPath(trackOptions.trackPathStr);
      // fill list with new files
      const QFileInfoList * list = logdir->entryInfoList();
      QFileInfoListIterator it(*list);
      QFileInfo * fi;
      while ( (fi = it.current())) {
         // add file to list
         QString fn = fi->fileName();
         if ( fn != "places.txt" && fn != "places.txt~" ) {
            wLog->insertItem(fn.latin1());
            rLog->insertItem(fn.latin1());
            // if it's the same as the old one select it
            if ( fn == wOld ) {
               wLog->setCurrentItem(wLog->count() - 1);
            }
            if ( fn == rOld ) {
               rLog->setCurrentItem(rLog->count() - 1);
            }
         }
         ++it;
      }
   }
}

void Track::updatePlaces()
{
   mapLatLonCB->clear();
   places = application->places; 
   Place *place;
   for (place = places->first(); place != 0; place = places->next() ) {
      mapLatLonCB->insertItem(place->name);
   }
}

/*
 * write the tracklog which is in memory
 */
void Track::Write(QString filename, int format)
{
   QString pathfile = trackOptions.trackPathStr;
   QTextStream * wStream;
   QFile wFile;
   TrackPoint * tp;

   pathfile.append("/");
   pathfile.append(filename);
   wFile.setName(pathfile);
   if (wFile.open(IO_WriteOnly|IO_Append)) {
      if ((wStream = new QTextStream(&wFile))) {
         while (!wTrack.isEmpty()) {
            tp = wTrack.first();
            switch (format) {
               case NMEA:		
                  *wStream << tp->toNMEA();
                  break;
               case PCX5:	
                  *wStream << tp->toPCX5();	
                  break;
               case GPSDRIVE:	*wStream << tp->toDrive();
                              break;
            }
            wTrack.removeFirst();
            delete tp;
         }
         delete wStream;
      }
      wFile.close();
   }
   if (filename == rLog->currentText()) Read(filename);
   // we've just written and cleared track we are displaying ... reread
   updateFileList();	// fill comboboxes with log names
}

/*
 * read tracklog into the list of trackpoints
 */

void Track::Read(QString filename) {
   QString				pathfile = trackOptions.trackPathStr,trkp;
   QTextStream		*rStream;
   QFile					rFile;
   TrackPoint		*tp;

   pathfile.append("/");
   pathfile.append(filename);
   rFile.setName(pathfile);

   while (!rTrack.isEmpty()) {			// delete old track if any
      tp = rTrack.first();
      rTrack.removeFirst();
      delete tp;
   }

   if (rFile.open(IO_ReadOnly)) {	// open file with new one
      rStream = new QTextStream(&rFile);

      while (!rStream->eof()) {			// get points
         trkp = rStream->readLine();
         if (trkp.length() > 3) { // avoid empty lines
			   tp = new TrackPoint(&trkp);
            rTrack.append(tp);
         }
      }

      delete rStream;
      rFile.close();

      emit trackChanged();
   }
}

/*
 * new gps data, update tracklog
 */

void Track::update(GpsData *gpsData) 
{
   if (wDo && gpsData->status) {
      if (wTrack.isEmpty() ||
            (wTrack.last()->dist(gpsData->fix.position) > MINTRACKDIST &&
             wTrack.last()->timediff(gpsData->timestamp.time().toString()) 
             > trackOptions.updt_freq)) {

         TrackPoint *tp = new TrackPoint(
               gpsData->timestamp.time().toString(),
               gpsData->fix.position.lat,
               gpsData->fix.position.lon,
               gpsData->fix.altitude.val
               );
         wTrack.append(tp);
      }
   }
}

/*
 * toggled write checkbox
 */

void Track::setWriteCB(bool state) {
   wDo = state;
   if (!wDo) Write(wLog->currentText());

   emit trackChanged();
}

/*
 * toggled read checkbox
 */

void Track::setReadCB(bool state) {
   TrackPoint *tp;

   rDo = state;
   if (rDo) Read(rLog->currentText());
   else {
      while (!rTrack.isEmpty()) {
         tp = rTrack.first();
         rTrack.removeFirst();
         delete tp;
      }
   }
   emit trackChanged();
}

/*
 * changed read log filename
 */

void Track::setReadName(const QString &) {
   if (rDo) Read(rLog->currentText());

   emit trackChanged();
}

/*
 * toggled Show places checkbox
 */

void Track::setShowPlacesTB(bool state) {
   placesOptions->showPlaces = state;

   WRITE_CONFIG;
   emit waypointsChanged();
}

void Track::setPlacesTextSize(int idx)
{
   placesOptions->placesTextSize = idx;

   WRITE_CONFIG;
   if (placesOptions->showPlaces)
      emit waypointsChanged();
}

/*
 * display track on the screen
 */

void Track::drawTrack(QPainter *painter,MapBase *actmap,
      int x1,int y1,int mx,int my) {
   bool first = true;

   QList<TrackPoint> *disp[2];
   if (rDo) {
      disp[0] = &rTrack;
      // if read and write tracks are the same display also the part in memory
      if (wDo && (wLog->currentText() == rLog->currentText())) 
         disp[1] = &wTrack;
      else 
         disp[1] = NULL;

		// calc limits
		Position posMax, posMin;
		actmap->calcPos(posMax, x1+mx, y1);
		actmap->calcPos(posMin, x1, y1+my);
      for ( int i=0; i<2; i++ ) {
			if ( disp[i] && !disp[i]->isEmpty() ) {
				double xwp=0,ywp=0;
				int xtp,ytp;
				
            QPen pen = painter->pen();
				pen.setColor(trackOptions.trackColor);
				pen.setWidth(trackOptions.track_thick);
				painter->setPen(pen);
				TrackPoint *tp = disp[i]->first();
				// step the first point
				tp = disp[i]->next();
          while ( tp ) {	// go through all points
					if ( tp->pos.lat >= posMin.lat && 
                     tp->pos.lat <= posMax.lat &&
						   tp->pos.lon >= posMin.lon && 
                     tp->pos.lon <= posMax.lon) {
						if ( first ) {	
							// first point in read track begins the track
							// go to previous point to find start point (outside the rect)
							tp = disp[i]->prev();
							actmap->calcxy(&xwp, &ywp,tp->pos);

							xtp = (int) xwp - x1;
							ytp = (int) ywp - y1;
							painter->moveTo(xtp, ytp); 

                     first = false; 
							tp = disp[i]->next();
						} 
						actmap->calcxy(&xwp, &ywp, tp->pos);
						xtp = (int) xwp - x1;
						ytp = (int) ywp - y1;
						// draw the line
						painter->lineTo(xtp,ytp);
               } else {
						if (!first)
						{
							// draw the last line
							actmap->calcxy(&xwp, &ywp, tp->pos);
							xtp = (int) xwp - x1;
							ytp = (int) ywp - y1;
							painter->lineTo(xtp,ytp);
							// if one point was outside the screen, 
							// start line at the next point within the screen
							first = true;
						}
					}
					tp = disp[i]->next();
				}
			}
      }
   }
}

/*
 * track path changed
 */

void Track::tLEChanged() {
   trackOptions.trackPathStr = tLE->text();
   // remove '/' at the end
   while (trackOptions.trackPathStr[trackOptions.trackPathStr.length()-1] == '/')
      trackOptions.trackPathStr.truncate(trackOptions.trackPathStr.length()-1);
   tLE->setText(trackOptions.trackPathStr);
   WRITE_CONFIG;
   updateFileList();
}

/*
 * searching for track directory
 */

void Track::setTrackPath() {
   DirDialog getDirDialog(this, 0, TRUE, 0);
   getDirDialog.setCaption(tr("select track directory"));
   getDirDialog.exec();
   if(getDirDialog.result()==QDialog::Accepted) {
      trackOptions.trackPathStr = getDirDialog.selectedPath;
      // remove '/' at the end
      while (trackOptions.trackPathStr[trackOptions.trackPathStr.length()-1] == '/')
         trackOptions.trackPathStr.truncate(trackOptions.trackPathStr.length()-1);
      tLE->setText(trackOptions.trackPathStr);
   }
   WRITE_CONFIG;
   updateFileList();
}

/*
 * minimal time difference between 2 positions changed
 */

void Track::dLEChanged() {
   trackOptions.updt_freq = dLE->text().toInt();
   WRITE_CONFIG;
}

/*
 * line thickness changes
 */

void Track::lMenuBChanged(int idx) {
   trackOptions.track_thick = idx + 1;
   WRITE_CONFIG;

   emit trackChanged();
}

/*
 * set rate of message
 */
#if 0
void Track::setRate(unsigned message,unsigned rate) {
   QString msg;
   int fd;

   if (gpsData->gpsdArgStr.contains("/dev/ttyS3")) {
      msg.sprintf("$PSRF103,%02u,00,%02u,01",message,rate);
      checksumNMEA(&msg);
      if ((fd = open("/dev/ttyS3",O_WRONLY))) {
         write(fd,msg.latin1(),strlen(msg.latin1()));
         close(fd);
         qWarning(tr("changing msg%d rate to %ds"),message,rate);
      }
   }
}

/*
 * set rate of all message
 */

void Track::cLEChanged() {
   int i,val = cLE->text().toInt();

   if (val < 1) val = 1;
   else if (val > 255) val = 255;

   for (i=0; i<6; i++) setRate(i,val);
}
#endif

// end of file

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -