Example #1
0
LocationProvider::LocationProvider() : QObject(), 
		       m_location(NULL), m_compass(NULL) {
  qDebug() << __FUNCTION__;

  m_location = QGeoPositionInfoSource::createDefaultSource(this);
  if(!m_location) {
    qWarning() << __FUNCTION__ << "no default position source found";

#ifdef GPSDPOSITIONINFOSOURCE
    qDebug() << __FUNCTION__ << "using gpsd";
    m_location = new GpsdPositionInfoSource(this);
#else
    qDebug() << __FUNCTION__ << "running simulation from nmea log";

    // if everything fails: try to load nmealog.txt from parent dir
    QNmeaPositionInfoSource *nmeaLocation = 
      new QNmeaPositionInfoSource(QNmeaPositionInfoSource::SimulationMode, this);
    nmeaLocation->setDevice(new QFile(QApplication::applicationDirPath() + 
				      + "/../nmealog.txt", this));
    m_location = nmeaLocation;
#endif
  }

  if(m_location) {
    m_location->setUpdateInterval(1000);
  
    connect(m_location, SIGNAL(positionUpdated(QGeoPositionInfo)),
	    this, SLOT(positionHasBeenUpdated(QGeoPositionInfo)));  

    m_location->startUpdates();
  } else
    qWarning() << __FUNCTION__ << ": Position reporting finally failed!";

  m_compass = new QCompass(this);
  connect(m_compass, SIGNAL(readingChanged()), 
	  this, SLOT(checkCompassReading()));

  if(!m_compass->start()) {
    qDebug() << __FUNCTION__ << "failed to start compass";

    // and forget aboout it
    delete m_compass;
    m_compass = NULL;
  }
}
Example #2
0
GPSModule::GPSModule(QObject *parent) : QObject(parent)
{
    QSerialPort* serial = new QSerialPort(this);
    serial->setPortName(QString("/dev/ttyUSB0"));
    serial->setBaudRate(QSerialPort::Baud9600);
    serial->setDataBits(QSerialPort::Data8);
    serial->setParity(QSerialPort::NoParity);
    serial->setStopBits(QSerialPort::OneStop);
    serial->open(QIODevice::ReadOnly);

    if(serial->isOpen())
    {
        QNmeaPositionInfoSource *source = new QNmeaPositionInfoSource(QNmeaPositionInfoSource::RealTimeMode);
        source->setDevice(serial);

        if(source){
            connect(source, SIGNAL(positionUpdated(QGeoPositionInfo)), this, SLOT(positionUpdate(QGeoPositionInfo)));
            source->setPreferredPositioningMethods(QGeoPositionInfoSource::AllPositioningMethods);
            source->setUpdateInterval(2000);
            source->startUpdates();
        }
    }
}
Example #3
0
FlickrDemo::FlickrDemo(QWidget* parent) :
        QMainWindow(parent),
        m_logfileInUse(false),
        m_session(0),
        m_pictureListReply(0),
        m_thumbnailReply(0),
        m_pictureReply(0),
        m_pages(0),
        m_page(1),
        m_satellitesInView(0),
        m_satellitesUsed(0),
        m_latitude(-1000),
        m_longitude(-1000),
        m_downloadPictureList(true),
        m_shuttingDown(false)
{
    resize(252, 344);

    locationLabel = new QLabel(tr("Lat: Long:"));
    satellitesLabel = new QLabel(tr("Using 0 of 0 satellites"));
    listWidget = new XQListWidget();
    downloadButton = new QPushButton(tr("Download Picture List"));

    QVBoxLayout *verticalLayout = new QVBoxLayout();
    verticalLayout->addWidget(locationLabel);
    verticalLayout->addWidget(satellitesLabel);
    verticalLayout->addWidget(listWidget);
    verticalLayout->addWidget(downloadButton);

    QWidget *centralWidget = new QWidget;
    centralWidget->setLayout(verticalLayout);
    setCentralWidget(centralWidget);

    createMenus();
    listWidget->setGridSize(gridSize);
    listWidget->setIconSize(thumbnailSize);
    m_progressDialog = new QProgressDialog(this);
    m_progressDialog->setModal(true);
    connect(m_progressDialog, SIGNAL(canceled()), this, SLOT(cancelDownload()));

    setWindowTitle(tr("Flickr Demo"));


    // QGeoPositionInfoSource
    m_location = QGeoPositionInfoSource::createDefaultSource(this);

    if (m_location == 0) {
        QNmeaPositionInfoSource *nmeaLocation = new QNmeaPositionInfoSource(QNmeaPositionInfoSource::SimulationMode, this);
        QFile *logFile = new QFile(QApplication::applicationDirPath()
                                   + QDir::separator() + "nmealog.txt", this);
        nmeaLocation->setDevice(logFile);
        m_location = nmeaLocation;
        m_logfileInUse = true;
    }

    // Listen gps position changes
    connect(m_location, SIGNAL(positionUpdated(QGeoPositionInfo)),
            this, SLOT(positionUpdated(QGeoPositionInfo)));

    // QGeoSatelliteInfoSource
    m_satellite = QGeoSatelliteInfoSource::createDefaultSource(this);
    // Listen satellite status changes
    if (m_satellite != 0) {
        connect(m_satellite, SIGNAL(satellitesInViewUpdated(const QList<QGeoSatelliteInfo>&)),
                this, SLOT(satellitesInViewUpdated(const QList<QGeoSatelliteInfo>&)));
        connect(m_satellite, SIGNAL(satellitesInUseUpdated(const QList<QGeoSatelliteInfo>&)),
                this, SLOT(satellitesInUseUpdated(const QList<QGeoSatelliteInfo>&)));
    }
 QGeoPositionInfoSource *createTestSource()
 {
     QNmeaPositionInfoSource *source = new QNmeaPositionInfoSource(QNmeaPositionInfoSource::SimulationMode);
     source->setDevice(new UnlimitedNmeaStream(source));
     return source;
 }