[Kstars-devel] branches/kstars/carbonix/kstars/kstars
Victor Carbune
victor.carbune at gmail.com
Fri Jun 11 01:43:42 CEST 2010
SVN commit 1136872 by vcarbune:
Replaced the regular QTableView (particularly in Observing List for the moment) with the new KSObjectList (which extends QTableView)
There's still a bug to fix, but overall the results really sound good.
We have a view (KSObjectList) which has a default context menu.
Making use of Q_PROPERTY enhances the developing process by enabling the use of the designer when specifying
what options are present on the context menu.
CCMAIL: asimha at gmail.com, prak902000 at gmail.com, kstars-devel at kde.org
M +99 -30 ksobjectlist.cpp
M +36 -1 ksobjectlist.h
A objlistpopupmenu.cpp [License: GPL (v2+)]
A objlistpopupmenu.h [License: GPL (v2+)]
M +2 -2 tools/objectlist.ui
M +4 -3 tools/observinglist.cpp
M +42 -0 tools/observinglist.ui
--- branches/kstars/carbonix/kstars/kstars/ksobjectlist.cpp #1136871:1136872
@@ -19,54 +19,123 @@
#include <QObject>
#include <QItemSelectionModel>
#include "ksobjectlist.h"
+
KSObjectList::KSObjectList(QWidget *parent):QTableView(parent)
{
- singleSelection = false;
- noSelection = true;
-
setContextMenuPolicy(Qt::CustomContextMenu);
- QObject::connect(this, SIGNAL(customContextMenuRequested(const QPoint &)), this, SLOT(slotContextMenu(const QPoint &)));
+ connect(this, SIGNAL(customContextMenuRequested(const QPoint &)), SLOT(slotContextMenu(const QPoint &)));
pmenu = new ObjListPopupMenu();
+
+ m_showAVT = true;
+ m_showAddToSession = m_showCenter = m_showDetails = m_showScope = m_showLinks = false;
+ m_showAddVisibleTonight = m_showRemoveFromWishList = m_showRemoveFromSessionPlan = false;
}
+KSObjectList::~KSObjectList()
+{
+// delete pmenu;
+}
+
+// Read functions for Q_PROPERTY items
+bool KSObjectList::showAddToSession() const { return m_showAddToSession; }
+bool KSObjectList::showAddVisibleTonight() const { return m_showAddVisibleTonight; }
+bool KSObjectList::showCenter() const { return m_showCenter; }
+bool KSObjectList::showAVT() const { return m_showAVT; }
+bool KSObjectList::showDetails() const { return m_showDetails; }
+bool KSObjectList::showScope() const { return m_showScope; }
+bool KSObjectList::showLinks() const { return m_showLinks; }
+bool KSObjectList::showRemoveFromWishList() const { return m_showRemoveFromWishList; }
+bool KSObjectList::showRemoveFromSessionPlan() const { return m_showRemoveFromSessionPlan; }
+
+// Write functions for Q_PROPERTY items
+void KSObjectList::setShowAddToSession(const bool &visible) { m_showAddToSession = visible; }
+void KSObjectList::setShowAddVisibleTonight(const bool &visible) { m_showAddVisibleTonight = visible; }
+void KSObjectList::setShowCenter(const bool &visible) { m_showCenter = visible; }
+void KSObjectList::setShowAVT(const bool &visible) { m_showAVT = visible; }
+void KSObjectList::setShowDetails(const bool &visible) { m_showDetails = visible; }
+void KSObjectList::setShowScope(const bool &visible) { m_showScope = visible; }
+void KSObjectList::setShowLinks(const bool &visible) { m_showLinks = visible; }
+void KSObjectList::setShowRemoveFromWishList(const bool &visible) { m_showRemoveFromWishList = visible; }
+void KSObjectList::setShowRemoveFromSessionPlan(const bool &visible) { m_showRemoveFromSessionPlan = visible; }
+
+// Public slots
void KSObjectList::slotContextMenu(const QPoint &pos)
{
int countRows = selectionModel()->selectedRows().count();
- qDebug() << countRows;
- if (countRows == 1) {
- pmenu->initPopupMenu( true, true, true, true, true, true );
- pmenu->popup(QWidget::mapToGlobal(pos));
+ QPoint localPos = QWidget::mapToGlobal(pos);
+
+ if (countRows >= 2) {
+ pmenu->init();
+
+ if (m_showAddToSession) {
+ pmenu->showAddToSession();
}
+ if (m_showAddVisibleTonight) {
+ pmenu->showAddVisibleTonight();
}
+ pmenu->addSeparator();
-void KSObjectList::slotNewSelection() {
- singleSelection = false;
- noSelection = false;
+ if (m_showAVT) {
+ pmenu->showAVT();
+ }
+ pmenu->addSeparator();
- QModelIndexList selectedItems;
- QString newName;
- SkyObject *o;
+ if (m_showLinks) {
+ pmenu->showLinks();
+ }
+ pmenu->addSeparator();
- selectedItems = (selectionModel()->selection()).indexes();
- qDebug() << "New Selection works!";
-/*
- //When one object is selected
- if (selectedItems.size() == selectionModel()->columnCount()) {
- newName = selectedItems[0].data().toString();
- singleSelection = true;
+ if (m_showRemoveFromWishList) {
+ pmenu->showRemoveFromWishList();
+ }
+ if (m_showRemoveFromSessionPlan) {
+ pmenu->showRemoveFromSessionPlan();
+ }
- qDebug() << newName;
+ pmenu->popup(localPos);
}
- if( singleSelection ) {
- qDebug() << "Single selection";
+ if (countRows == 1) {
+ pmenu->init();
- } else if ( selectedItems.size() == 0 ) {//Nothing selected
- noSelection = true;
- qDebug() << "No selection has been made";
- } else { //more than one object selected.
- qDebug() << "A lot of objects were selected";
+ if (m_showAddToSession) {
+ pmenu->showAddToSession();
}
- */
+ if (m_showAddVisibleTonight) {
+ pmenu->showAddVisibleTonight();
}
+ pmenu->addSeparator();
+
+ if (m_showCenter) {
+ pmenu->showCenter();
+ }
+ if (m_showScope) {
+ pmenu->showScope();
+ }
+ pmenu->addSeparator();
+
+ if (m_showDetails) {
+ pmenu->showDetails();
+ }
+ if (m_showAVT) {
+ pmenu->showAVT();
+ }
+ pmenu->addSeparator();
+
+ if (m_showLinks) {
+ pmenu->showLinks();
+ }
+ pmenu->addSeparator();
+
+ if (m_showRemoveFromWishList) {
+ pmenu->showRemoveFromWishList();
+ }
+ if (m_showRemoveFromSessionPlan) {
+ pmenu->showRemoveFromSessionPlan();
+ }
+
+ pmenu->popup(localPos);
+ }
+}
+
--- branches/kstars/carbonix/kstars/kstars/ksobjectlist.h #1136871:1136872
@@ -28,15 +28,50 @@
{
Q_OBJECT
+ Q_PROPERTY ( bool showAddToSession READ showAddToSession WRITE setShowAddToSession )
+ Q_PROPERTY ( bool showAddVisibleTonight READ showAddVisibleTonight WRITE setShowAddVisibleTonight )
+ Q_PROPERTY ( bool showCenter READ showCenter WRITE setShowCenter )
+ Q_PROPERTY ( bool showDetails READ showDetails WRITE setShowDetails )
+ Q_PROPERTY ( bool showAVT READ showAVT WRITE setShowAVT )
+ Q_PROPERTY ( bool showScope READ showScope WRITE setShowScope )
+ Q_PROPERTY ( bool showLinks READ showLinks WRITE setShowLinks )
+ Q_PROPERTY ( bool showRemoveFromWishList READ showRemoveFromWishList WRITE setShowRemoveFromWishList )
+ Q_PROPERTY ( bool showRemoveFromSessionPlan READ showRemoveFromSessionPlan WRITE setShowRemoveFromSessionPlan )
+
public:
KSObjectList(QWidget *parent);
+ ~KSObjectList();
+ /* Read functions for properties */
+ bool showAddToSession() const;
+ bool showAddVisibleTonight() const;
+ bool showCenter() const;
+ bool showAVT() const;
+ bool showDetails() const;
+ bool showScope() const;
+ bool showLinks() const;
+ bool showRemoveFromWishList() const;
+ bool showRemoveFromSessionPlan() const;
+
+ /* Write functions for properties */
+ void setShowAddToSession(const bool &);
+ void setShowAddVisibleTonight(const bool &);
+ void setShowCenter(const bool &);
+ void setShowAVT(const bool &);
+ void setShowDetails(const bool &);
+ void setShowScope(const bool &);
+ void setShowLinks(const bool &);
+ void setShowRemoveFromWishList(const bool &);
+ void setShowRemoveFromSessionPlan(const bool &);
+
public slots:
void slotContextMenu(const QPoint &pos);
- void slotNewSelection();
private:
ObjListPopupMenu *pmenu;
bool singleSelection, noSelection;
+ bool m_showAddToSession, m_showCenter, m_showDetails, m_showScope, m_showLinks;
+ bool m_showAddVisibleTonight, m_showAVT, m_showRemoveFromWishList, m_showRemoveFromSessionPlan;
};
+
#endif
--- branches/kstars/carbonix/kstars/kstars/tools/objectlist.ui #1136871:1136872
@@ -338,7 +338,7 @@
</attribute>
<layout class="QVBoxLayout">
<item>
- <widget class="QTableView" name="TableView">
+ <widget class="KSObjectList" name="TableView">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch>
@@ -370,7 +370,7 @@
</attribute>
<layout class="QHBoxLayout">
<item>
- <widget class="QTableView" name="SessionView">
+ <widget class="KSObjectList" name="SessionView">
<property name="editTriggers">
<set>QAbstractItemView::NoEditTriggers</set>
</property>
--- branches/kstars/carbonix/kstars/kstars/tools/observinglist.cpp #1136871:1136872
@@ -1301,7 +1301,6 @@
}
bool ObservingList::eventFilter( QObject *obj, QEvent *event ) {
- /*
if( obj == ui->ImagePreview ) {
if( event->type() == QEvent::MouseButtonRelease ) {
if( currentObject() ) {
@@ -1317,6 +1316,7 @@
return true;
}
}
+ /*
if( obj == ui->TableView->viewport() && ! noSelection ) {
if( event->type() == QEvent::MouseButtonRelease ) {
QMouseEvent *mouseEvent = static_cast<QMouseEvent* >(event);
@@ -1326,7 +1326,7 @@
pmenu->initPopupMenu( true, true, true, showScope, true, true );
else
pmenu->initPopupMenu( true, false, false, false, true );
-// pmenu->popup( pos );
+ pmenu->popup( pos );
return true;
}
}
@@ -1340,13 +1340,14 @@
pmenu->initPopupMenu( false, true, true, showScope, true, true, true );
else
pmenu->initPopupMenu( false, false, false, false, true, false, true );
-// pmenu->popup( pos );
+ pmenu->popup( pos );
return true;
}
}
}
*/
return false;
+
}
void ObservingList::slotGoogleImage() {
--- branches/kstars/carbonix/kstars/kstars/tools/observinglist.ui #1136871:1136872
@@ -339,6 +339,30 @@
<layout class="QVBoxLayout">
<item>
<widget class="KSObjectList" name="TableView">
+ <property name="showAddToSession">
+ <set>true</set>
+ </property>
+ <property name="showAddVisibleTonight">
+ <set>true</set>
+ </property>
+ <property name="showCenter">
+ <set>true</set>
+ </property>
+ <property name="showScope">
+ <set>true</set>
+ </property>
+ <property name="showDetails">
+ <set>true</set>
+ </property>
+ <property name="showAVT">
+ <set>true</set>
+ </property>
+ <property name="showLinks">
+ <set>true</set>
+ </property>
+ <property name="showRemoveFromWishList">
+ <set>true</set>
+ </property>
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch>
@@ -371,6 +395,24 @@
<layout class="QHBoxLayout">
<item>
<widget class="KSObjectList" name="SessionView">
+ <property name="showCenter">
+ <set>true</set>
+ </property>
+ <property name="showScope">
+ <set>true</set>
+ </property>
+ <property name="showDetails">
+ <set>true</set>
+ </property>
+ <property name="showAVT">
+ <set>true</set>
+ </property>
+ <property name="showLinks">
+ <set>true</set>
+ </property>
+ <property name="showRemoveFromSessionPlan">
+ <set>true</set>
+ </property>
<property name="editTriggers">
<set>QAbstractItemView::NoEditTriggers</set>
</property>
More information about the Kstars-devel
mailing list