// --------------------------- private slots ------------------------------- //
void QgsOpenRasterDialog::on_tbnSelectRaster_clicked()
{
  QSettings settings;
  QString dir = settings.value( "/Plugin-GeoReferencer/rasterdirectory" ).toString();
  if ( dir.isEmpty() )
    dir = ".";

  QString lastUsedFilter = settings.value( "/Plugin-GeoReferencer/lastusedfilter" ).toString();

  QString filters;
  QgsRasterLayer::buildSupportedRasterFileFilter( filters );
  filters.prepend( "(*.*);;" );
  QString rasterFileName = QFileDialog::getOpenFileName( this, tr( "Choose a name of the raster" ), dir,
                           filters, &lastUsedFilter );

  if ( rasterFileName.isEmpty() )
  {
    return;
  }
  leRasterFileName->setText( rasterFileName );

  // do we think that this is a valid raster?
  if ( !QgsRasterLayer::isValidRasterFileName( rasterFileName ) )
  {
    QMessageBox::critical( this, tr( "Error" ),
                           tr( "The selected file is not a valid raster file." ) );
    return;
  }

  QFileInfo fileInfo( rasterFileName );
  settings.setValue( "/Plugin-GeoReferencer/rasterdirectory", fileInfo.path() );
  settings.setValue( "/Plugin-GeoReferencer/lastusedfilter", lastUsedFilter );

  QString modifiedFileName = generateModifiedRasterFileName();
  leModifiedRasterFileName->setText( modifiedFileName );

  // What DOING this code?
  QgsProject* prj = QgsProject::instance();
  QString projBehaviour = settings.value( "/Projections/defaultBehaviour", "prompt" ).toString();
  QString projectCRS = prj->readEntry( "SpatialRefSys", "/ProjectCRSProj4String" );
  int projectCrsId = prj->readNumEntry( "SpatialRefSys", "/ProjectCrsId" );

  settings.setValue( "/Projections/defaultBehaviour", "useProject" );
  prj->writeEntry( "SpatialRefSys", "/ProjectCRSProj4String", GEOPROJ4 );
  prj->writeEntry( "SpatialRefSys", "/ProjectCrsId", int( GEOCRS_ID ) );

  settings.setValue( "/Projections/defaultBehaviour", projBehaviour );
  prj->writeEntry( "SpatialRefSys", "/ProjectCRSProj4String", projectCRS );
  prj->writeEntry( "SpatialRefSys", "/ProjectCrsId", projectCrsId );
}
Beispiel #2
0
spatialPlotDlg::spatialPlotDlg(QDialog *parent)
{
  setupUi(this);

  connect( pushButtonEleShape, SIGNAL( clicked() ), this, SLOT( browseEleShapeFile() ) );
  connect( pushButtonRivShape, SIGNAL( clicked() ), this, SLOT( browseRivShapeFile() ) );
  connect( pushButtonFileName, SIGNAL( clicked() ), this, SLOT( browseModelFile()    ) );
  connect( pushButtonGenerate, SIGNAL( clicked() ), this, SLOT( generate()           ) );
  connect( pushButtonHelp,     SIGNAL( clicked() ), this, SLOT( help()               ) );

  QgsProject *p = QgsProject::instance();
  QString projDir = p->readPath(p->readEntry("pihm", "projDir"));

  int scale = p->readNumEntry("pihm", "scale");       // 110
  int step = p->readNumEntry("pihm", "step5");       // 106
  comboBoxEle->setCurrentIndex(scale);
  comboBoxRiv->setCurrentIndex(scale);
  step= scale==0 ? step : scale==1 ? step/60 : step/1440;
  //lineEditEleTime->setText(QString::number(step, 10));

  step=p->readNumEntry("pihm", "step8");   // 109
  step= scale==0 ? step : scale==1 ? step/60 : step/1440;
  //lineEditRivTime->setText(QString::number(step,10));

  lineEditEleShape->setText(p->readPath(p->readEntry("pihm", "TIN"))); // 48
  lineEditRivShape->setText(p->readPath(p->readEntry("pihm", "rivdec"))); // 81

  int start, finish;
  start = p->readNumEntry("pihm", "start"); // 111
  finish= p->readNumEntry("pihm", "finish"); // 112
  start = scale==0 ? start : scale==1 ? start/60 : start/1440; start = start +1;
  finish= scale==0 ? finish : scale==1 ? finish/60 : finish/1440;
  lineEditEleStart->setText(QString::number(start,10));
  lineEditEleFinish->setText(QString::number(finish,10));
  lineEditRivStart->setText(QString::number(start,10));
  lineEditRivFinish->setText(QString::number(finish,10));
}
void QgsDecorationCopyright::projectRead()
{
  QgsDecorationItem::projectRead();

  QDate now = QDate::currentDate();
  QString defString = "© QGIS " + now.toString( "yyyy" );

  // there is no font setting in the UI, so just use the Qt/QGIS default font (what mQFont gets when created)
  //  mQFont.setFamily( QgsProject::instance()->readEntry( "CopyrightLabel", "/FontName", "Sans Serif" ) );
  //  mQFont.setPointSize( QgsProject::instance()->readNumEntry( "CopyrightLabel", "/FontSize", 9 ) );
  QgsProject* prj = QgsProject::instance();
  mLabelQString = prj->readEntry( mNameConfig, "/Label", defString );
  mPlacementIndex = prj->readNumEntry( mNameConfig, "/Placement", 3 );
  mLabelQColor.setNamedColor( prj->readEntry( mNameConfig, "/Color", "#000000" ) ); // default color is black
}
Beispiel #4
0
CatchmentPolygonDlg::CatchmentPolygonDlg(QWidget *parent)
{
  setupUi(this);
  connect(inputBrowseButton, SIGNAL(clicked()), this, SLOT(inputBrowse()));
  connect(outputBrowseButton, SIGNAL(clicked()), this, SLOT(outputBrowse()));
  connect(runButton, SIGNAL(clicked()), this, SLOT(run()));
  connect(helpButton, SIGNAL(clicked()), this, SLOT(help()));
  connect(closeButton, SIGNAL(clicked()), this, SLOT(close()));

  QgsProject *p = QgsProject::instance();
  QString projDir = p->readPath(p->readEntry("pihm", "projDir"));
  inputFileLineEdit->setText(p->readPath(p->readEntry("pihm", "catgrid"))); // 19

  int Thresh(p->readNumEntry("pihm", "facThreshold"));
  outputFileLineEdit->setText(projDir+"/RasterProcessing/cat"+ QString::number(Thresh) +".shp");
}
Beispiel #5
0
LinkGridDlg::LinkGridDlg(QWidget *parent)
{
  setupUi(this);
  connect(inputSTRBrowseButton, SIGNAL(clicked()), this, SLOT(inputSTRBrowse()));
  connect(inputFDRBrowseButton, SIGNAL(clicked()), this, SLOT(inputFDRBrowse()));
  connect(outputBrowseButton, SIGNAL(clicked()), this, SLOT(outputBrowse()));
  connect(runButton, SIGNAL(clicked()), this, SLOT(run()));
  connect(helpButton, SIGNAL(clicked()), this, SLOT(help()));
  connect(closeButton, SIGNAL(clicked()), this, SLOT(close()));

  QgsProject *p = QgsProject::instance();
  QString projDir = p->readPath(p->readEntry("pihm", "projDir"));

  inputSTRFileLineEdit->setText(p->readPath(p->readEntry("pihm", "strgrid"))); // 9
  inputFDRFileLineEdit->setText(p->readPath(p->readEntry("pihm", "fdr"))); // 6

  int Thresh(p->readNumEntry("pihm", "facThreshold")); // 10
  outputFileLineEdit->setText(projDir+"/RasterProcessing/lnk"+QString::number(Thresh)+".asc");
}
void QgsMapRenderer::render( QPainter* painter, double* forceWidthScale )
{
  //Lock render method for concurrent threads (e.g. from globe)
  QMutexLocker renderLock( &mRenderMutex );

  //flag to see if the render context has changed
  //since the last time we rendered. If it hasnt changed we can
  //take some shortcuts with rendering
  bool mySameAsLastFlag = true;

  QgsDebugMsg( "========== Rendering ==========" );

  if ( mExtent.isEmpty() )
  {
    QgsDebugMsg( "empty extent... not rendering" );
    return;
  }

  if ( mSize.width() == 1 && mSize.height() == 1 )
  {
    QgsDebugMsg( "size 1x1... not rendering" );
    return;
  }

  QPaintDevice* thePaintDevice = painter->device();
  if ( !thePaintDevice )
  {
    return;
  }

  // wait
  if ( mDrawing )
  {
    QgsDebugMsg( "already rendering" );
    QCoreApplication::processEvents();
  }

  if ( mDrawing )
  {
    QgsDebugMsg( "still rendering - skipping" );
    return;
  }

  mDrawing = true;

  const QgsCoordinateTransform *ct;

#ifdef QGISDEBUG
  QgsDebugMsg( "Starting to render layer stack." );
  QTime renderTime;
  renderTime.start();
#endif

  if ( mOverview )
    mRenderContext.setDrawEditingInformation( !mOverview );

  mRenderContext.setPainter( painter );
  mRenderContext.setCoordinateTransform( 0 );
  //this flag is only for stopping during the current rendering progress,
  //so must be false at every new render operation
  mRenderContext.setRenderingStopped( false );

  // set selection color
  QgsProject* prj = QgsProject::instance();
  int myRed = prj->readNumEntry( "Gui", "/SelectionColorRedPart", 255 );
  int myGreen = prj->readNumEntry( "Gui", "/SelectionColorGreenPart", 255 );
  int myBlue = prj->readNumEntry( "Gui", "/SelectionColorBluePart", 0 );
  int myAlpha = prj->readNumEntry( "Gui", "/SelectionColorAlphaPart", 255 );
  mRenderContext.setSelectionColor( QColor( myRed, myGreen, myBlue, myAlpha ) );

  //calculate scale factor
  //use the specified dpi and not those from the paint device
  //because sometimes QPainter units are in a local coord sys (e.g. in case of QGraphicsScene)
  double sceneDpi = mScaleCalculator->dpi();
  double scaleFactor = 1.0;
  if ( mOutputUnits == QgsMapRenderer::Millimeters )
  {
    if ( forceWidthScale )
    {
      scaleFactor = *forceWidthScale;
    }
    else
    {
      scaleFactor = sceneDpi / 25.4;
    }
  }
  double rasterScaleFactor = ( thePaintDevice->logicalDpiX() + thePaintDevice->logicalDpiY() ) / 2.0 / sceneDpi;
  if ( mRenderContext.rasterScaleFactor() != rasterScaleFactor )
  {
    mRenderContext.setRasterScaleFactor( rasterScaleFactor );
    mySameAsLastFlag = false;
  }
  if ( mRenderContext.scaleFactor() != scaleFactor )
  {
    mRenderContext.setScaleFactor( scaleFactor );
    mySameAsLastFlag = false;
  }
  if ( mRenderContext.rendererScale() != mScale )
  {
    //add map scale to render context
    mRenderContext.setRendererScale( mScale );
    mySameAsLastFlag = false;
  }
  if ( mLastExtent != mExtent )
  {
    mLastExtent = mExtent;
    mySameAsLastFlag = false;
  }

  mRenderContext.setLabelingEngine( mLabelingEngine );
  if ( mLabelingEngine )
    mLabelingEngine->init( this );

  // know we know if this render is just a repeat of the last time, we
  // can clear caches if it has changed
  if ( !mySameAsLastFlag )
  {
    //clear the cache pixmap if we changed resolution / extent
    QSettings mySettings;
    if ( mySettings.value( "/qgis/enable_render_caching", false ).toBool() )
    {
      QgsMapLayerRegistry::instance()->clearAllLayerCaches();
    }
  }

  // render all layers in the stack, starting at the base
  QListIterator<QString> li( mLayerSet );
  li.toBack();

  QgsRectangle r1, r2;

  while ( li.hasPrevious() )
  {
    if ( mRenderContext.renderingStopped() )
    {
      break;
    }

    // Store the painter in case we need to swap it out for the
    // cache painter
    QPainter * mypContextPainter = mRenderContext.painter();
    // Flattened image for drawing when a blending mode is set
    QImage * mypFlattenedImage = 0;

    QString layerId = li.previous();

    QgsDebugMsg( "Rendering at layer item " + layerId );

    // This call is supposed to cause the progress bar to
    // advance. However, it seems that updating the progress bar is
    // incompatible with having a QPainter active (the one that is
    // passed into this function), as Qt produces a number of errors
    // when try to do so. I'm (Gavin) not sure how to fix this, but
    // added these comments and debug statement to help others...
    QgsDebugMsg( "If there is a QPaintEngine error here, it is caused by an emit call" );

    //emit drawingProgress(myRenderCounter++, mLayerSet.size());
    QgsMapLayer *ml = QgsMapLayerRegistry::instance()->mapLayer( layerId );

    if ( !ml )
    {
      QgsDebugMsg( "Layer not found in registry!" );
      continue;
    }

    QgsDebugMsg( QString( "layer %1:  minscale:%2  maxscale:%3  scaledepvis:%4  extent:%5  blendmode:%6" )
                 .arg( ml->name() )
                 .arg( ml->minimumScale() )
                 .arg( ml->maximumScale() )
                 .arg( ml->hasScaleBasedVisibility() )
                 .arg( ml->extent().toString() )
                 .arg( ml->blendMode() )
               );

    if ( mRenderContext.useAdvancedEffects() )
    {
      // Set the QPainter composition mode so that this layer is rendered using
      // the desired blending mode
      mypContextPainter->setCompositionMode( ml->blendMode() );
    }

    if ( !ml->hasScaleBasedVisibility() || ( ml->minimumScale() <= mScale && mScale < ml->maximumScale() ) || mOverview )
    {
      connect( ml, SIGNAL( drawingProgress( int, int ) ), this, SLOT( onDrawingProgress( int, int ) ) );

      //
      // Now do the call to the layer that actually does
      // the rendering work!
      //

      bool split = false;

      if ( hasCrsTransformEnabled() )
      {
        r1 = mExtent;
        split = splitLayersExtent( ml, r1, r2 );
        ct = transformation( ml );
        mRenderContext.setExtent( r1 );
        QgsDebugMsg( "  extent 1: " + r1.toString() );
        QgsDebugMsg( "  extent 2: " + r2.toString() );
        if ( !r1.isFinite() || !r2.isFinite() ) //there was a problem transforming the extent. Skip the layer
        {
          continue;
        }
      }
      else
      {
        ct = NULL;
      }

      mRenderContext.setCoordinateTransform( ct );

      //decide if we have to scale the raster
      //this is necessary in case QGraphicsScene is used
      bool scaleRaster = false;
      QgsMapToPixel rasterMapToPixel;
      QgsMapToPixel bk_mapToPixel;

      if ( ml->type() == QgsMapLayer::RasterLayer && qAbs( rasterScaleFactor - 1.0 ) > 0.000001 )
      {
        scaleRaster = true;
      }

      // Force render of layers that are being edited
      // or if there's a labeling engine that needs the layer to register features
      if ( ml->type() == QgsMapLayer::VectorLayer )
      {
        QgsVectorLayer* vl = qobject_cast<QgsVectorLayer *>( ml );
        if ( vl->isEditable() ||
             ( mRenderContext.labelingEngine() && mRenderContext.labelingEngine()->willUseLayer( vl ) ) )
        {
          ml->setCacheImage( 0 );
        }
      }

      QSettings mySettings;
      bool useRenderCaching = false;
      if ( ! split )//render caching does not yet cater for split extents
      {
        if ( mySettings.value( "/qgis/enable_render_caching", false ).toBool() )
        {
          useRenderCaching = true;
          if ( !mySameAsLastFlag || ml->cacheImage() == 0 )
          {
            QgsDebugMsg( "Caching enabled but layer redraw forced by extent change or empty cache" );
            QImage * mypImage = new QImage( mRenderContext.painter()->device()->width(),
                                            mRenderContext.painter()->device()->height(), QImage::Format_ARGB32 );
            if ( mypImage->isNull() )
            {
              QgsDebugMsg( "insufficient memory for image " + QString::number( mRenderContext.painter()->device()->width() ) + "x" + QString::number( mRenderContext.painter()->device()->height() ) );
              emit drawError( ml );
              painter->end(); // drawError is not caught by anyone, so we end painting to notify caller
              return;
            }
            mypImage->fill( 0 );
            ml->setCacheImage( mypImage ); //no need to delete the old one, maplayer does it for you
            QPainter * mypPainter = new QPainter( ml->cacheImage() );
            // Changed to enable anti aliasing by default in QGIS 1.7
            if ( mySettings.value( "/qgis/enable_anti_aliasing", true ).toBool() )
            {
              mypPainter->setRenderHint( QPainter::Antialiasing );
            }
            mRenderContext.setPainter( mypPainter );
          }
          else if ( mySameAsLastFlag )
          {
            //draw from cached image
            QgsDebugMsg( "Caching enabled --- drawing layer from cached image" );
            mypContextPainter->drawImage( 0, 0, *( ml->cacheImage() ) );
            disconnect( ml, SIGNAL( drawingProgress( int, int ) ), this, SLOT( onDrawingProgress( int, int ) ) );
            //short circuit as there is nothing else to do...
            continue;
          }
        }
      }

      // If we are drawing with an alternative blending mode then we need to render to a separate image
      // before compositing this on the map. This effectively flattens the layer and prevents
      // blending occuring between objects on the layer
      // (this is not required for raster layers or when layer caching is enabled, since that has the same effect)
      bool flattenedLayer = false;
      if (( mRenderContext.useAdvancedEffects() ) && ( ml->type() == QgsMapLayer::VectorLayer ) )
      {
        QgsVectorLayer* vl = qobject_cast<QgsVectorLayer *>( ml );
        if (( !useRenderCaching )
            && (( vl->blendMode() != QPainter::CompositionMode_SourceOver )
                || ( vl->featureBlendMode() != QPainter::CompositionMode_SourceOver )
                || ( vl->layerTransparency() != 0 ) ) )
        {
          flattenedLayer = true;
          mypFlattenedImage = new QImage( mRenderContext.painter()->device()->width(),
                                          mRenderContext.painter()->device()->height(), QImage::Format_ARGB32 );
          if ( mypFlattenedImage->isNull() )
          {
            QgsDebugMsg( "insufficient memory for image " + QString::number( mRenderContext.painter()->device()->width() ) + "x" + QString::number( mRenderContext.painter()->device()->height() ) );
            emit drawError( ml );
            painter->end(); // drawError is not caught by anyone, so we end painting to notify caller
            return;
          }
          mypFlattenedImage->fill( 0 );
          QPainter * mypPainter = new QPainter( mypFlattenedImage );
          if ( mySettings.value( "/qgis/enable_anti_aliasing", true ).toBool() )
          {
            mypPainter->setRenderHint( QPainter::Antialiasing );
          }
          mypPainter->scale( rasterScaleFactor,  rasterScaleFactor );
          mRenderContext.setPainter( mypPainter );
        }
      }

      // Per feature blending mode
      if (( mRenderContext.useAdvancedEffects() ) && ( ml->type() == QgsMapLayer::VectorLayer ) )
      {
        QgsVectorLayer* vl = qobject_cast<QgsVectorLayer *>( ml );
        if ( vl->featureBlendMode() != QPainter::CompositionMode_SourceOver )
        {
          // set the painter to the feature blend mode, so that features drawn
          // on this layer will interact and blend with each other
          mRenderContext.painter()->setCompositionMode( vl->featureBlendMode() );
        }
      }

      if ( scaleRaster )
      {
        bk_mapToPixel = mRenderContext.mapToPixel();
        rasterMapToPixel = mRenderContext.mapToPixel();
        rasterMapToPixel.setMapUnitsPerPixel( mRenderContext.mapToPixel().mapUnitsPerPixel() / rasterScaleFactor );
        rasterMapToPixel.setYMaximum( mSize.height() * rasterScaleFactor );
        mRenderContext.setMapToPixel( rasterMapToPixel );
        mRenderContext.painter()->save();
        mRenderContext.painter()->scale( 1.0 / rasterScaleFactor, 1.0 / rasterScaleFactor );
      }

      if ( !ml->draw( mRenderContext ) )
      {
        emit drawError( ml );
      }
      else
      {
        QgsDebugMsg( "Layer rendered without issues" );
      }

      if ( split )
      {
        mRenderContext.setExtent( r2 );
        if ( !ml->draw( mRenderContext ) )
        {
          emit drawError( ml );
        }
      }

      if ( scaleRaster )
      {
        mRenderContext.setMapToPixel( bk_mapToPixel );
        mRenderContext.painter()->restore();
      }

      //apply layer transparency for vector layers
      if (( mRenderContext.useAdvancedEffects() ) && ( ml->type() == QgsMapLayer::VectorLayer ) )
      {
        QgsVectorLayer* vl = qobject_cast<QgsVectorLayer *>( ml );
        if ( vl->layerTransparency() != 0 )
        {
          // a layer transparency has been set, so update the alpha for the flattened layer
          // by combining it with the layer transparency
          QColor transparentFillColor = QColor( 0, 0, 0, 255 - ( 255 * vl->layerTransparency() / 100 ) );
          // use destination in composition mode to merge source's alpha with destination
          mRenderContext.painter()->setCompositionMode( QPainter::CompositionMode_DestinationIn );
          mRenderContext.painter()->fillRect( 0, 0, mRenderContext.painter()->device()->width(),
                                              mRenderContext.painter()->device()->height(), transparentFillColor );
        }
      }

      if ( useRenderCaching )
      {
        // composite the cached image into our view and then clean up from caching
        // by reinstating the painter as it was swapped out for caching renders
        delete mRenderContext.painter();
        mRenderContext.setPainter( mypContextPainter );
        //draw from cached image that we created further up
        if ( ml->cacheImage() )
          mypContextPainter->drawImage( 0, 0, *( ml->cacheImage() ) );
      }
      else if ( flattenedLayer )
      {
        // If we flattened this layer for alternate blend modes, composite it now
        delete mRenderContext.painter();
        mRenderContext.setPainter( mypContextPainter );
        mypContextPainter->save();
        mypContextPainter->scale( 1.0 / rasterScaleFactor, 1.0 / rasterScaleFactor );
        mypContextPainter->drawImage( 0, 0, *( mypFlattenedImage ) );
        mypContextPainter->restore();
        delete mypFlattenedImage;
        mypFlattenedImage = 0;
      }

      disconnect( ml, SIGNAL( drawingProgress( int, int ) ), this, SLOT( onDrawingProgress( int, int ) ) );
    }
int QgsServerProjectUtils::wmsMaxHeight( const QgsProject &project )
{
  return project.readNumEntry( QStringLiteral( "WMSMaxHeight" ), QStringLiteral( "/" ), -1 );
}
int QgsServerProjectUtils::wfsLayerPrecision( const QgsProject &project, const QString &layerId )
{
  return project.readNumEntry( QStringLiteral( "WFSLayersPrecision" ), "/" + layerId, 6 );
}
int QgsServerProjectUtils::wmsFeatureInfoPrecision( const QgsProject &project )
{
  return project.readNumEntry( QStringLiteral( "WMSPrecision" ), QStringLiteral( "/" ), 6 );
}
Beispiel #10
0
int QgsServerProjectUtils::wmsMaxAtlasFeatures( const QgsProject &project )
{
  return project.readNumEntry( QStringLiteral( "WMSMaxAtlasFeatures" ), QStringLiteral( "/" ), 1 );
}
Beispiel #11
0
int QgsServerProjectUtils::wmsImageQuality( const QgsProject &project )
{
  return project.readNumEntry( QStringLiteral( "WMSImageQuality" ), QStringLiteral( "/" ), -1 );
}
Beispiel #12
0
void spatialPlotDlg::generate()
{
  QDir dir = QDir::home();
  QString home = dir.homePath();
  QString logFileName(home+"/log.html");
  ofstream log;
  log.open(qPrintable(logFileName), ios::out);
  log<<"<html><body><br><font size=3 color=black><p> Running... ";      //</p></font></body></html>";
  log.close();
  textBrowser->setSource(logFileName);
  textBrowser->setFocus();
  textBrowser->setModified(TRUE);
  QApplication::processEvents();

  QgsProject *p = QgsProject::instance();
  QString projDir = p->readPath(p->readEntry("pihm", "projDir"));

  int bins;
  double **avgVal;

  int tabIndex;
  int variableIndex;
  int startTime, finishTime;
  int NUM_STEPS;
  int dataCount = 0;
  char fStr[100];

  int runFlag = 1;
  QString shapeFileName, outputFileName;
  ifstream inStream, inStream2;

  int NUM_ELE = 0;
  int NUM_RIV = 0;

  tabIndex = tabWidget->currentIndex();
  if(tabIndex == ELEMENT_FEATURE)
  {
    variableIndex = comboBoxEleVariable->currentIndex();
    startTime  = ( lineEditEleStart->text() ).toInt();
    finishTime = ( lineEditEleFinish->text() ).toInt();

    bins = lineEditBinsEle->text().toInt();
    int units = comboBoxEle->currentIndex();
    units = units==0 ? 1 : units==1 ? 60 : 1440;           // how many minutes
    // intercep, sat, unsat, surf, evap, trans, evap gw/sw, prep ??, nprep ??, infil ??, rech
    //                  106, 101, 107, 102, 108, 108, 108, 101, 101, 101, 105
    const int index[] = {5, 0, 6, 1, 7, 7, 7, 0, 0, 0, 4};
    QString var("step%1");
    int steps = p->readNumEntry("pihm", var.arg(index[comboBoxEleVariable->currentIndex()]));

    startTime = startTime*units / steps; cout << "Start Row= "<<startTime<<"\n";
    finishTime= finishTime*units/ steps; cout << "FinishRow= "<<finishTime<<"\n";

    shapeFileName  = lineEditEleShape->text();
    outputFileName = lineEditFileName->text();

    NUM_STEPS = finishTime - startTime + 1;
    cout<<"NUM_STEPS= "<<NUM_STEPS<<"\n";
    //getchar(); getchar();
    if( outputFileName.endsWith("txt", Qt::CaseInsensitive) ) {
      inStream.open( qPrintable(outputFileName) );
      if(inStream == NULL) {
        QMessageBox::critical(this, "Couldn't Open File", outputFileName);
        return;
        //exit(1);
      }
      string str;
      getline(inStream, str);
      int pos = 0;
      while( (pos = str.find('\t', pos+1) ) != -1 ) {
        NUM_ELE++;
      }
      cout << "NUM_ELE= "<<NUM_ELE<<"\n";
      inStream.close();
      inStream.open(qPrintable(outputFileName));
      avgVal = (double **)malloc(bins * sizeof(double *));
      for(int i=0; i<bins; i++) {
        avgVal[i] = (double *)malloc(NUM_ELE * sizeof(double));
        for(int j=0; j<NUM_ELE; j++)
          avgVal[i][j] = 0.0;
      }

      for(int i=1; i<startTime; i++)
        getline(inStream, str);
      if(inStream == NULL) {
        qWarning("Error: File ended Prematurely!\n       Cannot parse \"Start Time\" provided.\n");
        runFlag = 0;
      }
      if(runFlag != 0) {
        double temp;
        for(int b=0; b<bins; b++) {
          for(int i=0; i<NUM_STEPS/bins; i++) {
            if(inStream) {
              for(int j=0; j<NUM_ELE; j++) {
                inStream >> temp;
                avgVal[b][j]+=temp;
              }
              dataCount++;
            }
            else{
              dataCount--;
              break;
            }
          }
        }