[Kstars-devel] [kstars] kstars/options: Add checkboxes to select group of satellites

Jérome SONRIER jsid at emor3j.fr.eu.org
Wed Jul 20 02:26:48 CEST 2011


Git commit 2da22ad7ec633763a282c36ae5442d09cd306118 by Jérome SONRIER.
Committed on 20/07/2011 at 02:25.
Pushed by jsonrier into branch 'master'.

Add checkboxes to select group of satellites

CCBUG: 272369
CCMAIL: kstars-devel at kde.org

M  +65   -2    kstars/options/opssatellites.cpp
M  +1    -0    kstars/options/opssatellites.h

http://commits.kde.org/kstars/2da22ad7ec633763a282c36ae5442d09cd306118

diff --git a/kstars/options/opssatellites.cpp b/kstars/options/opssatellites.cpp
index d0f5554..7d4fc88 100644
--- a/kstars/options/opssatellites.cpp
+++ b/kstars/options/opssatellites.cpp
@@ -70,6 +70,7 @@ OpsSatellites::OpsSatellites( KStars *_ks )
     connect( m_ConfigDialog, SIGNAL( okClicked() ), SLOT( slotApply() ) );
     connect( m_ConfigDialog, SIGNAL( cancelClicked() ), SLOT( slotCancel() ) );
     connect( FilterEdit, SIGNAL( textChanged( const QString & ) ), this, SLOT( slotFilterReg( const QString & ) ) );
+    connect( m_Model, SIGNAL( itemChanged( QStandardItem* ) ), this, SLOT( slotItemChanged( QStandardItem* ) ) );
 }
 
 OpsSatellites::~OpsSatellites() {
@@ -95,20 +96,36 @@ void OpsSatellites::updateListView()
 
     // Add each groups and satellites in the list
     foreach ( SatelliteGroup* sat_group, data->skyComposite()->satellites()->groups() ) {
-        // Add the group
         QStandardItem* group_item;
         QStandardItem* sat_item;
+        bool all_sat_checked = true;
+        bool all_sat_unchecked = true;
+        
+        // Add the group
         group_item = new QStandardItem( sat_group->name() );
+        group_item->setCheckable( true );
         m_Model->appendRow( group_item );
         
+        
         // Add all satellites of the group
         for ( int i=0; i<sat_group->count(); ++i ) {
             sat_item = new QStandardItem( sat_group->at(i)->name() );
             sat_item->setCheckable( true );
-            if ( Options::selectedSatellites().contains( sat_group->at(i)->name() ) )
+            if ( Options::selectedSatellites().contains( sat_group->at(i)->name() ) ) {
                 sat_item->setCheckState( Qt::Checked );
+                all_sat_unchecked = false;
+            } else
+                all_sat_checked = false;
             group_item->setChild( i, sat_item );
         }
+        
+        // If all satellites of the group are selected, select the group 
+        if ( all_sat_checked )
+            group_item->setCheckState( Qt::Checked );
+        else if ( all_sat_unchecked )
+            group_item->setCheckState( Qt::Unchecked );
+        else
+            group_item->setCheckState( Qt::PartiallyChecked );
     }
 }
 
@@ -171,5 +188,51 @@ void OpsSatellites::slotFilterReg( const QString& filter )
         SatListTreeView->collapseAll();
 }
 
+void OpsSatellites::slotItemChanged( QStandardItem* item )
+{
+    QModelIndex sat_index;
+    QStandardItem* sat_item;
+    
+    disconnect( m_Model, SIGNAL( itemChanged( QStandardItem* ) ), this, SLOT( slotItemChanged( QStandardItem* ) ) );
+    
+    // If a group has been (un)checked, (un)check all satellites of the group
+    // else a satellite has been (un)checked, (un)check his group
+    if ( item->hasChildren() ) {
+        for ( int i=0; i<m_Model->rowCount( item->index() ); ++i ) {
+            sat_index = m_Model->index( i, 0, item->index() );
+            sat_item = m_Model->itemFromIndex( sat_index );
+            
+            if ( item->checkState() == Qt::Checked )
+                sat_item->setCheckState( Qt::Checked );
+            else
+                sat_item->setCheckState( Qt::Unchecked );
+        }
+    } else {
+        bool all_sat_checked = true;
+        bool all_sat_unchecked = true;
+        
+        for ( int i=0; i<item->parent()->model()->rowCount( item->parent()->index() ); ++i ) {
+            sat_index = m_Model->index( i, 0, item->parent()->index() );
+            sat_item = m_Model->itemFromIndex( sat_index );
+            
+            if ( sat_item->checkState() == Qt::Checked )
+                all_sat_unchecked = false;
+            else
+                all_sat_checked = false;
+        }
+        
+        if ( all_sat_checked )
+            item->parent()->setCheckState( Qt::Checked );
+        else if ( all_sat_unchecked )
+            item->parent()->setCheckState( Qt::Unchecked );
+        else
+            item->parent()->setCheckState( Qt::PartiallyChecked );
+        
+    }
+    
+    connect( m_Model, SIGNAL( itemChanged( QStandardItem* ) ), this, SLOT( slotItemChanged( QStandardItem* ) ) );
+}
+
+
 
 #include "opssatellites.moc"
diff --git a/kstars/options/opssatellites.h b/kstars/options/opssatellites.h
index c1a1bf1..4fe4f87 100644
--- a/kstars/options/opssatellites.h
+++ b/kstars/options/opssatellites.h
@@ -72,6 +72,7 @@ private slots:
     void slotApply();
     void slotCancel();
     void slotFilterReg( const QString& );
+    void slotItemChanged( QStandardItem* );
 };
 
 #endif  //OPSSATELLITES_H_


More information about the Kstars-devel mailing list