Commit 52a28143 authored by Jasem Mutlaq's avatar Jasem Mutlaq

Rework how configuration settings are applied. All this time _any_...

Rework how configuration settings are applied. All this time _any_ configuration settings that changes resulted in a complete reload of many catalogs and database entries unnecessairly. It is now more granular and each page applies its own changes as necessary.
This needs extensive testing as I am not sure what other assumption were made when this configuration model was conceived. It now _appears_ to be applying changes only when necessary but I could have missed a few things here and there. Please test.
CCMAIL:kstars-devel@kde.org
parent 17749ee8
......@@ -763,25 +763,14 @@ void KStars::slotViewOps() {
dialog->show();
}
void KStars::slotApplyConfigChanges() {
Options::self()->save();
// If the focus object was a constellation and the sky culture has changed, remove the focus object
if( map()->focusObject() && map()->focusObject()->type() == SkyObject::CONSTELLATION ) {
if( m_KStarsData->skyComposite()->currentCulture() != m_KStarsData->skyComposite()->getCultureName( (int)Options::skyCulture() ) || m_KStarsData->skyComposite()->isLocalCNames() != Options::useLocalConstellNames() ) {
map()->setClickedObject( NULL );
map()->setFocusObject( NULL );
}
}
void KStars::slotApplyConfigChanges()
{
Options::self()->save();
applyConfig();
data()->setFullTimeUpdate();
map()->forceUpdate();
m_KStarsData->skyComposite()->setCurrentCulture( m_KStarsData->skyComposite()->getCultureName( (int)Options::skyCulture() ) );
m_KStarsData->skyComposite()->reloadCLines();
m_KStarsData->skyComposite()->reloadCNames();
m_KStarsData->skyComposite()->reloadConstellationArt();
//data()->setFullTimeUpdate();
//map()->forceUpdate();
}
void KStars::slotApplyWIConfigChanges() {
......
......@@ -76,7 +76,7 @@ OpsCatalog::OpsCatalog()
populateCustomCatalogs();
connect( CatalogList, SIGNAL( itemClicked( QListWidgetItem* ) ), this, SLOT( updateCustomCatalogs() ) );
connect( CatalogList, SIGNAL( itemSelectionChanged() ), this, SLOT( selectCatalog() ) );
connect( CatalogList, SIGNAL( itemSelectionChanged() ), this, SLOT( selectCatalog() ) );
connect( AddCatalog, SIGNAL( clicked() ), this, SLOT( slotAddCatalog() ) );
connect( LoadCatalog, SIGNAL( clicked() ), this, SLOT( slotLoadCatalog() ) );
connect( RemoveCatalog, SIGNAL( clicked() ), this, SLOT( slotRemoveCatalog() ) );
......@@ -93,6 +93,12 @@ OpsCatalog::OpsCatalog()
connect( m_ConfigDialog->button(QDialogButtonBox::Apply), SIGNAL( clicked() ), SLOT( slotApply() ) );
connect( m_ConfigDialog->button(QDialogButtonBox::Ok), SIGNAL( clicked() ), SLOT( slotApply() ) );
connect( m_ConfigDialog->button(QDialogButtonBox::Cancel), SIGNAL( clicked() ), SLOT( slotCancel() ) );
// Keep track of changes
connect( CatalogList, &QListWidget::itemChanged, this, [&](){ isDirty = true;});
connect( catalogButtonGroup, static_cast<void (QButtonGroup::*)(int)>(&QButtonGroup::buttonPressed), this, [&](){ isDirty = true;});
isDirty = false;
}
//empty destructor
......@@ -119,12 +125,21 @@ void OpsCatalog::updateCustomCatalogs() {
* not contain the name. If it does, we remove it.
*/
if (l.count() == 0) continue; // skip the name if no match found
if ( l[0]->checkState()==Qt::Checked ) {
if ( l[0]->checkState()==Qt::Checked )
{
if (!m_CheckedCatalogNames.contains(name))
{
m_CheckedCatalogNames.append(name);
} else if ( l[0]->checkState()==Qt::Unchecked ){
//isDirty = true;
}
}
else if ( l[0]->checkState()==Qt::Unchecked )
{
if (m_CheckedCatalogNames.contains(name))
{
m_CheckedCatalogNames.removeAll(name);
//isDirty = true;
}
}
}
......@@ -132,15 +147,20 @@ void OpsCatalog::updateCustomCatalogs() {
}
void OpsCatalog::selectCatalog() {
void OpsCatalog::selectCatalog()
{
//If selected item is a custom catalog, enable the remove button (otherwise, disable it)
RemoveCatalog->setEnabled( false );
RemoveCatalog->setEnabled( false );
if ( ! CatalogList->currentItem() ) return;
foreach ( SkyComponent *sc, KStars::Instance()->data()->skyComposite()->customCatalogs() ) {
//isDirty = true;
foreach ( SkyComponent *sc, KStars::Instance()->data()->skyComposite()->customCatalogs() )
{
CatalogComponent *cc = (CatalogComponent*)sc;
if ( CatalogList->currentItem()->text() == cc->name() ) {
if ( CatalogList->currentItem()->text() == cc->name() )
{
RemoveCatalog->setEnabled( true );
break;
}
......@@ -148,21 +168,27 @@ void OpsCatalog::selectCatalog() {
}
void OpsCatalog::slotAddCatalog() {
void OpsCatalog::slotAddCatalog()
{
QPointer<AddCatDialog> ac = new AddCatDialog( KStars::Instance() );
if ( ac->exec()==QDialog::Accepted ) {
KStars::Instance()->data()->catalogdb()->AddCatalogContents( ac->filename() );
if ( ac->exec()==QDialog::Accepted )
{
KStars::Instance()->data()->catalogdb()->AddCatalogContents( ac->filename() );
refreshCatalogList();
isDirty=true;
}
delete ac;
}
void OpsCatalog::slotLoadCatalog() {
void OpsCatalog::slotLoadCatalog()
{
//Get the filename from the user
QString filename = QFileDialog::getOpenFileName(KStars::Instance(), QString(), QDir::homePath(), "*");
if ( ! filename.isEmpty() ) {
if ( ! filename.isEmpty() )
{
KStars::Instance()->data()->catalogdb()->AddCatalogContents(filename);
isDirty = true;
refreshCatalogList();
}
......@@ -170,28 +196,31 @@ void OpsCatalog::slotLoadCatalog() {
}
void OpsCatalog::refreshCatalogList() {
void OpsCatalog::refreshCatalogList()
{
KStars::Instance()->data()->catalogdb()->Catalogs();
populateCustomCatalogs();
}
void OpsCatalog::slotRemoveCatalog() {
if (KMessageBox::warningYesNo(0,
i18n("The selected database will be removed. "
"This action cannot be reversed! Delete Catalog?"),
i18n("Delete Catalog?") )
== KMessageBox::No) {
void OpsCatalog::slotRemoveCatalog()
{
if (KMessageBox::warningYesNo(0, i18n("The selected database will be removed. This action cannot be reversed! Delete Catalog?"), i18n("Delete Catalog?") ) == KMessageBox::No)
{
KMessageBox::information(0, "Catalog deletion cancelled.");
return;
}
isDirty = true;
//Ask DB to remove catalog
KStars::Instance()->data()->catalogdb()->RemoveCatalog( CatalogList->currentItem()->text() );
// Remove from Options if it exists in it (i.e. was marked as visible)
// This does not remove it from the database or from the widget in Options
QList<QString> checkedlist = Options::showCatalogNames();
if (checkedlist.contains(CatalogList->currentItem()->text())) {
if (checkedlist.contains(CatalogList->currentItem()->text()))
{
checkedlist.removeAll(CatalogList->currentItem()->text());
Options::setShowCatalogNames(checkedlist);
}
......@@ -218,9 +247,14 @@ void OpsCatalog::slotSetDrawStarZoomOutMagnitude(double newValue) {
}
*/
void OpsCatalog::slotApply() {
refreshCatalogList();
Options::setShowCatalogNames(m_CheckedCatalogNames);
void OpsCatalog::slotApply()
{
if (isDirty == false)
return;
isDirty = false;
refreshCatalogList();
Options::setStarDensity( kcfg_StarDensity->value() );
// Options::setMagLimitDrawStarZoomOut( kcfg_MagLimitDrawStarZoomOut->value() );
......@@ -228,26 +262,27 @@ void OpsCatalog::slotApply() {
//FIXME: need to add the ShowDeepSky meta-option to the config dialog!
//For now, I'll set showDeepSky to true if any catalog options changed
if ( m_ShowMessier != Options::showMessier() || m_ShowMessImages != Options::showMessierImages()
|| m_ShowNGC != Options::showNGC() || m_ShowIC != Options::showIC() ) {
|| m_ShowNGC != Options::showNGC() || m_ShowIC != Options::showIC() )
{
Options::setShowDeepSky( true );
}
updateCustomCatalogs();
// JM: Why are we calling this if no deep sky stuff was changed?
// AS: It's possible that custom catalogs have changed, which is probably why.
KStars::Instance()->data()->skyComposite()->reloadDeepSky();
Options::setShowMessier( m_ShowMessier );
Options::setShowMessierImages( m_ShowMessImages );
Options::setShowNGC( m_ShowNGC );
Options::setShowIC( m_ShowIC );
// update time for all objects because they might be not initialized
// it's needed when using horizontal coordinates
KStars::Instance()->data()->setFullTimeUpdate();
KStars::Instance()->updateTime();
KStars::Instance()->map()->forceUpdate();
Options::setShowCatalogNames(m_CheckedCatalogNames);
Options::setShowMessier( m_ShowMessier );
Options::setShowMessierImages( m_ShowMessImages );
Options::setShowNGC( m_ShowNGC );
Options::setShowIC( m_ShowIC );
}
......
......@@ -74,6 +74,7 @@ private:
QList<int> m_ShowCustomCatalog;
float m_StarDensity;
bool m_ShowMessier, m_ShowMessImages, m_ShowNGC, m_ShowIC;
bool isDirty=false;
};
#endif //OPSCATALOG_H_
......@@ -24,6 +24,9 @@
<property name="text">
<string>&amp;Star Catalogs</string>
</property>
<attribute name="buttonGroup">
<string notr="true">catalogButtonGroup</string>
</attribute>
</widget>
</item>
<item>
......@@ -125,6 +128,9 @@
<property name="text">
<string>Show &amp;name</string>
</property>
<attribute name="buttonGroup">
<string notr="true">catalogButtonGroup</string>
</attribute>
</widget>
</item>
<item row="1" column="1">
......@@ -132,6 +138,9 @@
<property name="text">
<string>Show ma&amp;gnitude</string>
</property>
<attribute name="buttonGroup">
<string notr="true">catalogButtonGroup</string>
</attribute>
</widget>
</item>
<item row="0" column="0">
......@@ -257,6 +266,9 @@
<property name="text">
<string>Deep-Sky Catalogs</string>
</property>
<attribute name="buttonGroup">
<string notr="true">catalogButtonGroup</string>
</attribute>
</widget>
</item>
<item>
......@@ -285,6 +297,9 @@
<property name="text">
<string>Show na&amp;me</string>
</property>
<attribute name="buttonGroup">
<string notr="true">catalogButtonGroup</string>
</attribute>
</widget>
</item>
</layout>
......@@ -315,6 +330,9 @@
<property name="text">
<string>Show &amp;long names</string>
</property>
<attribute name="buttonGroup">
<string notr="true">catalogButtonGroup</string>
</attribute>
</widget>
</item>
<item>
......@@ -358,6 +376,9 @@
<property name="text">
<string>Show magni&amp;tude</string>
</property>
<attribute name="buttonGroup">
<string notr="true">catalogButtonGroup</string>
</attribute>
</widget>
</item>
</layout>
......@@ -503,19 +524,19 @@
</layout>
</item>
<item>
<layout class="QHBoxLayout">
<item>
<widget class="QCheckBox" name="kcfg_ResolveNamesOnline">
<property name="text">
<string>Resolve names not known to KStars using online services</string>
</property>
<property name="toolTip">
<string>If this checkbox is checked, when an object name unknown to KStars is entered in the Find Dialog, KStars will contact online services (such as CDS Sesame) to learn about the object and then add it to the database.
<layout class="QHBoxLayout">
<item>
<widget class="QCheckBox" name="kcfg_ResolveNamesOnline">
<property name="toolTip">
<string>If this checkbox is checked, when an object name unknown to KStars is entered in the Find Dialog, KStars will contact online services (such as CDS Sesame) to learn about the object and then add it to the database.
The objects acquired in this manner are stored under a catalog that is called _Internet_Resolved as of this writing.</string>
</property>
</widget>
</item>
</layout>
</property>
<property name="text">
<string>Resolve names not known to KStars using online services</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout">
......@@ -634,6 +655,9 @@ These magnitude limits do not affect IC objects, as the magnitudes for many IC o
<property name="text">
<string>Show objects of unknown magnitude</string>
</property>
<attribute name="buttonGroup">
<string notr="true">catalogButtonGroup</string>
</attribute>
</widget>
</item>
<item>
......@@ -665,4 +689,11 @@ These magnitude limits do not affect IC objects, as the magnitudes for many IC o
</customwidgets>
<resources/>
<connections/>
<buttongroups>
<buttongroup name="catalogButtonGroup">
<property name="exclusive">
<bool>false</bool>
</property>
</buttongroup>
</buttongroups>
</ui>
......@@ -56,7 +56,7 @@ private slots:
private:
bool setColors( const QString &filename );
QStringList PresetFileList;
QStringList PresetFileList;
};
#endif //OPSCOLORS_H_
......
......@@ -14,10 +14,13 @@
* *
***************************************************************************/
#include <KConfigDialog>
#include "opsguides.h"
#include "ksfilereader.h"
#include "kstars.h"
#include "kstarsdata.h"
#include "skymap.h"
#include "skycomponents/skymapcomposite.h"
#include "Options.h"
......@@ -25,20 +28,14 @@ OpsGuides::OpsGuides()
: QFrame(KStars::Instance())
{
setupUi( this );
connect( kcfg_ShowCNames, SIGNAL( toggled( bool ) ),
this, SLOT( slotToggleConstellOptions( bool ) ) );
connect( kcfg_ShowConstellationArt, SIGNAL( toggled( bool ) ),
this, SLOT( slotToggleConstellationArt( bool ) ) );
connect( kcfg_ShowMilkyWay, SIGNAL( toggled( bool ) ),
this, SLOT( slotToggleMilkyWayOptions( bool ) ) );
connect( kcfg_ShowGround, SIGNAL( toggled( bool ) ),
this, SLOT( slotToggleOpaqueGround( bool ) ) );
connect( kcfg_AutoSelectGrid, SIGNAL( toggled( bool ) ),
this, SLOT( slotToggleAutoSelectGrid( bool ) ) );
foreach( const QString& item, KStarsData::Instance()->skyComposite()->getCultureNames() )
kcfg_SkyCulture->addItem( i18nc("Sky Culture", item.toUtf8().constData() ) );
m_ConfigDialog = KConfigDialog::exists( "settings" );
connect( m_ConfigDialog->button(QDialogButtonBox::Apply), SIGNAL( clicked() ), SLOT( slotApply() ) );
connect( m_ConfigDialog->button(QDialogButtonBox::Ok), SIGNAL( clicked() ), SLOT( slotApply() ) );
// When setting up the widget, update the enabled status of the
// checkboxes depending on the options.
slotToggleOpaqueGround( Options::showGround() );
......@@ -47,30 +44,76 @@ OpsGuides::OpsGuides()
slotToggleMilkyWayOptions( Options::showMilkyWay() );
slotToggleAutoSelectGrid( Options::autoSelectGrid() );
connect( kcfg_ShowCNames, SIGNAL( toggled( bool ) ), this, SLOT( slotToggleConstellOptions( bool ) ) );
connect( kcfg_ShowConstellationArt, SIGNAL( toggled( bool ) ), this, SLOT( slotToggleConstellationArt( bool ) ) );
connect( kcfg_ShowMilkyWay, SIGNAL( toggled( bool ) ), this, SLOT( slotToggleMilkyWayOptions( bool ) ) );
connect( kcfg_ShowGround, SIGNAL( toggled( bool ) ), this, SLOT( slotToggleOpaqueGround( bool ) ) );
connect( kcfg_AutoSelectGrid, SIGNAL( toggled( bool ) ), this, SLOT( slotToggleAutoSelectGrid( bool ) ) );
// Track changes to apply settings
connect( constellationButtonGroup, static_cast<void (QButtonGroup::*)(int)>(&QButtonGroup::buttonPressed), this, [&](){ isDirty = true;});
connect( nameButtonGroup, static_cast<void (QButtonGroup::*)(int)>(&QButtonGroup::buttonPressed), this, [&](){ isDirty = true;});
connect( kcfg_SkyCulture, static_cast<void(QComboBox::*)(int)>(&QComboBox::activated), this, [&](){ isDirty = true; });
isDirty = false;
}
OpsGuides::~OpsGuides()
{}
void OpsGuides::slotToggleConstellOptions( bool state ) {
void OpsGuides::slotToggleConstellOptions( bool state )
{
ConstellOptions->setEnabled( state );
}
void OpsGuides::slotToggleConstellationArt( bool state ) {
void OpsGuides::slotToggleConstellationArt( bool state )
{
kcfg_ShowConstellationArt->setEnabled( state );
}
void OpsGuides::slotToggleMilkyWayOptions( bool state ) {
void OpsGuides::slotToggleMilkyWayOptions( bool state )
{
kcfg_FillMilkyWay->setEnabled( state );
}
void OpsGuides::slotToggleOpaqueGround( bool state ) {
void OpsGuides::slotToggleOpaqueGround( bool state )
{
kcfg_ShowHorizon->setEnabled( !state );
}
void OpsGuides::slotToggleAutoSelectGrid( bool state ) {
void OpsGuides::slotToggleAutoSelectGrid( bool state )
{
kcfg_ShowEquatorialGrid->setEnabled( !state );
kcfg_ShowHorizontalGrid->setEnabled( !state );
}
void OpsGuides::slotApply()
{
if (isDirty == false)
return;
isDirty = false;
KStarsData *data = KStarsData::Instance();
SkyMap *map = SkyMap::Instance();
// If the focus object was a constellation and the sky culture has changed, remove the focus object
if( map->focusObject() && map->focusObject()->type() == SkyObject::CONSTELLATION )
{
if( data->skyComposite()->currentCulture() != data->skyComposite()->getCultureName(kcfg_SkyCulture->currentIndex()) ||
data->skyComposite()->isLocalCNames() != Options::useLocalConstellNames() )
{
map->setClickedObject( NULL );
map->setFocusObject( NULL );
}
}
data->skyComposite()->setCurrentCulture( KStarsData::Instance()->skyComposite()->getCultureName( kcfg_SkyCulture->currentIndex() ) );
data->skyComposite()->reloadCLines();
data->skyComposite()->reloadCNames();
data->skyComposite()->reloadConstellationArt();
data->setFullTimeUpdate();
KStars::Instance()->updateTime();
map->forceUpdate();
}
......@@ -19,7 +19,7 @@
#include "ui_opsguides.h"
class KStars;
class KConfigDialog;
/**
* @class OpsGuides
......@@ -35,12 +35,17 @@ public:
~OpsGuides();
private slots:
void slotApply();
void slotToggleConstellOptions( bool state );
void slotToggleConstellationArt(bool state );
void slotToggleMilkyWayOptions( bool state );
void slotToggleOpaqueGround( bool state );
void slotToggleAutoSelectGrid( bool state );
private:
KConfigDialog *m_ConfigDialog;
bool isDirty = false;
};
#endif // OPSGUIDES_H_
......@@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>446</width>
<height>262</height>
<width>454</width>
<height>279</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
......@@ -28,6 +28,9 @@
<property name="text">
<string>&amp;Constellation lines</string>
</property>
<attribute name="buttonGroup">
<string notr="true">constellationButtonGroup</string>
</attribute>
</widget>
</item>
<item>
......@@ -57,6 +60,9 @@
<property name="text">
<string>Constellation &amp;boundaries</string>
</property>
<attribute name="buttonGroup">
<string notr="true">constellationButtonGroup</string>
</attribute>
</widget>
</item>
<item>
......@@ -64,6 +70,9 @@
<property name="text">
<string>Constellation Art</string>
</property>
<attribute name="buttonGroup">
<string notr="true">constellationButtonGroup</string>
</attribute>
</widget>
</item>
<item>
......@@ -71,6 +80,9 @@
<property name="text">
<string>Highlight central constellation boundary</string>
</property>
<attribute name="buttonGroup">
<string notr="true">constellationButtonGroup</string>
</attribute>
</widget>
</item>
<item>
......@@ -84,6 +96,9 @@
<property name="text">
<string>Constellation &amp;names</string>
</property>
<attribute name="buttonGroup">
<string notr="true">constellationButtonGroup</string>
</attribute>
</widget>
</item>
</layout>
......@@ -120,6 +135,9 @@
<property name="text">
<string>L&amp;atin</string>
</property>
<attribute name="buttonGroup">
<string notr="true">nameButtonGroup</string>
</attribute>
</widget>
</item>
<item>
......@@ -133,6 +151,9 @@
<property name="text">
<string>Localized</string>
</property>
<attribute name="buttonGroup">
<string notr="true">nameButtonGroup</string>
</attribute>
</widget>
</item>
<item>
......@@ -146,6 +167,9 @@
<property name="text">
<string>Abbre&amp;viated</string>
</property>
<attribute name="buttonGroup">
<string notr="true">nameButtonGroup</string>
</attribute>
</widget>
</item>
</layout>
......@@ -182,6 +206,9 @@
<property name="text">
<string>Ecliptic</string>
</property>
<attribute name="buttonGroup">
<string notr="true">constellationButtonGroup</string>
</attribute>
</widget>
</item>
<item row="2" column="0">
......@@ -195,6 +222,9 @@
<property name="text">
<string>Fill Milk&amp;y Way</string>
</property>
<attribute name="buttonGroup">
<string notr="true">constellationButtonGroup</string>
</attribute>
</widget>
</item>
<item row="0" column="1">
......@@ -208,6 +238,9 @@
<property name="text">
<string>Hori&amp;zon (line)</string>
</property>