[Kstars-devel] [kstars] kstars/options: Add a search field on satellites option dialog
Jérome SONRIER
jsid at emor3j.fr.eu.org
Wed Jul 20 02:26:48 CEST 2011
Git commit 170700e72fb77b7ed73d9035828e8ee4318db0fc by Jérome SONRIER.
Committed on 19/07/2011 at 03:06.
Pushed by jsonrier into branch 'master'.
Add a search field on satellites option dialog
CCBUG: 272369
CCMAIL: kstars-devel at kde.org
M +91 -70 kstars/options/opssatellites.ui
M +72 -31 kstars/options/opssatellites.cpp
M +14 -1 kstars/options/opssatellites.h
http://commits.kde.org/kstars/170700e72fb77b7ed73d9035828e8ee4318db0fc
diff --git a/kstars/options/opssatellites.cpp b/kstars/options/opssatellites.cpp
index d4dc715..d0f5554 100644
--- a/kstars/options/opssatellites.cpp
+++ b/kstars/options/opssatellites.cpp
@@ -16,10 +16,8 @@
#include "opssatellites.h"
-#include <qcheckbox.h>
-#include <QTreeWidgetItem>
-
-
+#include <QStandardItemModel>
+#include <QSortFilterProxyModel>
#include "Options.h"
#include "kstars.h"
@@ -28,14 +26,41 @@
#include "skycomponents/satellitescomponent.h"
#include "satellitegroup.h"
+
+SatelliteSortFilterProxyModel::SatelliteSortFilterProxyModel( QObject* parent ): QSortFilterProxyModel( parent )
+{}
+
+bool SatelliteSortFilterProxyModel::filterAcceptsRow( int sourceRow, const QModelIndex& sourceParent ) const
+{
+ QModelIndex index = sourceModel()->index( sourceRow, 0, sourceParent );
+
+ if ( sourceModel()->hasChildren( index ) ) {
+ for ( int i=0; i<sourceModel()->rowCount( index ); ++i )
+ if ( filterAcceptsRow( i, index ) )
+ return true;
+ return false;
+ }
+
+ return sourceModel()->data( index ).toString().contains( filterRegExp() );
+}
+
+
OpsSatellites::OpsSatellites( KStars *_ks )
: QFrame( _ks ), ksw(_ks)
{
setupUi( this );
m_ConfigDialog = KConfigDialog::exists( "settings" );
-
- // Ppulate satellites list
+
+ //Set up the Table Views
+ m_Model = new QStandardItemModel( 0, 1, this );
+ m_Model->setHorizontalHeaderLabels( QStringList() << i18n( "Satellite name" ) );
+ m_SortModel = new SatelliteSortFilterProxyModel( this );
+ m_SortModel->setSourceModel( m_Model );
+ SatListTreeView->setModel( m_SortModel );
+ SatListTreeView->setSortingEnabled( false );
+
+ // Populate satellites list
updateListView();
// Signals and slots connections
@@ -44,6 +69,7 @@ OpsSatellites::OpsSatellites( KStars *_ks )
connect( m_ConfigDialog, SIGNAL( applyClicked() ), SLOT( slotApply() ) );
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 & ) ) );
}
OpsSatellites::~OpsSatellites() {
@@ -64,28 +90,24 @@ void OpsSatellites::updateListView()
KStarsData* data = KStarsData::Instance();
// Clear satellites list
- SatListTreeView->clear();
+ m_Model->clear();
+ SatListTreeView->reset();
// Add each groups and satellites in the list
foreach ( SatelliteGroup* sat_group, data->skyComposite()->satellites()->groups() ) {
// Add the group
- QTreeWidgetItem *group_item = new QTreeWidgetItem( SatListTreeView, QStringList() << sat_group->name() );
- SatListTreeView->insertTopLevelItem( SatListTreeView->topLevelItemCount(), group_item );
-
+ QStandardItem* group_item;
+ QStandardItem* sat_item;
+ group_item = new QStandardItem( sat_group->name() );
+ m_Model->appendRow( group_item );
+
// Add all satellites of the group
for ( int i=0; i<sat_group->count(); ++i ) {
- // Create a checkbox to (un)select satellite
- QCheckBox *sat_cb = new QCheckBox( SatListTreeView );
- sat_cb->setText( sat_group->at(i)->name() );
+ sat_item = new QStandardItem( sat_group->at(i)->name() );
+ sat_item->setCheckable( true );
if ( Options::selectedSatellites().contains( sat_group->at(i)->name() ) )
- sat_cb->setCheckState( Qt::Checked );
-
- // Create our item
- QTreeWidgetItem *sat_item = new QTreeWidgetItem( group_item );
- // Add checkbox to our item
- SatListTreeView->setItemWidget( sat_item, 0, sat_cb );
- // Add item to satellites list
- group_item->addChild( sat_item );
+ sat_item->setCheckState( Qt::Checked );
+ group_item->setChild( i, sat_item );
}
}
}
@@ -95,21 +117,27 @@ void OpsSatellites::slotApply()
KStarsData* data = KStarsData::Instance();
QString sat_name;
QStringList selected_satellites;
-
+ QModelIndex group_index, sat_index;
+ QStandardItem* group_item;
+ QStandardItem* sat_item;
+
// Retrive each satellite in the list and select it if checkbox is checked
- for ( int i=0; i<SatListTreeView->topLevelItemCount(); ++i ) {
- QTreeWidgetItem *top_level_item = SatListTreeView->topLevelItem( i );
- for ( int j=0; j<top_level_item->childCount(); ++j ) {
- QTreeWidgetItem *item = top_level_item->child( j );
- QCheckBox *check_box = qobject_cast<QCheckBox*>( SatListTreeView->itemWidget( item, 0 ) );
- sat_name = check_box->text().replace("&", "");
+ for ( int i=0; i<m_Model->rowCount( SatListTreeView->rootIndex() ); ++i ) {
+ group_index = m_Model->index( i, 0, SatListTreeView->rootIndex() );
+ group_item = m_Model->itemFromIndex( group_index );
+
+ for ( int j=0; j<m_Model->rowCount( group_item->index() ); ++j ) {
+ sat_index = m_Model->index( j, 0, group_index );
+ sat_item = m_Model->itemFromIndex( sat_index );
+ sat_name = sat_item->data( 0 ).toString();
+
Satellite *sat = data->skyComposite()->satellites()->findSatellite( sat_name );
if ( sat ) {
- if ( check_box->checkState() == Qt::Checked ) {
- data->skyComposite()->satellites()->findSatellite( sat_name )->setSelected( true );
+ if ( sat_item->checkState() == Qt::Checked ) {
+ sat->setSelected( true );
selected_satellites.append( sat_name );
} else {
- data->skyComposite()->satellites()->findSatellite( sat_name )->setSelected( false );
+ sat->setSelected( false );
}
}
}
@@ -131,4 +159,17 @@ void OpsSatellites::slotShowSatellites( bool on )
kcfg_DrawSatellitesLikeStars->setEnabled( on );
}
+void OpsSatellites::slotFilterReg( const QString& filter )
+{
+ m_SortModel->setFilterRegExp( QRegExp( filter, Qt::CaseInsensitive, QRegExp::RegExp ) );
+ m_SortModel->setFilterKeyColumn( -1 );
+
+ // Expand all categories when the user use filter
+ if ( filter.length() > 0 )
+ SatListTreeView->expandAll();
+ else
+ SatListTreeView->collapseAll();
+}
+
+
#include "opssatellites.moc"
diff --git a/kstars/options/opssatellites.h b/kstars/options/opssatellites.h
index 3cb55d8..c1a1bf1 100644
--- a/kstars/options/opssatellites.h
+++ b/kstars/options/opssatellites.h
@@ -19,11 +19,21 @@
#include "ui_opssatellites.h"
-#include <kconfigdialog.h>
+#include <QStandardItemModel>
+#include <QSortFilterProxyModel>
+#include <kconfigdialog.h>
class KStars;
+
+class SatelliteSortFilterProxyModel : public QSortFilterProxyModel
+{
+public:
+ SatelliteSortFilterProxyModel( QObject* parent );
+ bool filterAcceptsRow( int sourceRow, const QModelIndex &sourceParent ) const;
+};
+
/**@class OpsSatellites
*The Satellites Tab of the Options window. In this Tab the user can configure
*satellites options and select satellites that should be draw
@@ -53,12 +63,15 @@ private:
KStars *ksw;
KConfigDialog *m_ConfigDialog;
+ QStandardItemModel *m_Model;
+ QSortFilterProxyModel *m_SortModel;
private slots:
void slotUpdateTLEs();
void slotShowSatellites( bool on );
void slotApply();
void slotCancel();
+ void slotFilterReg( const QString& );
};
#endif //OPSSATELLITES_H_
diff --git a/kstars/options/opssatellites.ui b/kstars/options/opssatellites.ui
index 2f030cc..21b637f 100644
--- a/kstars/options/opssatellites.ui
+++ b/kstars/options/opssatellites.ui
@@ -6,87 +6,103 @@
<rect>
<x>0</x>
<y>0</y>
- <width>468</width>
- <height>504</height>
+ <width>533</width>
+ <height>575</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="1" column="0">
<layout class="QVBoxLayout" name="verticalLayout">
<item>
- <layout class="QHBoxLayout" name="horizontalLayout">
- <item>
- <widget class="QCheckBox" name="kcfg_ShowSatellites">
- <property name="text">
- <string>Show satellites</string>
- </property>
- </widget>
- </item>
- <item>
- <widget class="QCheckBox" name="kcfg_ShowVisibleSatellites">
- <property name="text">
- <string>Show only visible satellites</string>
- </property>
- </widget>
- </item>
- </layout>
- </item>
- <item>
- <layout class="QHBoxLayout" name="horizontalLayout_2">
- <item>
- <widget class="QCheckBox" name="kcfg_ShowSatellitesLabels">
- <property name="text">
- <string>Show labels</string>
- </property>
- </widget>
- </item>
- <item>
- <widget class="QCheckBox" name="kcfg_DrawSatellitesLikeStars">
- <property name="text">
- <string>Draw satellites like stars</string>
- </property>
- </widget>
- </item>
- </layout>
- </item>
- <item>
- <widget class="KPushButton" name="UpdateTLEButton">
- <property name="sizePolicy">
- <sizepolicy hsizetype="Fixed" vsizetype="Fixed">
- <horstretch>0</horstretch>
- <verstretch>0</verstretch>
- </sizepolicy>
- </property>
- <property name="text">
- <string>Update TLEs</string>
+ <widget class="QGroupBox" name="groupBox_2">
+ <property name="title">
+ <string>View options</string>
</property>
+ <layout class="QVBoxLayout" name="verticalLayout_3">
+ <item>
+ <layout class="QHBoxLayout" name="horizontalLayout">
+ <property name="sizeConstraint">
+ <enum>QLayout::SetDefaultConstraint</enum>
+ </property>
+ <item>
+ <widget class="QCheckBox" name="kcfg_ShowSatellites">
+ <property name="text">
+ <string>Show satellites</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QCheckBox" name="kcfg_ShowVisibleSatellites">
+ <property name="text">
+ <string>Show only visible satellites</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ <item>
+ <layout class="QHBoxLayout" name="horizontalLayout_2">
+ <item>
+ <widget class="QCheckBox" name="kcfg_ShowSatellitesLabels">
+ <property name="text">
+ <string>Show labels</string>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="QCheckBox" name="kcfg_DrawSatellitesLikeStars">
+ <property name="text">
+ <string>Draw satellites like stars</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ </layout>
+ <zorder></zorder>
+ <zorder></zorder>
</widget>
</item>
<item>
- <widget class="QTreeWidget" name="SatListTreeView">
- <property name="rootIsDecorated">
- <bool>true</bool>
+ <widget class="QGroupBox" name="groupBox">
+ <property name="title">
+ <string>LIst of sattelies</string>
</property>
- <property name="headerHidden">
- <bool>true</bool>
- </property>
- <property name="columnCount">
- <number>1</number>
- </property>
- <attribute name="headerVisible">
- <bool>false</bool>
- </attribute>
- <attribute name="headerCascadingSectionResizes">
- <bool>false</bool>
- </attribute>
- <attribute name="headerDefaultSectionSize">
- <number>60</number>
- </attribute>
- <column>
- <property name="text">
- <string notr="true">1</string>
- </property>
- </column>
+ <layout class="QVBoxLayout" name="verticalLayout_2">
+ <item>
+ <layout class="QHBoxLayout" name="horizontalLayout_3">
+ <item>
+ <widget class="KLineEdit" name="FilterEdit">
+ <property name="squeezedTextEnabled">
+ <bool>false</bool>
+ </property>
+ <property name="clickMessage">
+ <string>Search satellites</string>
+ </property>
+ <property name="showClearButton" stdset="0">
+ <bool>true</bool>
+ </property>
+ </widget>
+ </item>
+ <item>
+ <widget class="KPushButton" name="UpdateTLEButton">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Fixed" vsizetype="Fixed">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <property name="text">
+ <string>Update TLEs</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </item>
+ <item>
+ <widget class="QTreeView" name="SatListTreeView"/>
+ </item>
+ </layout>
</widget>
</item>
</layout>
@@ -99,6 +115,11 @@
<extends>QPushButton</extends>
<header>kpushbutton.h</header>
</customwidget>
+ <customwidget>
+ <class>KLineEdit</class>
+ <extends>QLineEdit</extends>
+ <header>klineedit.h</header>
+ </customwidget>
</customwidgets>
<resources/>
<connections/>
More information about the Kstars-devel
mailing list