19 #include <QStandardItemModel>
20 #include <QSortFilterProxyModel>
36 QModelIndex index = sourceModel()->index( sourceRow, 0, sourceParent );
38 if ( sourceModel()->hasChildren( index ) ) {
39 for (
int i=0; i<sourceModel()->rowCount( index ); ++i )
45 return sourceModel()->data( index ).toString().contains( filterRegExp() );
54 m_ConfigDialog = KConfigDialog::exists(
"settings" );
57 m_Model =
new QStandardItemModel( 0, 1,
this );
59 m_SortModel->setSourceModel( m_Model );
60 SatListTreeView->setModel( m_SortModel );
61 SatListTreeView->setEditTriggers( QTreeView::NoEditTriggers );
62 SatListTreeView->setSortingEnabled(
false );
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* ) ) );
81 void OpsSatellites::slotUpdateTLEs()
90 void OpsSatellites::updateListView()
96 SatListTreeView->reset();
98 m_Model->setHorizontalHeaderLabels( QStringList( i18n(
"Satellite name" ) ) );
102 QStandardItem* group_item;
103 QStandardItem* sat_item;
104 bool all_sat_checked =
true;
105 bool all_sat_unchecked =
true;
109 group_item->setCheckable(
true );
110 m_Model->appendRow( group_item );
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 );
118 sat_item->setCheckState( Qt::Checked );
119 all_sat_unchecked =
false;
121 all_sat_checked =
false;
122 group_item->setChild( i, sat_item );
126 if ( all_sat_checked )
127 group_item->setCheckState( Qt::Checked );
128 else if ( all_sat_unchecked )
129 group_item->setCheckState( Qt::Unchecked );
131 group_item->setCheckState( Qt::PartiallyChecked );
135 void OpsSatellites::slotApply()
139 QStringList selected_satellites;
140 QModelIndex group_index, sat_index;
141 QStandardItem* group_item;
142 QStandardItem* sat_item;
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 );
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();
156 if ( sat_item->checkState() == Qt::Checked ) {
158 selected_satellites.append( sat_name );
169 void OpsSatellites::slotCancel()
175 void OpsSatellites::slotShowSatellites(
bool on )
177 kcfg_ShowVisibleSatellites->setEnabled( on );
178 kcfg_ShowSatellitesLabels->setEnabled( on );
179 kcfg_DrawSatellitesLikeStars->setEnabled( on );
182 void OpsSatellites::slotFilterReg(
const QString& filter )
184 m_SortModel->setFilterRegExp( QRegExp( filter, Qt::CaseInsensitive, QRegExp::RegExp ) );
185 m_SortModel->setFilterKeyColumn( -1 );
188 if ( filter.length() > 0 )
189 SatListTreeView->expandAll();
191 SatListTreeView->collapseAll();
194 void OpsSatellites::slotItemChanged( QStandardItem* item )
196 if( item->parent() == 0 && !item->hasChildren() ) {
200 QModelIndex sat_index;
201 QStandardItem* sat_item;
203 disconnect( m_Model, SIGNAL( itemChanged( QStandardItem* ) ),
this, SLOT( slotItemChanged( QStandardItem* ) ) );
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 );
212 if ( item->checkState() == Qt::Checked )
213 sat_item->setCheckState( Qt::Checked );
215 sat_item->setCheckState( Qt::Unchecked );
218 bool all_sat_checked =
true;
219 bool all_sat_unchecked =
true;
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 );
225 if ( sat_item->checkState() == Qt::Checked )
226 all_sat_unchecked =
false;
228 all_sat_checked =
false;
231 if ( all_sat_checked )
232 item->parent()->setCheckState( Qt::Checked );
233 else if ( all_sat_unchecked )
234 item->parent()->setCheckState( Qt::Unchecked );
236 item->parent()->setCheckState( Qt::PartiallyChecked );
240 connect( m_Model, SIGNAL( itemChanged( QStandardItem* ) ),
this, SLOT( slotItemChanged( QStandardItem* ) ) );
245 #include "opssatellites.moc"
OpsSatellites(KStars *_ks)
Constructor.
static QStringList selectedSatellites()
Get Selected satellites.
SatelliteSortFilterProxyModel(QObject *parent)
KStarsData is the backbone of KStars.
Represents a group of artificial satellites.
static KStarsData * Instance()
static void setSelectedSatellites(const QStringList &v)
Set Selected satellites.
This is the main window for KStars.
bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const
SatellitesComponent * satellites()
~OpsSatellites()
Destructor.
void updateTLEs()
Download new TLE files.
i18nc("string from libindi, used in the config dialog","100x")
SkyMapComposite * skyComposite()
QList< SatelliteGroup * > groups()
Represents an artificial satellites.
static const char * satgroup_strings_context
void setSelected(bool selected)
Select or not the satellite.
Satellite * findSatellite(QString name)
Search a satellite by name.