• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdeedu API Reference
  • KDE Home
  • Contact Us
 

kstars

  • sources
  • kde-4.12
  • kdeedu
  • kstars
  • kstars
  • options
opscatalog.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  opscatalog.cpp - K Desktop Planetarium
3  -------------------
4  begin : Sun Feb 29 2004
5  copyright : (C) 2004 by Jason Harris
6  email : jharris@30doradus.org
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 
18 #include "opscatalog.h"
19 
20 #include <QList>
21 #include <QListWidgetItem>
22 #include <QTextStream>
23 
24 #include <kfiledialog.h>
25 #include <kactioncollection.h>
26 #include <kconfigdialog.h>
27 
28 #include "Options.h"
29 #include "kstars.h"
30 #include "kstarsdata.h"
31 #include "skymap.h"
32 #include "dialogs/addcatdialog.h"
33 #include "widgets/magnitudespinbox.h"
34 #include "skycomponents/catalogcomponent.h"
35 #include "skycomponents/skymapcomposite.h"
36 
37 OpsCatalog::OpsCatalog( KStars *_ks )
38  : QFrame( _ks ), ksw(_ks)
39 {
40  setupUi(this);
41 
42  //Get a pointer to the KConfigDialog
43  m_ConfigDialog = KConfigDialog::exists( "settings" );
44 
45  //Populate CatalogList
46  populateInbuiltCatalogs();
47 
48  m_ShowMessier = Options::showMessier();
49  m_ShowMessImages = Options::showMessierImages();
50  m_ShowNGC = Options::showNGC();
51  m_ShowIC = Options::showIC();
52 
53  // kcfg_MagLimitDrawStar->setValue( Options::magLimitDrawStar() );
54  kcfg_StarDensity->setValue( Options::starDensity() );
55  // kcfg_MagLimitDrawStarZoomOut->setValue( Options::magLimitDrawStarZoomOut() );
56  // m_MagLimitDrawStar = kcfg_MagLimitDrawStar->value();
57  m_StarDensity = kcfg_StarDensity->value();
58  // m_MagLimitDrawStarZoomOut = kcfg_MagLimitDrawStarZoomOut->value();
59 
60  // kcfg_MagLimitDrawStar->setMinimum( Options::magLimitDrawStarZoomOut() );
61  // kcfg_MagLimitDrawStarZoomOut->setMaximum( 12.0 );
62 
63  kcfg_MagLimitDrawDeepSky->setMaximum( 16.0 );
64  kcfg_MagLimitDrawDeepSkyZoomOut->setMaximum( 16.0 );
65 
66  //disable star-related widgets if not showing stars
67  if ( ! kcfg_ShowStars->isChecked() ) slotStarWidgets(false);
68 
69  //Add custom catalogs, if necessary
70  /*
71  * 1) Get the list from DB and add it as unchecked
72  * 2) If the showCatalogNames list has any of the items, check it
73  */
74  m_CustomCatalogFile = ksw->data()->catalogdb()->Catalogs();
75  m_CheckedCatalogNames = Options::showCatalogNames();
76  populateCustomCatalogs();
77 
78  connect( CatalogList, SIGNAL( itemClicked( QListWidgetItem* ) ), this, SLOT( updateCustomCatalogs() ) );
79  connect( CatalogList, SIGNAL( itemSelectionChanged() ), this, SLOT( selectCatalog() ) );
80  connect( AddCatalog, SIGNAL( clicked() ), this, SLOT( slotAddCatalog() ) );
81  connect( LoadCatalog, SIGNAL( clicked() ), this, SLOT( slotLoadCatalog() ) );
82  connect( RemoveCatalog, SIGNAL( clicked() ), this, SLOT( slotRemoveCatalog() ) );
83 
84  /*
85  connect( kcfg_MagLimitDrawStar, SIGNAL( valueChanged(double) ),
86  SLOT( slotSetDrawStarMagnitude(double) ) );
87  connect( kcfg_MagLimitDrawStarZoomOut, SIGNAL( valueChanged(double) ),
88  SLOT( slotSetDrawStarZoomOutMagnitude(double) ) );
89  */
90  connect( kcfg_ShowStars, SIGNAL( toggled(bool) ), SLOT( slotStarWidgets(bool) ) );
91  connect( kcfg_ShowDeepSky, SIGNAL( toggled(bool) ), SLOT( slotDeepSkyWidgets(bool) ) );
92  connect( kcfg_ShowDeepSkyNames, SIGNAL( toggled(bool) ), kcfg_DeepSkyLongLabels, SLOT( setEnabled(bool) ) );
93  connect( m_ConfigDialog, SIGNAL( applyClicked() ), SLOT( slotApply() ) );
94  connect( m_ConfigDialog, SIGNAL( okClicked() ), SLOT( slotApply() ) );
95  connect( m_ConfigDialog, SIGNAL( cancelClicked() ), SLOT( slotCancel() ) );
96 }
97 
98 //empty destructor
99 OpsCatalog::~OpsCatalog() {}
100 
101 
102 void OpsCatalog::updateCustomCatalogs() {
103  m_ShowMessier = showMessier->checkState();
104  m_ShowMessImages = showMessImages->checkState();
105  m_ShowNGC = showNGC->checkState();
106  m_ShowIC = showIC->checkState();
107 
108  int limit = m_CustomCatalogFile->size();
109  for ( int i=0; i < limit; ++i ) {
110  QString name = m_CustomCatalogFile->at(i);
111  QList<QListWidgetItem*> l = CatalogList->findItems( name, Qt::MatchExactly );
112 
113  /*
114  * Options::CatalogNames contains the list of those custom catalog
115  * names which are to be checked.
116  * For every checked item, we check if the option CatalogNames has
117  * the name. If not, we add it.
118  * For every unchecked item, we check if the option CatalogNames does
119  * not contain the name. If it does, we remove it.
120  */
121  if (l.count() == 0) continue; // skip the name if no match found
122  if ( l[0]->checkState()==Qt::Checked ) {
123  if (!m_CheckedCatalogNames.contains(name))
124  m_CheckedCatalogNames.append(name);
125  } else if ( l[0]->checkState()==Qt::Unchecked ){
126  if (m_CheckedCatalogNames.contains(name))
127  m_CheckedCatalogNames.removeAll(name);
128  }
129  }
130 
131  m_ConfigDialog->enableButtonApply( false );
132 }
133 
134 
135 void OpsCatalog::selectCatalog() {
136  //If selected item is a custom catalog, enable the remove button (otherwise, disable it)
137  RemoveCatalog->setEnabled( false );
138 
139  if ( ! CatalogList->currentItem() ) return;
140 
141  foreach ( SkyComponent *sc, ksw->data()->skyComposite()->customCatalogs() ) {
142  CatalogComponent *cc = (CatalogComponent*)sc;
143  if ( CatalogList->currentItem()->text() == cc->name() ) {
144  RemoveCatalog->setEnabled( true );
145  break;
146  }
147  }
148 }
149 
150 
151 void OpsCatalog::slotAddCatalog() {
152  QPointer<AddCatDialog> ac = new AddCatDialog( ksw );
153  if ( ac->exec()==QDialog::Accepted )
154  ksw->data()->catalogdb()->AddCatalogContents( ac->filename() );
155  refreshCatalogList();
156  delete ac;
157 }
158 
159 
160 void OpsCatalog::slotLoadCatalog() {
161  //Get the filename from the user
162  QString filename = KFileDialog::getOpenFileName( QDir::homePath(), "*");
163  if ( ! filename.isEmpty() ) {
164  ksw->data()->catalogdb()->AddCatalogContents(filename);
165  refreshCatalogList();
166  }
167  m_ConfigDialog->enableButtonApply( false );
168 }
169 
170 
171 void OpsCatalog::refreshCatalogList() {
172  ksw->data()->catalogdb()->Catalogs();
173  populateCustomCatalogs();
174 }
175 
176 
177 void OpsCatalog::slotRemoveCatalog() {
178  if (KMessageBox::warningYesNo(0,
179  i18n("The selected database will be removed. "
180  "This action cannot be reversed! Delete Catalog?"),
181  i18n("Delete Catalog?") )
182  == KMessageBox::No) {
183  KMessageBox::information(0, "Catalog deletion cancelled.");
184  return;
185  }
186  //Ask DB to remove catalog
187  ksw->data()->catalogdb()->RemoveCatalog( CatalogList->currentItem()->text() );
188 
189  // Remove from Options if it exists in it (i.e. was marked as visible)
190  // This does not remove it from the database or from the widget in Options
191  QList<QString> checkedlist = Options::showCatalogNames();
192  if (checkedlist.contains(CatalogList->currentItem()->text())) {
193  checkedlist.removeAll(CatalogList->currentItem()->text());
194  Options::setShowCatalogNames(checkedlist);
195  }
196 
197  //Remove entry in the QListView
198  QListWidgetItem *todelete = CatalogList->takeItem( CatalogList->row( CatalogList->currentItem() ) );
199  delete todelete;
200  refreshCatalogList();
201  m_ConfigDialog->enableButtonApply( false );
202  KStars::Instance()->data()->skyComposite()->reloadDeepSky();
203 }
204 
205 /*
206 void OpsCatalog::slotSetDrawStarMagnitude(double newValue) {
207  m_MagLimitDrawStar = newValue;
208  kcfg_MagLimitDrawStarZoomOut->setMaximum( newValue );
209  m_ConfigDialog->enableButtonApply( true );
210 }
211 
212 void OpsCatalog::slotSetDrawStarZoomOutMagnitude(double newValue) {
213  m_MagLimitDrawStarZoomOut = newValue;
214  kcfg_MagLimitDrawStar->setMinimum( newValue );
215  m_ConfigDialog->enableButtonApply( true );
216 }
217 */
218 
219 void OpsCatalog::slotApply() {
220  refreshCatalogList();
221  Options::setShowCatalogNames(m_CheckedCatalogNames);
222 
223  Options::setStarDensity( kcfg_StarDensity->value() );
224  // Options::setMagLimitDrawStarZoomOut( kcfg_MagLimitDrawStarZoomOut->value() );
225 
226  //FIXME: need to add the ShowDeepSky meta-option to the config dialog!
227  //For now, I'll set showDeepSky to true if any catalog options changed
228  if ( m_ShowMessier != Options::showMessier() || m_ShowMessImages != Options::showMessierImages()
229  || m_ShowNGC != Options::showNGC() || m_ShowIC != Options::showIC() ) {
230  Options::setShowDeepSky( true );
231  }
232 
233  updateCustomCatalogs();
234 
235  KStars::Instance()->data()->skyComposite()->reloadDeepSky();
236 
237  Options::setShowMessier( m_ShowMessier );
238  Options::setShowMessierImages( m_ShowMessImages );
239  Options::setShowNGC( m_ShowNGC );
240  Options::setShowIC( m_ShowIC );
241 
242  // update time for all objects because they might be not initialized
243  // it's needed when using horizontal coordinates
244  ksw->data()->setFullTimeUpdate();
245  ksw->updateTime();
246  ksw->map()->forceUpdate();
247 }
248 
249 
250 void OpsCatalog::slotCancel() {
251  //Revert all local option placeholders to the values in the global config object
252  // m_MagLimitDrawStar = Options::magLimitDrawStar();
253  m_StarDensity = Options::starDensity();
254  // m_MagLimitDrawStarZoomOut = Options::magLimitDrawStarZoomOut();
255 
256  m_ShowMessier = Options::showMessier();
257  m_ShowMessImages = Options::showMessierImages();
258  m_ShowNGC = Options::showNGC();
259  m_ShowIC = Options::showIC();
260 
261  m_ShowCustomCatalog = Options::showCatalog();
262 
263 }
264 
265 
266 void OpsCatalog::slotStarWidgets(bool on) {
267  // LabelMagStars->setEnabled(on);
268  LabelStarDensity->setEnabled(on);
269  // LabelMagStarsZoomOut->setEnabled(on);
270  LabelDensity->setEnabled(on);
271  // LabelMag1->setEnabled(on);
272  // LabelMag2->setEnabled(on);
273  // kcfg_MagLimitDrawStar->setEnabled(on);
274  kcfg_StarDensity->setEnabled(on);
275  LabelStarDensity->setEnabled( on );
276  // kcfg_MagLimitDrawStarZoomOut->setEnabled(on);
277  kcfg_StarLabelDensity->setEnabled(on);
278  kcfg_ShowStarNames->setEnabled(on);
279  kcfg_ShowStarMagnitudes->setEnabled(on);
280 }
281 
282 
283 void OpsCatalog::slotDeepSkyWidgets(bool on) {
284  CatalogList->setEnabled( on );
285  AddCatalog->setEnabled( on );
286  LoadCatalog->setEnabled( on );
287  LabelMagDeepSky->setEnabled( on );
288  LabelMagDeepSkyZoomOut->setEnabled( on );
289  kcfg_MagLimitDrawDeepSky->setEnabled( on );
290  kcfg_MagLimitDrawDeepSkyZoomOut->setEnabled( on );
291  kcfg_ShowDeepSkyNames->setEnabled( on );
292  kcfg_ShowDeepSkyMagnitudes->setEnabled( on );
293  kcfg_DeepSkyLabelDensity->setEnabled( on );
294  kcfg_DeepSkyLongLabels->setEnabled( on );
295  LabelMag3->setEnabled( on );
296  LabelMag4->setEnabled( on );
297  if ( on ) {
298  //Enable RemoveCatalog if the selected catalog is custom
299  selectCatalog();
300  } else {
301  RemoveCatalog->setEnabled( on );
302  }
303 }
304 
305 
306 void OpsCatalog::populateInbuiltCatalogs() {
307  showIC = new QListWidgetItem( i18n( "Index Catalog (IC)" ), CatalogList );
308  showIC->setFlags( Qt::ItemIsSelectable | Qt::ItemIsUserCheckable | Qt::ItemIsEnabled );
309  showIC->setCheckState( Options::showIC() ? Qt::Checked : Qt::Unchecked );
310 
311  showNGC = new QListWidgetItem( i18n( "New General Catalog (NGC)" ), CatalogList );
312  showNGC->setFlags( Qt::ItemIsSelectable | Qt::ItemIsUserCheckable | Qt::ItemIsEnabled );
313  showNGC->setCheckState( Options::showNGC() ? Qt::Checked : Qt::Unchecked );
314 
315  showMessImages = new QListWidgetItem( i18n( "Messier Catalog (images)" ), CatalogList );
316  showMessImages->setFlags( Qt::ItemIsSelectable | Qt::ItemIsUserCheckable | Qt::ItemIsEnabled );
317  showMessImages->setCheckState( Options::showMessierImages() ? Qt::Checked : Qt::Unchecked );
318 
319  showMessier = new QListWidgetItem( i18n( "Messier Catalog (symbols)" ), CatalogList );
320  showMessier->setFlags( Qt::ItemIsSelectable | Qt::ItemIsUserCheckable | Qt::ItemIsEnabled );
321  showMessier->setCheckState( Options::showMessier() ? Qt::Checked : Qt::Unchecked );
322 
323 }
324 
325 void OpsCatalog::populateCustomCatalogs() {
326  QStringList toggleNames = Options::showCatalogNames();
327  QStringList customList = *m_CustomCatalogFile; // Create a copy
328  QStringListIterator catalogIter(customList);
329 
330  while ( catalogIter.hasNext() ) {
331  QString catalogname = catalogIter.next();
332  //Skip already existing items
333  if (CatalogList->findItems( catalogname, Qt::MatchExactly ).length() > 0)
334  continue;
335 
336  //Allocate new catalog list item
337  QListWidgetItem *newItem = new QListWidgetItem( catalogname, CatalogList );
338  newItem->setFlags( Qt::ItemIsSelectable | Qt::ItemIsUserCheckable | Qt::ItemIsEnabled );
339 
340  if ( toggleNames.contains( catalogname ) ) {
341  newItem->setCheckState( Qt::Checked );
342  } else {
343  newItem->setCheckState( Qt::Unchecked );
344  }
345  }
346 
347 }
348 
349 
350 #include "opscatalog.moc"
Options::setStarDensity
static void setStarDensity(int v)
Set Density of stars in the field of view.
Definition: Options.h:2616
Options::setShowMessier
static void setShowMessier(bool v)
Set Draw Messier objects in the sky map?
Definition: Options.h:1825
Options::showCatalog
static QList< int > showCatalog()
Get List of toggles for displaying custom object catalogs.
Definition: Options.h:448
KStars::Instance
static KStars * Instance()
Definition: kstars.h:125
SkyComponent
SkyComponent represents an object on the sky map.
Definition: skycomponent.h:44
addcatdialog.h
Options::starDensity
static int starDensity()
Get Density of stars in the field of view.
Definition: Options.h:2626
KStarsData::catalogdb
CatalogDB * catalogdb()
Definition: kstarsdata.h:155
KStars
This is the main window for KStars.
Definition: kstars.h:94
OpsCatalog::OpsCatalog
OpsCatalog(KStars *_ks)
Definition: opscatalog.cpp:37
CatalogDB::Catalogs
QStringList * Catalogs()
Accessor for list of all available catalogs in db.
Definition: catalogdb.cpp:111
opscatalog.h
skymapcomposite.h
magnitudespinbox.h
CatalogComponent
Represents a custom user-defined catalog.
Definition: catalogcomponent.h:39
Options::setShowIC
static void setShowIC(bool v)
Set Draw IC objects in the sky map?
Definition: Options.h:1787
CatalogComponent::name
QString name() const
Definition: catalogcomponent.h:63
Options::setShowCatalogNames
static void setShowCatalogNames(const QStringList &v)
Set List for displaying custom object catalogs.
Definition: Options.h:457
skymap.h
SkyMapComposite::reloadDeepSky
void reloadDeepSky()
Definition: skymapcomposite.cpp:512
KStarsData::skyComposite
SkyMapComposite * skyComposite()
Definition: kstarsdata.h:146
OpsCatalog::~OpsCatalog
~OpsCatalog()
Definition: opscatalog.cpp:99
Options.h
Options::showMessierImages
static bool showMessierImages()
Get Draw Messier object images in the sky map?
Definition: Options.h:1854
Options::showCatalogNames
static QStringList showCatalogNames()
Get List for displaying custom object catalogs.
Definition: Options.h:467
Options::setShowMessierImages
static void setShowMessierImages(bool v)
Set Draw Messier object images in the sky map?
Definition: Options.h:1844
Options::showNGC
static bool showNGC()
Get Draw NGC objects in the sky map?
Definition: Options.h:1816
KStars::data
KStarsData * data() const
Definition: kstars.h:131
Options::setShowNGC
static void setShowNGC(bool v)
Set Draw NGC objects in the sky map?
Definition: Options.h:1806
kstarsdata.h
Options::setShowDeepSky
static void setShowDeepSky(bool v)
Set Draw "deep sky" objects in the sky map?
Definition: Options.h:1616
QFrame
kstars.h
catalogcomponent.h
Options::showIC
static bool showIC()
Get Draw IC objects in the sky map?
Definition: Options.h:1797
QList
Options::showMessier
static bool showMessier()
Get Draw Messier objects in the sky map?
Definition: Options.h:1835
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:36:20 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kstars

Skip menu "kstars"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdeedu API Reference

Skip menu "kdeedu API Reference"
  • Analitza
  •     lib
  • kalgebra
  • kalzium
  •   libscience
  • kanagram
  • kig
  •   lib
  • klettres
  • kstars
  • libkdeedu
  •   keduvocdocument
  • marble
  • parley
  • rocs
  •   App
  •   RocsCore
  •   VisualEditor
  •   stepcore

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal