• 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
opssatellites.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  opssatellites.cpp - K Desktop Planetarium
3  -------------------
4  begin : Mon 21 Mar 2011
5  copyright : (C) 2011 by Jérôme SONRIER
6  email : jsid@emor3j.fr.eu.org
7  ***************************************************************************/
8 /***************************************************************************
9  * *
10  * This program is free software; you can redistribute it and/or modify *
11  * it under the terms of the GNU General Public License as published by *
12  * the Free Software Foundation; either version 2 of the License, or *
13  * (at your option) any later version. *
14  * *
15  ***************************************************************************/
16 
17 #include "opssatellites.h"
18 
19 #include <QStandardItemModel>
20 #include <QSortFilterProxyModel>
21 
22 #include "Options.h"
23 #include "kstars.h"
24 #include "kstarsdata.h"
25 #include "skymapcomposite.h"
26 #include "skycomponents/satellitescomponent.h"
27 #include "satellitegroup.h"
28 
29 static const char *satgroup_strings_context = "Satellite group name";
30 
31 SatelliteSortFilterProxyModel::SatelliteSortFilterProxyModel( QObject* parent ): QSortFilterProxyModel( parent )
32 {}
33 
34 bool SatelliteSortFilterProxyModel::filterAcceptsRow( int sourceRow, const QModelIndex& sourceParent ) const
35 {
36  QModelIndex index = sourceModel()->index( sourceRow, 0, sourceParent );
37 
38  if ( sourceModel()->hasChildren( index ) ) {
39  for ( int i=0; i<sourceModel()->rowCount( index ); ++i )
40  if ( filterAcceptsRow( i, index ) )
41  return true;
42  return false;
43  }
44 
45  return sourceModel()->data( index ).toString().contains( filterRegExp() );
46 }
47 
48 
49 OpsSatellites::OpsSatellites( KStars *_ks )
50  : QFrame( _ks ), ksw(_ks)
51 {
52  setupUi( this );
53 
54  m_ConfigDialog = KConfigDialog::exists( "settings" );
55 
56  //Set up the Table Views
57  m_Model = new QStandardItemModel( 0, 1, this );
58  m_SortModel = new SatelliteSortFilterProxyModel( this );
59  m_SortModel->setSourceModel( m_Model );
60  SatListTreeView->setModel( m_SortModel );
61  SatListTreeView->setEditTriggers( QTreeView::NoEditTriggers );
62  SatListTreeView->setSortingEnabled( false );
63 
64  // Populate satellites list
65  updateListView();
66 
67  // Signals and slots connections
68  connect( UpdateTLEButton, SIGNAL( clicked() ), this, SLOT( slotUpdateTLEs() ) );
69  connect( kcfg_ShowSatellites, SIGNAL( toggled( bool ) ), SLOT( slotShowSatellites( bool ) ) );
70  connect( m_ConfigDialog, SIGNAL( applyClicked() ), SLOT( slotApply() ) );
71  connect( m_ConfigDialog, SIGNAL( okClicked() ), SLOT( slotApply() ) );
72  connect( m_ConfigDialog, SIGNAL( cancelClicked() ), SLOT( slotCancel() ) );
73  connect( FilterEdit, SIGNAL( textChanged( const QString & ) ), this, SLOT( slotFilterReg( const QString & ) ) );
74  connect( m_Model, SIGNAL( itemChanged( QStandardItem* ) ), this, SLOT( slotItemChanged( QStandardItem* ) ) );
75 }
76 
77 OpsSatellites::~OpsSatellites() {
78 
79 }
80 
81 void OpsSatellites::slotUpdateTLEs()
82 {
83  // Get new data files
84  KStarsData::Instance()->skyComposite()->satellites()->updateTLEs();
85 
86  // Refresh satellites list
87  updateListView();
88 }
89 
90 void OpsSatellites::updateListView()
91 {
92  KStarsData* data = KStarsData::Instance();
93 
94  // Clear satellites list
95  m_Model->clear();
96  SatListTreeView->reset();
97 
98  m_Model->setHorizontalHeaderLabels( QStringList( i18n( "Satellite name" ) ) );
99 
100  // Add each groups and satellites in the list
101  foreach ( SatelliteGroup* sat_group, data->skyComposite()->satellites()->groups() ) {
102  QStandardItem* group_item;
103  QStandardItem* sat_item;
104  bool all_sat_checked = true;
105  bool all_sat_unchecked = true;
106 
107  // Add the group
108  group_item = new QStandardItem( i18nc( satgroup_strings_context, sat_group->name().toUtf8() ) );
109  group_item->setCheckable( true );
110  m_Model->appendRow( group_item );
111 
112 
113  // Add all satellites of the group
114  for ( int i=0; i<sat_group->count(); ++i ) {
115  sat_item = new QStandardItem( sat_group->at(i)->name() );
116  sat_item->setCheckable( true );
117  if ( Options::selectedSatellites().contains( sat_group->at(i)->name() ) ) {
118  sat_item->setCheckState( Qt::Checked );
119  all_sat_unchecked = false;
120  } else
121  all_sat_checked = false;
122  group_item->setChild( i, sat_item );
123  }
124 
125  // If all satellites of the group are selected, select the group
126  if ( all_sat_checked )
127  group_item->setCheckState( Qt::Checked );
128  else if ( all_sat_unchecked )
129  group_item->setCheckState( Qt::Unchecked );
130  else
131  group_item->setCheckState( Qt::PartiallyChecked );
132  }
133 }
134 
135 void OpsSatellites::slotApply()
136 {
137  KStarsData* data = KStarsData::Instance();
138  QString sat_name;
139  QStringList selected_satellites;
140  QModelIndex group_index, sat_index;
141  QStandardItem* group_item;
142  QStandardItem* sat_item;
143 
144  // Retrive each satellite in the list and select it if checkbox is checked
145  for ( int i=0; i<m_Model->rowCount( SatListTreeView->rootIndex() ); ++i ) {
146  group_index = m_Model->index( i, 0, SatListTreeView->rootIndex() );
147  group_item = m_Model->itemFromIndex( group_index );
148 
149  for ( int j=0; j<m_Model->rowCount( group_item->index() ); ++j ) {
150  sat_index = m_Model->index( j, 0, group_index );
151  sat_item = m_Model->itemFromIndex( sat_index );
152  sat_name = sat_item->data( 0 ).toString();
153 
154  Satellite *sat = data->skyComposite()->satellites()->findSatellite( sat_name );
155  if ( sat ) {
156  if ( sat_item->checkState() == Qt::Checked ) {
157  sat->setSelected( true );
158  selected_satellites.append( sat_name );
159  } else {
160  sat->setSelected( false );
161  }
162  }
163  }
164  }
165 
166  Options::setSelectedSatellites( selected_satellites );
167 }
168 
169 void OpsSatellites::slotCancel()
170 {
171  // Update satellites list
172  updateListView();
173 }
174 
175 void OpsSatellites::slotShowSatellites( bool on )
176 {
177  kcfg_ShowVisibleSatellites->setEnabled( on );
178  kcfg_ShowSatellitesLabels->setEnabled( on );
179  kcfg_DrawSatellitesLikeStars->setEnabled( on );
180 }
181 
182 void OpsSatellites::slotFilterReg( const QString& filter )
183 {
184  m_SortModel->setFilterRegExp( QRegExp( filter, Qt::CaseInsensitive, QRegExp::RegExp ) );
185  m_SortModel->setFilterKeyColumn( -1 );
186 
187  // Expand all categories when the user use filter
188  if ( filter.length() > 0 )
189  SatListTreeView->expandAll();
190  else
191  SatListTreeView->collapseAll();
192 }
193 
194 void OpsSatellites::slotItemChanged( QStandardItem* item )
195 {
196  if( item->parent() == 0 && !item->hasChildren() ) {
197  return;
198  }
199 
200  QModelIndex sat_index;
201  QStandardItem* sat_item;
202 
203  disconnect( m_Model, SIGNAL( itemChanged( QStandardItem* ) ), this, SLOT( slotItemChanged( QStandardItem* ) ) );
204 
205  // If a group has been (un)checked, (un)check all satellites of the group
206  // else a satellite has been (un)checked, (un)check his group
207  if ( item->hasChildren() ) {
208  for ( int i=0; i<m_Model->rowCount( item->index() ); ++i ) {
209  sat_index = m_Model->index( i, 0, item->index() );
210  sat_item = m_Model->itemFromIndex( sat_index );
211 
212  if ( item->checkState() == Qt::Checked )
213  sat_item->setCheckState( Qt::Checked );
214  else
215  sat_item->setCheckState( Qt::Unchecked );
216  }
217  } else {
218  bool all_sat_checked = true;
219  bool all_sat_unchecked = true;
220 
221  for ( int i=0; i<item->parent()->model()->rowCount( item->parent()->index() ); ++i ) {
222  sat_index = m_Model->index( i, 0, item->parent()->index() );
223  sat_item = m_Model->itemFromIndex( sat_index );
224 
225  if ( sat_item->checkState() == Qt::Checked )
226  all_sat_unchecked = false;
227  else
228  all_sat_checked = false;
229  }
230 
231  if ( all_sat_checked )
232  item->parent()->setCheckState( Qt::Checked );
233  else if ( all_sat_unchecked )
234  item->parent()->setCheckState( Qt::Unchecked );
235  else
236  item->parent()->setCheckState( Qt::PartiallyChecked );
237 
238  }
239 
240  connect( m_Model, SIGNAL( itemChanged( QStandardItem* ) ), this, SLOT( slotItemChanged( QStandardItem* ) ) );
241 }
242 
243 
244 
245 #include "opssatellites.moc"
satellitescomponent.h
OpsSatellites::OpsSatellites
OpsSatellites(KStars *_ks)
Constructor.
Definition: opssatellites.cpp:49
Options::selectedSatellites
static QStringList selectedSatellites()
Get Selected satellites.
Definition: Options.h:4388
SatelliteSortFilterProxyModel::SatelliteSortFilterProxyModel
SatelliteSortFilterProxyModel(QObject *parent)
Definition: opssatellites.cpp:31
satellitegroup.h
KStarsData
KStarsData is the backbone of KStars.
Definition: kstarsdata.h:66
SatelliteGroup
Represents a group of artificial satellites.
Definition: satellitegroup.h:35
KStarsData::Instance
static KStarsData * Instance()
Definition: kstarsdata.h:92
Options::setSelectedSatellites
static void setSelectedSatellites(const QStringList &v)
Set Selected satellites.
Definition: Options.h:4378
SatelliteGroup::name
QString name()
Definition: satellitegroup.cpp:84
QObject
KStars
This is the main window for KStars.
Definition: kstars.h:94
SatelliteSortFilterProxyModel::filterAcceptsRow
bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const
Definition: opssatellites.cpp:34
SatelliteSortFilterProxyModel
Definition: opssatellites.h:30
SkyMapComposite::satellites
SatellitesComponent * satellites()
Definition: skymapcomposite.cpp:609
OpsSatellites::~OpsSatellites
~OpsSatellites()
Destructor.
Definition: opssatellites.cpp:77
skymapcomposite.h
SatellitesComponent::updateTLEs
void updateTLEs()
Download new TLE files.
Definition: satellitescomponent.cpp:111
i18nc
i18nc("string from libindi, used in the config dialog","100x")
KStarsData::skyComposite
SkyMapComposite * skyComposite()
Definition: kstarsdata.h:146
SatellitesComponent::groups
QList< SatelliteGroup * > groups()
Definition: satellitescomponent.cpp:138
QSortFilterProxyModel
Options.h
opssatellites.h
Satellite
Represents an artificial satellites.
Definition: satellite.h:35
kstarsdata.h
satgroup_strings_context
static const char * satgroup_strings_context
Definition: opssatellites.cpp:29
QFrame
Satellite::setSelected
void setSelected(bool selected)
Select or not the satellite.
Definition: satellite.cpp:1206
kstars.h
SatellitesComponent::findSatellite
Satellite * findSatellite(QString name)
Search a satellite by name.
Definition: satellitescomponent.cpp:143
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