[Kstars-devel] KDE/kdeedu/kstars/kstars/tools
Akarsh Simha
akarshsimha at gmail.com
Tue May 19 06:45:49 CEST 2009
SVN commit 969848 by asimha:
Applying Alexey Khudyakov's third patch refactoring the astro
calculator. Quoting from his description:
Items in navigation panel are allocated by two helper functions. They
also fill two maps. First: item name -> widget in stack, second: name
-> help text.
Although it may appear to at first sight, it looks like the patch
doesn't add any new strings. Thanks Alexey!
CCMAIL: kstars-devel at kde.org
M +40 -26 astrocalc.cpp
M +17 -0 astrocalc.h
--- trunk/KDE/kdeedu/kstars/kstars/tools/astrocalc.cpp #969847:969848
@@ -61,32 +61,6 @@
QIcon sunsetIcon = QIcon ("sunset.png");
QIcon timeIcon = QIcon ("sunclock.png");
- //Populate the tree widget
- QTreeWidgetItem * timeItem = new QTreeWidgetItem(navigationPanel,QStringList(i18n("Time Calculators")) );
- timeItem->setIcon(0,timeIcon);
-
- QTreeWidgetItem * jdItem = new QTreeWidgetItem(timeItem,QStringList(i18n("Julian Day")) );
- jdItem->setIcon(0,jdIcon);
-
- new QTreeWidgetItem(timeItem,QStringList(i18n("Sidereal Time")) );
- new QTreeWidgetItem(timeItem,QStringList(i18n("Almanac")) );
- new QTreeWidgetItem(timeItem,QStringList(i18n("Equinoxes & Solstices")) );
- // dayItem->setIcon(0,sunsetIcon);
-
- QTreeWidgetItem * coordItem = new QTreeWidgetItem(navigationPanel,QStringList(i18n("Coordinate Converters")) );
- new QTreeWidgetItem(coordItem,QStringList(i18n("Equatorial/Galactic")) );
- new QTreeWidgetItem(coordItem,QStringList(i18n("Apparent Coordinates")) );
- new QTreeWidgetItem(coordItem,QStringList(i18n("Horizontal Coordinates")) );
- new QTreeWidgetItem(coordItem,QStringList(i18n("Ecliptic Coordinates")) );
- new QTreeWidgetItem(coordItem,QStringList(i18n("Angular Distance")) );
- new QTreeWidgetItem(coordItem,QStringList(i18n("Geodetic Coordinates")) );
- new QTreeWidgetItem(coordItem,QStringList(i18n("LSR Velocity")) );
-
- QTreeWidgetItem * solarItem = new QTreeWidgetItem(navigationPanel,QStringList(i18n("Solar System")) );
- solarItem->setIcon(0,solarIcon);
- new QTreeWidgetItem(solarItem,QStringList(i18n("Planets Coordinates")) );
- new QTreeWidgetItem(solarItem,QStringList(i18n("Conjunctions")) );
-
//FIXME: Would be better to make the navigationPanel fit its contents,
//but I wasn't able to make it work
navigationPanel->setMinimumWidth( 200 );
@@ -132,7 +106,33 @@
ConjunctFrame = addToStack<ConjunctionsTool>();
acStack->setCurrentWidget( splashScreen );
+
+ //Populate the tree widget
+ QTreeWidgetItem * timeItem = addTreeTopItem(navigationPanel, i18n("Time Calculators"), "");
+ timeItem->setIcon(0,timeIcon);
+ QTreeWidgetItem * jdItem = addTreeItem(timeItem, i18n("Julian Day"), JDFrame );
+ jdItem->setIcon(0,jdIcon);
+
+ addTreeItem(timeItem, i18n("Sidereal Time"), SidFrame );
+ addTreeItem(timeItem, i18n("Almanac"), DayFrame );
+ addTreeItem(timeItem, i18n("Equinoxes & Solstices"), EquinoxFrame );
+ // dayItem->setIcon(0,sunsetIcon);
+
+ QTreeWidgetItem * coordItem = addTreeTopItem(navigationPanel, i18n("Coordinate Converters"), "");
+ addTreeItem(coordItem, i18n("Equatorial/Galactic"), GalFrame);
+ addTreeItem(coordItem, i18n("Apparent Coordinates"), AppFrame);
+ addTreeItem(coordItem, i18n("Horizontal Coordinates"), AltAzFrame);
+ addTreeItem(coordItem, i18n("Ecliptic Coordinates"), EclFrame);
+ addTreeItem(coordItem, i18n("Angular Distance"), AngDistFrame);
+ addTreeItem(coordItem, i18n("Geodetic Coordinates"), GeodCoordFrame);
+ addTreeItem(coordItem, i18n("LSR Velocity"), VlsrFrame);
+
+ QTreeWidgetItem * solarItem = addTreeTopItem(navigationPanel, i18n("Solar System"), "");
+ solarItem->setIcon(0,solarIcon);
+ addTreeItem(solarItem, i18n("Planets Coordinates"), PlanetsFrame);
+ addTreeItem(solarItem, i18n("Conjunctions"), ConjunctFrame);
+
connect(navigationPanel, SIGNAL(itemClicked(QTreeWidgetItem *, int)), this,
SLOT(slotItemSelection(QTreeWidgetItem *)));
}
@@ -145,6 +145,20 @@
return t;
}
+QTreeWidgetItem* AstroCalc::addTreeItem(QTreeWidgetItem* parent, QString title, QWidget* widget)
+{
+ QTreeWidgetItem* item = new QTreeWidgetItem(parent, QStringList(title));
+ dispatchTable.insert(title, widget);
+ return item;
+}
+
+QTreeWidgetItem* AstroCalc::addTreeTopItem(QTreeWidget* parent, QString title, QString html)
+{
+ QTreeWidgetItem* item = new QTreeWidgetItem(parent, QStringList(title));
+ htmlTable.insert(title, html);
+ return item;
+}
+
AstroCalc::~AstroCalc()
{
}
--- trunk/KDE/kdeedu/kstars/kstars/tools/astrocalc.h #969847:969848
@@ -19,6 +19,7 @@
#define ASTROCALC_H_
#include <QTreeWidgetItem>
+#include <QMap>
#include <kdialog.h>
#include "dms.h"
@@ -84,6 +85,22 @@
template<typename T>
inline T* addToStack();
+ /** Add top level item to navigation panel.
+ title - name of item
+ html - string to be displayed in splash screen
+ */
+ QTreeWidgetItem* addTreeTopItem(QTreeWidget* parent, QString title, QString html);
+
+ /** Add item to navigation panel.
+ title - name of item
+ widget - widget to be selected on click
+ */
+ QTreeWidgetItem* addTreeItem(QTreeWidgetItem* parent, QString title, QWidget* widget);
+
+ /** Lookup table for help texts */
+ QMap<QString, QString> htmlTable;
+ /** Lookup table for widgets */
+ QMap<QString, QWidget*> dispatchTable;
QSplitter *split;
QTreeWidget *navigationPanel;
QString previousElection;
More information about the Kstars-devel
mailing list