Changeset 3288 in ntrip


Ignore:
Timestamp:
May 31, 2011, 3:59:25 PM (13 years ago)
Author:
weber
Message:

Scaling site distribution map from caster sourcetable contents

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/BNC/bncmap.cpp

    r2805 r3288  
    1010bncMap::bncMap(QWidget* parent) : QDialog(parent)
    1111{
    12   _scale  =  2.8;   // scale the map
    13   _LaOff  =   25;   // shift longitude
     12  _LaOff   = 25;   // shift longitude
    1413  _mapScen = new QGraphicsScene();
    1514  _mapView = new BncMapView();
    1615  _mapView->setScene(_mapScen);
    17   _mapView->setMatrix(QMatrix(_scale,0,0,_scale,0,0));
     16  _mapView->resetScale();
    1817  slotReadMap();
    1918  slotCreateMap();
     
    2726   
    2827  /* rescale button */
    29   QPushButton* buttClean = new QPushButton("Clean");
    30   connect(buttClean, SIGNAL(clicked()), this, SLOT(slotCleanMap()));
    31 
    32   /* reset button */
    33   QPushButton* buttReset = new QPushButton("Reset");
    34   connect(buttReset, SIGNAL(clicked()), this, SLOT(slotResetMap()));
     28//  QPushButton* buttClean = new QPushButton("Clean");
     29//  connect(buttClean, SIGNAL(clicked()), this, SLOT(slotCleanMap()));
    3530
    3631  /* zoom button */
     
    4237  connect(buttZoomOut, SIGNAL(clicked()), this, SLOT(slotZoomOut()));
    4338
     39  /* reset button */
     40  QPushButton* buttReset = new QPushButton("World");
     41  connect(buttReset, SIGNAL(clicked()), this, SLOT(slotResetMap()));
     42
    4443  /* fit button */
    45   QPushButton* buttFit = new QPushButton("Fit");
     44  QPushButton* buttFit = new QPushButton("Fit Map");
    4645  connect(buttFit, SIGNAL(clicked()), this, SLOT(slotFitMap()));
     46
     47  /* font reset button */
     48  QPushButton* buttFont = new QPushButton("Fit Font");
     49  connect(buttFont, SIGNAL(clicked()), this, SLOT(slotFitFont()));
    4750
    4851  /* layout */
     
    5255  ButLayout->addWidget(buttZoomIn);
    5356  ButLayout->addWidget(buttZoomOut);
    54   ButLayout->addWidget(buttClean);
     57//  ButLayout->addWidget(buttClean);
    5558  ButLayout->addWidget(buttReset);
    5659  ButLayout->addWidget(buttFit);
     60  ButLayout->addWidget(buttFont);
    5761  ButLayout->addWidget(buttClose);
    5862   
     
    145149  slotCreateMap();
    146150  slotResetMap();
     151  slotFitFont();
    147152}
    148153
     
    151156void bncMap::slotResetMap()
    152157{
    153   _mapView->setMatrix(QMatrix(_scale,0,0,_scale,0,0));
    154 }
    155 
    156 
    157 // ------------
    158 void bncMap::slotZoomIn()
    159 
    160   _mapView->scale( 1.2, 1.2 );
    161 }
    162 
    163 
    164 // ------------
    165 void bncMap::slotZoomOut()
    166 
    167   _mapView->scale( 1/1.2, 1/1.2 );
     158  _mapView->resetScale();
    168159}
    169160
     
    174165  QRectF reg = _allPoints.boundingRect().adjusted(-10,-10,10,10);
    175166   
     167  _mapView->resetScale();
    176168  _mapView->updateSceneRect(reg);
    177169  _mapView->centerOn(reg.center());
    178170  _mapView->fitInView(reg,Qt::KeepAspectRatio);
    179 }
    180 
    181 
    182 // ------------
    183 void bncMap::slotNewPoint(QPointF point, QString name, QPen pen)
     171
     172  slotFitFont();
     173}
     174
     175
     176// ------------
     177void bncMap::slotFitFont()
     178
     179  _mapScen->clear();
     180  slotCreateMap();
     181
     182  float fontsize  = _mapView->scale_rate();
     183  float pointsize = _mapView->scale_rate();
     184   
     185  QMapIterator<QString, QList<QVariant> >  it(_allNames);
     186  while( it.hasNext() ){ 
     187     
     188     it.next();
     189     QString name = it.key();     
     190     QList<QVariant> tmp = it.value();
     191       
     192     double la    = tmp.at(0).toPointF().x();
     193     double fi    = tmp.at(0).toPointF().y();
     194     QPen   pen   = tmp.at(1).value<QPen>();
     195     double basPT = tmp.at(2).toDouble();
     196     double basFT = tmp.at(3).toDouble();
     197     
     198     float tmpPT = pointsize * basPT;
     199     float tmpFT =  fontsize * basFT;
     200     
     201     QFont font(QFont("Arial", 2, 1));
     202           font.setPointSizeF( tmpFT );
     203
     204     QGraphicsTextItem* nameItem = new QGraphicsTextItem( name );
     205     nameItem->setFont( font );
     206     
     207     if( floor(fontsize) < 1 ){
     208       nameItem->setPos( la - 4.0 - floor(fontsize), fi - 5.0 - floor(fontsize) );
     209     }else{
     210       nameItem->setPos( la - 1.0 - floor(fontsize), fi - 4.0 - floor(fontsize) );
     211     }
     212
     213     if( tmpPT < 0.25 ) tmpPT = 0.25;
     214     pen.setWidthF(tmpPT);
     215
     216    _mapScen->addItem( nameItem );
     217    _mapScen->addEllipse( la, fi, tmpPT, tmpPT, pen );
     218  }
     219  _mapView->zoom( 1.0 );
     220}
     221
     222
     223// ------------
     224void bncMap::slotZoomIn()
     225
     226  _mapView->zoom( 1.2 );
     227}
     228
     229
     230// ------------
     231void bncMap::slotZoomOut()
     232
     233  _mapView->zoom( 1/1.2 );
     234}
     235
     236
     237// ------------
     238void bncMap::slotNewPoint(QPointF point, QString name, QPen pen, double size)
    184239{
    185240  float la =   point.x() + _LaOff;
     
    189244  while( la >= 360 ){ la -= 360; }
    190245   
    191   _allPoints << QPointF(la, fi);
    192   _mapScen->addEllipse( la, fi, 1.5, 1.5, pen );
     246  QPointF tmppoint(la,fi);
     247  _allPoints << tmppoint;
    193248
    194249  if( ! name.isEmpty() ){
    195     QGraphicsTextItem* nameItem = new QGraphicsTextItem( name );
    196     nameItem->setPos( QPointF(la-1, fi-2));
    197     nameItem->setFont( QFont("Arial", 2, 1) );
    198 
    199     _mapScen->addItem( nameItem );
    200   }
    201 }
     250
     251    QList<QVariant> tmp;
     252    tmp << tmppoint      // QPoint
     253        << pen           // QPen
     254        << size << 4.5;  // base pointsize, fontsize
     255    _allNames.insert( name, tmp );
     256  }
     257}
Note: See TracChangeset for help on using the changeset viewer.