-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
move map scale selector to QgsScaleComboBox class. Highlight nearest
value to the current scale when open selectors popup
- Loading branch information
Showing
7 changed files
with
132 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
|
||
/** A combobox which lets the user select map scale from predefined list | ||
* and highlights nearest to current scale valu | ||
*/ | ||
class QgsScaleComboBox : QComboBox | ||
{ | ||
%TypeHeaderCode | ||
#include <qgsscalecombobox.h> | ||
%End | ||
|
||
public: | ||
QgsScaleComboBox(QWidget * parent = 0); | ||
~QgsScaleComboBox(); | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/*************************************************************************** | ||
qgsscalecombobox.h | ||
------------------------ | ||
begin : January 7, 2012 | ||
copyright : (C) 2012 by Alexander Bruy | ||
email : alexander dot bruy at gmail dot com | ||
***************************************************************************/ | ||
|
||
/*************************************************************************** | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
***************************************************************************/ | ||
|
||
#include "qgsscalecombobox.h" | ||
|
||
#include <QAbstractItemView> | ||
|
||
QgsScaleComboBox::QgsScaleComboBox( QWidget* parent ) : QComboBox( parent ) | ||
{ | ||
// make combobox editable and populate with predefined scales | ||
setEditable( true ); | ||
addItem( "1:1000000" ); | ||
addItem( "1:500000" ); | ||
addItem( "1:250000" ); | ||
addItem( "1:100000" ); | ||
addItem( "1:50000" ); | ||
addItem( "1:25000" ); | ||
addItem( "1:10000" ); | ||
addItem( "1:5000" ); | ||
addItem( "1:2500" ); | ||
addItem( "1:1000" ); | ||
addItem( "1:500" ); | ||
|
||
setInsertPolicy( QComboBox::NoInsert ); | ||
} | ||
|
||
QgsScaleComboBox::~QgsScaleComboBox() | ||
{ | ||
} | ||
|
||
void QgsScaleComboBox::showPopup() | ||
{ | ||
QComboBox::showPopup(); | ||
|
||
QStringList parts = currentText().split( ':' ); | ||
bool ok; | ||
int idx = 0; | ||
int min = 999999; | ||
long currScale = parts.at( 1 ).toLong( &ok ); | ||
long nextScale, delta; | ||
for ( int i = 0; i < count(); i++ ) | ||
{ | ||
parts = itemText( i ).split( ':' ); | ||
nextScale = parts.at( 1 ).toLong( &ok ); | ||
delta = qAbs( currScale - nextScale ); | ||
if( delta < min ) | ||
{ | ||
min = delta; | ||
idx = i; | ||
} | ||
} | ||
|
||
blockSignals( true ); | ||
view()->setCurrentIndex( model()->index( idx, 0 ) ); | ||
blockSignals( false ); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/*************************************************************************** | ||
qgsscalecombobox.h | ||
------------------------ | ||
begin : January 7, 2012 | ||
copyright : (C) 2012 by Alexander Bruy | ||
email : alexander dot bruy at gmail dot com | ||
***************************************************************************/ | ||
|
||
/*************************************************************************** | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
***************************************************************************/ | ||
|
||
#ifndef QGSSCALECOMBOBOX_H | ||
#define QGSSCALECOMBOBOX_H | ||
|
||
#include <QComboBox> | ||
|
||
/** \ingroup gui | ||
* A combobox which lets the user select map scale from predefined list | ||
* and highlights nearest to current scale valu | ||
**/ | ||
class GUI_EXPORT QgsScaleComboBox : public QComboBox | ||
{ | ||
Q_OBJECT | ||
public: | ||
QgsScaleComboBox( QWidget* parent = 0 ); | ||
virtual ~QgsScaleComboBox(); | ||
|
||
protected: | ||
void showPopup(); | ||
}; | ||
|
||
#endif // QGSSCALECOMBOBOX_H |