[Kstars-devel] KDE/kdeedu/kstars/kstars

Alexey Khudyakov alexey.skladnoy at gmail.com
Fri Jul 31 21:53:37 CEST 2009


SVN commit 1005321 by khudyakov:

Add function for reading and writing list of FOVs from/to fov.dat

Add function ot return list of default FOVs.

CCMAIL: kstars-devel at kde.org


 M  +94 -0     fov.cpp  
 M  +8 -0      fov.h  


--- trunk/KDE/kdeedu/kstars/kstars/fov.cpp #1005320:1005321
@@ -179,3 +179,97 @@
 {
     m_shape = intToShape(s);
 }
+
+
+QList<FOV*> FOV::defaults()
+{
+    QList<FOV*> fovs;
+    fovs << new FOV(i18nc("use field-of-view for binoculars", "7x35 Binoculars" ),
+                    558,  558,  CIRCLE,"#AAAAAA")
+         << new FOV(i18nc("use a Telrad field-of-view indicator", "Telrad" ),
+                    30,   30,   CROSSHAIRS,"#AA0000")
+         << new FOV(i18nc("use 1-degree field-of-view indicator", "One Degree"),
+                    60,   60,   CIRCLE,"#AAAAAA")
+         << new FOV(i18nc("use HST field-of-view indicator", "HST WFPC2"),
+                    2.4,  2.4,  SQUARE,"#AAAAAA")
+         << new FOV(i18nc("use Radiotelescope HPBW", "30m at 1.3cm" ),
+                    1.79, 1.79, SQUARE,"#AAAAAA");
+    return fovs;
+}
+
+void FOV::writeFOVs(const QList<FOV*> fovs)
+{
+    QFile f;
+    f.setFileName( KStandardDirs::locateLocal( "appdata", "fov.dat" ) );
+
+    if ( ! f.open( QIODevice::WriteOnly ) ) {
+        kDebug() << i18n( "Could not open fov.dat." );
+        return;
+    }
+    QTextStream ostream(&f);
+    foreach(FOV* fov, fovs) {
+        ostream << fov->name()  << ':'
+                << fov->sizeX() << ':'
+                << fov->sizeY() << ':'
+                << QString::number( fov->shape() ) << ':' //FIXME: is this needed???
+                << fov->color() << endl;
+    }
+    f.close();
+}
+
+QList<FOV*> FOV::readFOVs()
+{
+    QFile f;
+    QList<FOV*> fovs;
+    f.setFileName( KStandardDirs::locateLocal( "appdata", "fov.dat" ) );
+
+    if( !f.exists() ) {
+        fovs = defaults();
+        writeFOVs(fovs);
+        return fovs;
+    }
+
+    if( f.open(QIODevice::ReadOnly) ) {
+        fovs.clear();
+        QTextStream istream(&f);
+        while( !istream.atEnd() ) {
+            QStringList fields = istream.readLine().split(':');
+            bool ok;
+            QString name, color;
+            float   sizeX, sizeY;
+            Shape   shape;
+            if( fields.count() == 4 ) {
+                name = fields[1];
+                sizeX = fields[1].toFloat(&ok);
+                if( !ok ) {
+                    return QList<FOV*>();
+                }
+                sizeY = sizeX;
+                shape = intToShape( fields[2].toInt(&ok) );
+                if( !ok ) {
+                    return QList<FOV*>();
+                }
+                color = fields[3];
+            } else if( fields.count() == 5 ) {
+                name = fields[1];
+                sizeX = fields[1].toFloat(&ok);
+                if( !ok ) {
+                    return QList<FOV*>();
+                }
+                sizeY = fields[2].toFloat(&ok);
+                if( !ok ) {
+                    return QList<FOV*>();
+                }
+                shape = intToShape( fields[3].toInt(&ok) );
+                if( !ok ) {
+                    return QList<FOV*>();
+                }
+                color = fields[4];
+            } else {
+                continue;
+            }
+            fovs.append( new FOV(name, sizeX, sizeY, shape, color) );
+        }
+    }
+    return fovs;
+}
--- trunk/KDE/kdeedu/kstars/kstars/fov.h #1005320:1005321
@@ -18,6 +18,8 @@
 #ifndef FOV_H_
 #define FOV_H_
 
+#include <QList>
+
 #include <qstring.h>
 #include <klocale.h>
 
@@ -64,6 +66,12 @@
     	*/
     void draw( QPainter &p, float pixelSizeX, float pixelSizeY=-1 );
 
+    /** @short Fill list with default FOVs*/
+    static QList<FOV*> defaults();
+    /** @short Write list of FOVs to "fov.dat" */
+    static void writeFOVs(const QList<FOV*> fovs);
+    /** @short Read list of FOVs from "fov.dat" */
+    static QList<FOV*>readFOVs();
 private:
     QString m_name,  m_color;
     float   m_sizeX, m_sizeY;


More information about the Kstars-devel mailing list