Changeset 2796 in ntrip for trunk/BNC/bncmap.cpp


Ignore:
Timestamp:
Dec 14, 2010, 3:47:20 PM (13 years ago)
Author:
mervart
Message:
 
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/BNC/bncmap.cpp

    r2754 r2796  
    1010bncMap::bncMap(QWidget* parent) : QDialog(parent)
    1111{
    12   _scale  = 2.8;    // scale the map
    13   _LaOff  =  20;    // shift longitude
    14   _mapView = new QGraphicsView();
     12  _scale  =  2.8;   // scale the map
     13  _LaOff  =   25;   // shift longitude
    1514  _mapScen = new QGraphicsScene();
     15  _mapView = new BncMapView();
    1616  _mapView->setScene(_mapScen);
     17  _mapView->setMatrix(QMatrix(_scale,0,0,_scale,0,0));
    1718  slotReadMap();
    1819  slotCreateMap();
    19 
    20   setWindowTitle(tr("World Map [*]"));
     20  _mapScen->setSceneRect(QRect(0,-90,360,180));
     21
     22  setWindowTitle(tr("Source-Table Map [*]"));
    2123 
    2224  /* close button */
    2325  QPushButton* buttClose = new QPushButton("Close");
    2426  connect(buttClose, SIGNAL(clicked()), this, SLOT(close()));
     27   
     28  /* rescale button */
     29  QPushButton* buttClean = new QPushButton("Clean");
     30  connect(buttClean, SIGNAL(clicked()), this, SLOT(slotCleanMap()));
    2531
    2632  /* reset button */
     
    2834  connect(buttReset, SIGNAL(clicked()), this, SLOT(slotResetMap()));
    2935
     36  /* zoom button */
     37  QPushButton* buttZoomIn = new QPushButton("Zoom +");
     38  connect(buttZoomIn, SIGNAL(clicked()), this, SLOT(slotZoomIn()));
     39
     40  /* zoom button */
     41  QPushButton* buttZoomOut = new QPushButton("Zoom -");
     42  connect(buttZoomOut, SIGNAL(clicked()), this, SLOT(slotZoomOut()));
     43
     44  /* fit button */
     45  QPushButton* buttFit = new QPushButton("Fit");
     46  connect(buttFit, SIGNAL(clicked()), this, SLOT(slotFitMap()));
     47
    3048  /* layout */
    31   QGridLayout *layout = new QGridLayout;
    32   layout->setRowMinimumHeight(  0, 250);
    33   layout->addWidget(_mapView,                0, 0, 3, 1, Qt::AlignLeft);
    34   layout->addWidget(buttReset,               1, 1, 1, 1, Qt::AlignBottom);
    35   layout->addWidget(buttClose,               2, 1, 1, 1, Qt::AlignBottom);
    36   setLayout(layout);
    37  
    38 //  this->resize(860,400);
     49  QVBoxLayout* MapLayout = new QVBoxLayout;
     50  QHBoxLayout* ButLayout = new QHBoxLayout;
     51   
     52  ButLayout->addWidget(buttZoomIn);
     53  ButLayout->addWidget(buttZoomOut);
     54  ButLayout->addWidget(buttClean);
     55  ButLayout->addWidget(buttReset);
     56  ButLayout->addWidget(buttFit);
     57  ButLayout->addWidget(buttClose);
     58   
     59  MapLayout->addWidget(_mapView);
     60  MapLayout->addLayout(ButLayout);
     61   
     62  setLayout(MapLayout);
     63
    3964  this->show();
    4065}
     
    6186
    6287    in >> la >> fi;
     88
     89    // la = 0-360
     90    while( la <    0 ){ la += 360; }
     91    while( la >= 360 ){ la -= 360; }
     92     
     93    // fi opposite
    6394    _worldMap << QPointF( la, -fi );
    64        
     95       
    6596  }
    66 
    6797  world.close();
    6898}
     
    72102void bncMap::slotCreateMap()
    73103
    74 //   mapScen->setForegroundBrush(QBrush(Qt::lightGray, Qt::CrossPattern));   // grid
     104  //  _mapScen->setForegroundBrush(QBrush(Qt::lightGray, Qt::CrossPattern));   // grid
    75105
    76106  int begIdx = 0;
     
    79109    if( _worldMap.at(i).x() == 0.0 and _worldMap.at(i).y() == 0.0 ){
    80110      if( i > 0 ){
    81         endIdx = i-1;
     111        endIdx = i-1;
    82112        while( begIdx < endIdx ){
    83113
    84           int l1 = 0;
    85           int l2 = 0;
     114          int l1 = 0;
     115          int l2 = 0;
    86116
    87117          float la1 = _worldMap.at(begIdx+0).x() + _LaOff;
     
    90120          float fi2 = _worldMap.at(begIdx+1).y();
    91121          begIdx++;
    92            
    93           while( la1 <    0 ){ la1 += 360; l1++; }
    94           while( la1 >= 360 ){ la1 -= 360; l1--; }
    95           while( la2 <    0 ){ la2 += 360; l2++; }
    96           while( la2 >= 360 ){ la2 -= 360; l2--; }
    97 
    98           if( l1 != 0 and l2 == 0 ){ continue; } // break this line
    99           if( l2 != 0 and l1 == 0 ){ continue; } // break this line
    100 
    101           _mapScen->addLine(la1*_scale, fi1*_scale, la2*_scale, fi2*_scale, QPen(QBrush(Qt::black),1));
     122           
     123          while( la1 <    0 ){ la1 += 360; l1++; }
     124          while( la1 >= 360 ){ la1 -= 360; l1--; }
     125          while( la2 <    0 ){ la2 += 360; l2++; }
     126          while( la2 >= 360 ){ la2 -= 360; l2--; }
     127
     128          if( l1 != 0 and l2 == 0 ){ continue; } // break this line
     129          if( l2 != 0 and l1 == 0 ){ continue; } // break this line
     130
     131          _mapScen->addLine(la1, fi1, la2, fi2, QPen(QBrush(Qt::gray),0.3));
    102132        }
    103133      }
     
    105135    }
    106136  }
    107   _mapScen->setSceneRect(0*_scale,-90*_scale,360*_scale,180*_scale);
    108 }
    109 
    110 
    111 // ------------
    112 void bncMap::slotResetMap()
     137}
     138
     139
     140// ------------
     141void bncMap::slotCleanMap()
    113142{
    114143  QMutexLocker locker(&_mutexMap);
    115144  _mapScen->clear();
    116145  slotCreateMap();
     146  slotResetMap();
     147}
     148
     149
     150// ------------
     151void bncMap::slotResetMap()
     152{
     153  _mapView->setMatrix(QMatrix(_scale,0,0,_scale,0,0));
     154}
     155
     156
     157// ------------
     158void bncMap::slotZoomIn()
     159
     160  _mapView->scale( 1.2, 1.2 );
     161}
     162
     163
     164// ------------
     165void bncMap::slotZoomOut()
     166
     167  _mapView->scale( 1/1.2, 1/1.2 );
     168}
     169
     170
     171// ------------
     172void bncMap::slotFitMap()
     173
     174  QRectF reg = _allPoints.boundingRect().adjusted(-10,-10,10,10);
     175   
     176  _mapView->updateSceneRect(reg);
     177  _mapView->centerOn(reg.center());
     178  _mapView->fitInView(reg,Qt::KeepAspectRatio);
    117179}
    118180
     
    121183void bncMap::slotNewPoint(QPointF point, QString name, QPen pen)
    122184{
    123   float la = point.x() + _LaOff;
    124   float fi = point.y();
     185  float la =   point.x() + _LaOff;
     186  float fi = - point.y();
    125187   
    126188  while( la <    0 ){ la += 360; }
    127189  while( la >= 360 ){ la -= 360; }
    128 
    129   _mapScen->addEllipse( la*_scale, -fi*_scale, 5, 5, pen );
     190   
     191  _allPoints << QPointF(la, fi);
     192  _mapScen->addEllipse( la, fi, 1.5, 1.5, pen );
    130193
    131194  if( ! name.isEmpty() ){
    132195    QGraphicsTextItem* nameItem = new QGraphicsTextItem( name );
    133     nameItem->setPos( QPointF(la*_scale, -fi*_scale));
    134     nameItem->setFont( QFont("Helvetica", 8) );
     196    nameItem->setPos( QPointF(la-1, fi-2));
     197    nameItem->setFont( QFont("Arial", 2, 1) );
    135198
    136199    _mapScen->addItem( nameItem );
Note: See TracChangeset for help on using the changeset viewer.