Commit 741a9f5a authored by Jason Harris's avatar Jason Harris
Browse files

efficiency bugfix: call SkyMap::update() less often. We had been calling

a "non-computational" update() 10 times a second.  This basically blits
the sky pixmap onto the window and draws the infoboxes.  We now only call
update() if the LT/UT/ST time values have changed (so, roughly 1-2 times
per second).

Also, removed hard-coded restriction on width of timespinbox widget.

svn path=/trunk/kdeedu/kstars/; revision=183943
parent 207a3627
......@@ -329,7 +329,11 @@ bool InfoBoxes::fixCollisions( InfoBox *target ) {
else return false;
}
void InfoBoxes::timeChanged(QDateTime ut, QDateTime lt, QTime lst, long double julian) {
bool InfoBoxes::timeChanged(QDateTime ut, QDateTime lt, QTime lst, long double julian) {
QString ot1 = TimeBox->text1();
QString ot2 = TimeBox->text2();
QString ot3 = TimeBox->text3();
TimeBox->setText1( i18n( "Local Time", "LT: " ) + lt.time().toString()
+ " " + KGlobal::locale()->formatDate( lt.date(), true ) );
TimeBox->setText2( i18n( "Universal Time", "UT: " ) + ut.time().toString()
......@@ -339,9 +343,17 @@ void InfoBoxes::timeChanged(QDateTime ut, QDateTime lt, QTime lst, long double j
TimeBox->setText3( i18n( "Sidereal Time", "ST: " ) + STString +
i18n( "Julian Day", "JD: " ) +
KGlobal::locale()->formatNumber( julian, 2 ) );
if ( ot1 == TimeBox->text1() && ot2 == TimeBox->text2() &&
ot3 == TimeBox->text3() )
return false;
else return true;
}
void InfoBoxes::geoChanged(const GeoLocation *geo) {
bool InfoBoxes::geoChanged(const GeoLocation *geo) {
QString ot1 = GeoBox->text1();
QString ot2 = GeoBox->text2();
QString name = geo->translatedName() + ", ";
if ( ! geo->province().isEmpty() ) name += geo->translatedProvince() + ", ";
name += geo->translatedCountry();
......@@ -351,17 +363,32 @@ void InfoBoxes::geoChanged(const GeoLocation *geo) {
KGlobal::locale()->formatNumber( geo->lng().Degrees(),3) + " " +
i18n( "Latitude", "Lat:" ) + " " +
KGlobal::locale()->formatNumber( geo->lat().Degrees(),3) );
if ( ot1 == GeoBox->text1() && ot2 == GeoBox->text2() )
return false;
else return true;
}
void InfoBoxes::focusObjChanged( const QString &n ) {
bool InfoBoxes::focusObjChanged( const QString &n ) {
QString ot1 = FocusBox->text1();
FocusBox->setText1( i18n( "Focused on: " ) + n );
if ( ot1 == FocusBox->text1() ) return false;
else return true;
}
void InfoBoxes::focusCoordChanged(const SkyPoint *p) {
bool InfoBoxes::focusCoordChanged(const SkyPoint *p) {
QString ot2 = FocusBox->text2();
QString ot3 = FocusBox->text3();
FocusBox->setText2( i18n( "Right Ascension", "RA" ) + ": " + p->ra().toHMSString() +
" " + i18n( "Declination", "Dec" ) + ": " + p->dec().toDMSString(true) );
FocusBox->setText3( i18n( "Altitude", "Alt" ) + ": " + p->alt().toDMSString(true) +
" " + i18n( "Azimuth", "Az" ) + ": " + p->az().toDMSString(true) );
if ( ot2 == FocusBox->text2() && ot3 == FocusBox->text3() )
return false;
else return true;
}
void InfoBoxes::checkBorders(bool resetToDefault) {
......
......@@ -204,23 +204,27 @@ public slots:
*@param lt The Local Time date/time object
*@param lst The Sidereal Time object
*@param jd The Julian Date (long double)
*@returns true if values have changed
*/
void timeChanged(QDateTime ut, QDateTime lt, QTime lst, long double julian);
bool timeChanged(QDateTime ut, QDateTime lt, QTime lst, long double julian);
/**Update the GeoBox strings according to the argument.
*@param geo The Geographic Location (we get the name, longitude and latitude from this)
*@returns true if values have changed
*/
void geoChanged(const GeoLocation *geo);
bool geoChanged(const GeoLocation *geo);
/**Update the FocusBox coordinates strings according to the argument.
*@param p the SkyPoint object from which we get the coordinates.
*@returns true if values have changed
*/
void focusCoordChanged(const SkyPoint *p);
bool focusCoordChanged(const SkyPoint *p);
/**Update the FocusBox name string according to the argument.
*@param n The object name
*@returns true if values have changed
*/
void focusObjChanged(const QString &n);
bool focusObjChanged(const QString &n);
/**Check if boxes are anchored with bottom or right border.
@param resetToDefault reset all borders of boxes to false before checking borders.
......
......@@ -91,6 +91,7 @@ KStars::KStars( KStarsData* kd )
KStars::~KStars()
{
kdDebug() << "in kstars destructor..." << endl;
saveOptions();
clearCachedFindDialog();
......@@ -152,8 +153,11 @@ void KStars::updateTime( const bool automaticDSTchange ) {
Data->updateTime( clock, geo(), Map, automaticDSTchange );
infoBoxes()->timeChanged(Data->UTime, Data->LTime, Data->LST, Data->CurrentDate);
if ( infoBoxes()->timeChanged(Data->UTime, Data->LTime, Data->LST, Data->CurrentDate) )
Map->update();
//We do this outside of kstarsdata just to get the coordinates
//displayed in the infobox to update every second.
if ( !options()->isTracking && Data->LST > oldLST ) { //kludge advancing the focus
int nSec = oldLST.secsTo( Data->LST );
Map->focus()->setRA( Map->focus()->ra().Hours() + double( nSec )/3600. );
......@@ -161,8 +165,6 @@ void KStars::updateTime( const bool automaticDSTchange ) {
showFocusCoords();
}
Map->update();
//If time is accelerated beyond slewTimescale, then the clock's timer is stopped,
//so that it can be ticked manually after each update, in order to make each time
//step exactly equal to the timeScale setting.
......
......@@ -35,8 +35,6 @@
TimeSpinBox::TimeSpinBox( QWidget *parent, const char *name )
: QSpinBox ( -41, 41, 1 /* step */, parent, name )
{
setMinimumWidth( 80 );
setMaximumWidth( 80 );
setValidator( 0 );
setButtonSymbols( QSpinBox::PlusMinus );
editor()->setReadOnly( true );
......@@ -157,7 +155,7 @@ QString TimeSpinBox::mapValueToText( int value ) {
void TimeSpinBox::changeScale( float x ) {
//Pick the closest value
int imin;
float dx, dxlast, dxmin(10000000000.0);
float dx, dxlast(10000000000.0), dxmin(10000000000.0);
for ( unsigned int i=0; i<42; ++i ) {
dx = fabs( TimeScale[i] - fabs(x) );
if ( dx < dxmin ) { imin = i; dxmin = dx; }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment