[Kstars-devel] KDE/kdeedu/kstars/kstars
Alexey Khudyakov
alexey.skladnoy at gmail.com
Fri Jul 31 21:50:25 CEST 2009
SVN commit 1005320 by khudyakov:
Make type of FOV an enumration and enforce its use via type
system. Nothing in particular just for little bit of type
safety and magic number avoidance.
Change class members names so they have m_ prefix.
CCMAIL: kstars-devel at kde.org
M +5 -3 dialogs/fovdialog.cpp
M +31 -20 fov.cpp
M +25 -15 fov.h
--- trunk/KDE/kdeedu/kstars/kstars/dialogs/fovdialog.cpp #1005319:1005320
@@ -105,7 +105,7 @@
}
if ( ok ) {
- FOV *newfov = new FOV( nm, sx, sy, sh, cl );
+ FOV *newfov = new FOV( nm, sx, sy, FOV::intToShape(sh), cl );
fov->FOVListBox->addItem( nm );
FOVList.append( newfov );
@@ -144,7 +144,8 @@
if ( newfdlg->exec() == QDialog::Accepted ) {
FOV *newfov = new FOV( newfdlg->ui->FOVName->text(), fovsizeX, fovsizeY,
- newfdlg->ui->ShapeBox->currentIndex(), newfdlg->ui->ColorButton->color().name() );
+ FOV::intToShape(newfdlg->ui->ShapeBox->currentIndex()),
+ newfdlg->ui->ColorButton->color().name() );
FOVList.append( newfov );
@@ -173,7 +174,8 @@
double fovsizeX = newfdlg.ui->FOVEditX->text().replace( KGlobal::locale()->decimalSymbol(), "." ).toDouble();
double fovsizeY = newfdlg.ui->FOVEditY->text().replace( KGlobal::locale()->decimalSymbol(), "." ).toDouble();
FOV *newfov = new FOV( newfdlg.ui->FOVName->text(), fovsizeX, fovsizeY,
- newfdlg.ui->ShapeBox->currentIndex(), newfdlg.ui->ColorButton->color().name() );
+ FOV::intToShape(newfdlg.ui->ShapeBox->currentIndex()),
+ newfdlg.ui->ColorButton->color().name() );
fov->FOVListBox->currentItem()->setText( newfdlg.ui->FOVName->text() );
--- trunk/KDE/kdeedu/kstars/kstars/fov.cpp #1005319:1005320
@@ -25,12 +25,18 @@
#include <klocale.h>
#include <kstandarddirs.h>
-FOV::FOV( const QString &n, float a, float b, int sh, const QString &col ) : Name( n ), Color( col ), SizeX( a ), Shape( sh )
-{
- SizeY = (b < 0.0) ? a : b;
-}
+FOV::Shape FOV::intToShape(int s)
+{
+ return (s >= FOV::UNKNOWN || s < 0) ? FOV::UNKNOWN : static_cast<FOV::Shape>(s);
+}
-FOV::FOV() : Name( i18n( "No FOV" ) ), Color( "#FFFFFF" ), SizeX( 0.0 ), SizeY( 0.0 ), Shape( 0 )
+FOV::FOV( const QString &n, float a, float b, Shape sh, const QString &col ) :
+ m_name( n ), m_color( col ), m_sizeX( a ), m_shape( sh )
+{
+ m_sizeY = (b < 0.0) ? a : b;
+}
+
+FOV::FOV() : m_name( i18n( "No FOV" ) ), m_color( "#FFFFFF" ), m_sizeX( 0.0 ), m_sizeY( 0.0 ), m_shape( SQUARE )
{}
FOV::FOV( const QString &sname ) {
@@ -73,11 +79,11 @@
if( !ok )
break;
++index;
- Name = fields[0];
- SizeX = sx;
- SizeY = sy;
- Shape = sh;
- Color = fields[index];
+ m_name = fields[0];
+ m_sizeX = sx;
+ m_sizeY = sy;
+ m_shape = intToShape(sh);
+ m_color = fields[index];
return;
}
}
@@ -85,11 +91,11 @@
}
//If we get here, then the symbol could not be assigned
- Name = i18n( "No FOV" );
- SizeX = 0.0;
- SizeY = 0.0;
- Shape = 0;
- Color = "#FFFFFF";
+ m_name = i18n( "No FOV" );
+ m_sizeX = 0.0;
+ m_sizeY = 0.0;
+ m_shape = UNKNOWN;
+ m_color = "#FFFFFF";
}
void FOV::draw( QPainter &p, float pixelSizeX, float pixelSizeY ) {
@@ -105,15 +111,15 @@
int sy = int( pixelSizeY );
switch ( shape() ) {
- case 0: { //Square
+ case SQUARE: { //Square
p.drawRect( (w - sx)/2, (h - sy)/2, sx, sy );
break;
}
- case 1: { //Circle
+ case CIRCLE: { //Circle
p.drawEllipse( (w - sx)/2, (h - sy)/2, sx, sy );
break;
}
- case 2: { //Crosshairs
+ case CROSSHAIRS: { //Crosshairs
int sx1 = sx;
int sy1 = sy;
int sx2 = 2 * sx;
@@ -138,7 +144,7 @@
break;
}
- case 3: { //Bullseye
+ case BULLSEYE: { //Bullseye
int sx1 = sx;
int sy1 = sy;
int sx2 = 4 * sx;
@@ -157,7 +163,7 @@
break;
}
- case 4: { // Solid Circle
+ case SOLIDCIRCLE: { // Solid Circle
QColor colorAlpha( color() );
colorAlpha.setAlpha(127);
p.setBrush( QBrush ( colorAlpha ) );
@@ -165,6 +171,11 @@
p.setBrush(Qt::NoBrush);
break;
}
+ default: ;
}
}
+void FOV::setShape( int s)
+{
+ m_shape = intToShape(s);
+}
--- trunk/KDE/kdeedu/kstars/kstars/fov.h #1005319:1005320
@@ -29,25 +29,35 @@
*/
class FOV {
public:
+ enum Shape { SQUARE,
+ CIRCLE,
+ CROSSHAIRS,
+ BULLSEYE,
+ SOLIDCIRCLE,
+ UNKNOWN };
+ static FOV::Shape intToShape(int);
+
/**Default constructor*/
FOV();
FOV( const QString &name ); //in this case, read params from fov.dat
- FOV( const QString &name, float a, float b=-1, int shape=0, const QString &color="#FFFFFF" );
+ FOV( const QString &name, float a, float b=-1, Shape shape=SQUARE, const QString &color="#FFFFFF" );
~FOV() {}
- // enum SHAPE { FOV_SQUARE=0, FOV_CIRCLE=1, FOV_CROSSHAIRS=2, FOV_BULLSEYE=3, FOV_UNKNOWN };
+ inline QString name() const { return m_name; }
+ void setName( const QString &n ) { m_name = n; }
- inline QString name() const { return Name; }
- void setName( const QString &n ) { Name = n; }
- inline int shape() const { return Shape; }
- void setShape( int s ) { Shape = s; }
- inline float sizeX() const { return SizeX; }
- inline float sizeY() const { return SizeY; }
- void setSize( float s ) { SizeX = SizeY = s; }
- void setSize( float sx, float sy ) { SizeX = sx; SizeY = sy; }
- inline QString color() const { return Color; }
- void setColor( const QString &c ) { Color = c; }
+ inline Shape shape() const { return m_shape; }
+ void setShape( Shape s ) { m_shape = s; }
+ void setShape( int s);
+
+ inline float sizeX() const { return m_sizeX; }
+ inline float sizeY() const { return m_sizeY; }
+ void setSize( float s ) { m_sizeX = m_sizeY = s; }
+ void setSize( float sx, float sy ) { m_sizeX = sx; m_sizeY = sy; }
+ inline QString color() const { return m_color; }
+ void setColor( const QString &c ) { m_color = c; }
+
/**@short draw the FOV symbol on a QPainter
*@param p reference to the target QPainter. The painter should already be started.
*@param size the size of the target symbol, in pixels.
@@ -55,9 +65,9 @@
void draw( QPainter &p, float pixelSizeX, float pixelSizeY=-1 );
private:
- QString Name, Color;
- float SizeX, SizeY;
- int Shape;
+ QString m_name, m_color;
+ float m_sizeX, m_sizeY;
+ Shape m_shape;
};
#endif
More information about the Kstars-devel
mailing list