mirror of
				https://github.com/qgis/QGIS.git
				synced 2025-11-04 00:04:25 -05:00 
			
		
		
		
	Added SIP, fixed qgisapp to use new setter and optimized a bit
This commit is contained in:
		
							parent
							
								
									01c4ac7d54
								
							
						
					
					
						commit
						d1c8884ca1
					
				@ -12,6 +12,28 @@ class QgsScaleComboBox : QComboBox
 | 
			
		||||
    QgsScaleComboBox(QWidget * parent = 0);
 | 
			
		||||
    ~QgsScaleComboBox();
 | 
			
		||||
 | 
			
		||||
    //! Function to read the selected scale as text
 | 
			
		||||
    // @note added in 2.0
 | 
			
		||||
    QString scaleString();
 | 
			
		||||
    //! Function to set the selected scale from text
 | 
			
		||||
    // @note added in 2.0
 | 
			
		||||
    bool setScaleString( QString scaleTxt );
 | 
			
		||||
    //! Function to read the selected scale as double
 | 
			
		||||
    // @note added in 2.0
 | 
			
		||||
    double scale();
 | 
			
		||||
    //! Function to set the selected scale from double
 | 
			
		||||
    // @note added in 2.0
 | 
			
		||||
    void setScale( double scale );
 | 
			
		||||
 
 | 
			
		||||
   //! Helper function to convert a double to scale string
 | 
			
		||||
    // Performs rounding, so an exact representation is not to
 | 
			
		||||
    // be expected.
 | 
			
		||||
    // @note added in 2.0
 | 
			
		||||
    static QString toString( double scale );
 | 
			
		||||
    //! Helper function to convert a scale string to double
 | 
			
		||||
    // @note added in 2.0
 | 
			
		||||
    static double toDouble( QString scaleString, bool *ok = NULL );
 | 
			
		||||
 | 
			
		||||
  public slots:
 | 
			
		||||
    void updateScales( const QStringList &scales = QStringList() );
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
@ -1467,16 +1467,10 @@ void QgisApp::createStatusBar()
 | 
			
		||||
  mScaleEdit->setMaximumWidth( 100 );
 | 
			
		||||
  mScaleEdit->setMaximumHeight( 20 );
 | 
			
		||||
  mScaleEdit->setContentsMargins( 0, 0, 0, 0 );
 | 
			
		||||
  // QRegExp validator( "\\d+\\.?\\d*:\\d+\\.?\\d*" );
 | 
			
		||||
  // QRegExp validator( "\\d+\\.?\\d*:\\d+\\.?\\d*|\\d+\\.?\\d*" );
 | 
			
		||||
  // mScaleEditValidator = new QRegExpValidator( validator, mScaleEdit );
 | 
			
		||||
  // mScaleEdit->setValidator( mScaleEditValidator );
 | 
			
		||||
  mScaleEdit->setWhatsThis( tr( "Displays the current map scale" ) );
 | 
			
		||||
  mScaleEdit->setToolTip( tr( "Current map scale (formatted as x:y)" ) );
 | 
			
		||||
 | 
			
		||||
  statusBar()->addPermanentWidget( mScaleEdit, 0 );
 | 
			
		||||
  //connect( mScaleEdit, SIGNAL( currentIndexChanged( const QString & ) ), this, SLOT( userScale() ) );
 | 
			
		||||
  //connect( mScaleEdit->lineEdit(), SIGNAL( editingFinished() ), this, SLOT( userScale() ) );
 | 
			
		||||
  connect( mScaleEdit, SIGNAL( scaleChanged() ), this, SLOT( userScale() ) );
 | 
			
		||||
 | 
			
		||||
  //stop rendering status bar widget
 | 
			
		||||
@ -5250,15 +5244,10 @@ void QgisApp::showMouseCoordinate( const QgsPoint & p )
 | 
			
		||||
 | 
			
		||||
void QgisApp::showScale( double theScale )
 | 
			
		||||
{
 | 
			
		||||
  if ( theScale >= 1.0 )
 | 
			
		||||
    mScaleEdit->setEditText( "1:" + QString::number( theScale, 'f', 0 ) );
 | 
			
		||||
  else if ( theScale > 0.0 )
 | 
			
		||||
    mScaleEdit->setEditText( QString::number( 1.0 / theScale, 'f', 0 ) + ":1" );
 | 
			
		||||
  else
 | 
			
		||||
    mScaleEdit->setEditText( tr( "Invalid scale" ) );
 | 
			
		||||
 | 
			
		||||
  mOldScale = mScaleEdit->currentText();
 | 
			
		||||
  // Why has MapCanvas the scale inverted?
 | 
			
		||||
  mScaleEdit->setScale( 1.0 / theScale );
 | 
			
		||||
 | 
			
		||||
  // Not sure if the lines below do anything meaningful /Homann
 | 
			
		||||
  if ( mScaleEdit->width() > mScaleEdit->minimumWidth() )
 | 
			
		||||
  {
 | 
			
		||||
    mScaleEdit->setMinimumWidth( mScaleEdit->width() );
 | 
			
		||||
@ -5267,7 +5256,7 @@ void QgisApp::showScale( double theScale )
 | 
			
		||||
 | 
			
		||||
void QgisApp::userScale()
 | 
			
		||||
{
 | 
			
		||||
  // Why has MapCanvas the scale inversed?
 | 
			
		||||
  // Why has MapCanvas the scale inverted?
 | 
			
		||||
  mMapCanvas->zoomScale( 1.0 / mScaleEdit->scale() );
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -1236,8 +1236,6 @@ class QgisApp : public QMainWindow, private Ui::MainWindow
 | 
			
		||||
 | 
			
		||||
    bool cmpByText( QAction* a, QAction* b );
 | 
			
		||||
 | 
			
		||||
    QString mOldScale;
 | 
			
		||||
 | 
			
		||||
    //! the user has trusted the project macros
 | 
			
		||||
    bool mTrustedMacros;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -16,6 +16,7 @@
 | 
			
		||||
 ***************************************************************************/
 | 
			
		||||
 | 
			
		||||
#include "qgis.h"
 | 
			
		||||
#include "qgslogger.h"
 | 
			
		||||
#include "qgsscalecombobox.h"
 | 
			
		||||
 | 
			
		||||
#include <QAbstractItemView>
 | 
			
		||||
@ -30,7 +31,7 @@ QgsScaleComboBox::QgsScaleComboBox( QWidget* parent ) : QComboBox( parent )
 | 
			
		||||
  setEditable( true );
 | 
			
		||||
  setInsertPolicy( QComboBox::NoInsert );
 | 
			
		||||
  setCompleter( 0 );
 | 
			
		||||
  connect( this, SIGNAL( currentIndexChanged( const QString & ) ), this, SLOT( fixupScale() ) );
 | 
			
		||||
  connect( this, SIGNAL( activated( const QString & ) ), this, SLOT( fixupScale() ) );
 | 
			
		||||
  connect( lineEdit(), SIGNAL( editingFinished() ), this, SLOT( fixupScale() ) );
 | 
			
		||||
  fixupScale();
 | 
			
		||||
}
 | 
			
		||||
@ -65,7 +66,7 @@ void QgsScaleComboBox::updateScales( const QStringList &scales )
 | 
			
		||||
  blockSignals( true );
 | 
			
		||||
  clear();
 | 
			
		||||
  addItems( myScalesList );
 | 
			
		||||
  setEditText( oldScale );
 | 
			
		||||
  setScaleString( oldScale );
 | 
			
		||||
  blockSignals( false );
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -148,18 +149,25 @@ void QgsScaleComboBox::fixupScale()
 | 
			
		||||
  bool ok;
 | 
			
		||||
  QStringList txtList;
 | 
			
		||||
 | 
			
		||||
  // QgsDebugMsg( QString( "entered with oldScale: %1" ).arg( oldScale ) );
 | 
			
		||||
  newScale = toDouble( currentText(), &ok );
 | 
			
		||||
  if ( ok )
 | 
			
		||||
  {
 | 
			
		||||
    mScale = newScale;
 | 
			
		||||
    // Valid string representation
 | 
			
		||||
    if ( newScale != oldScale )
 | 
			
		||||
    {
 | 
			
		||||
      // Scale has change, update.
 | 
			
		||||
      // QgsDebugMsg( QString( "New scale OK!: %1" ).arg( newScale ) );
 | 
			
		||||
      mScale = newScale;
 | 
			
		||||
      setScale( mScale );
 | 
			
		||||
      emit scaleChanged();
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
  // We set to the new string representation
 | 
			
		||||
  // or reset to the old
 | 
			
		||||
  setScale( mScale );
 | 
			
		||||
 | 
			
		||||
  if ( oldScale != mScale )
 | 
			
		||||
  else
 | 
			
		||||
  {
 | 
			
		||||
    emit scaleChanged();
 | 
			
		||||
    // Invalid string representation
 | 
			
		||||
    // Reset to the old
 | 
			
		||||
    setScale( mScale );
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user