Skip to content

Commit 9cdba6e

Browse files
author
wonder
committed
attribute table: docking available again, better switching between all/selected rows, fixed editing toggle
git-svn-id: http://svn.osgeo.org/qgis/trunk@10374 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent af6f0d2 commit 9cdba6e

File tree

3 files changed

+118
-28
lines changed

3 files changed

+118
-28
lines changed

src/app/attributetable/BeataDialog.cpp

+60-16
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,25 @@
3030
#include "qgisapp.h"
3131
#include "qgssearchquerybuilder.h"
3232

33+
34+
class QBeataTableDock : public QDockWidget
35+
{
36+
public:
37+
QBeataTableDock( const QString & title, QWidget * parent = 0, Qt::WindowFlags flags = 0 )
38+
: QDockWidget( title, parent, flags )
39+
{
40+
setObjectName("AttributeTable"); // set object name so the position can be saved
41+
}
42+
43+
virtual void closeEvent( QCloseEvent * ev )
44+
{
45+
deleteLater();
46+
}
47+
};
48+
49+
3350
BeataDialog::BeataDialog(QgsVectorLayer *theLayer, QWidget *parent, Qt::WindowFlags flags)
34-
: QDialog(parent, flags)
51+
: QDialog(parent, flags), mDock(NULL)
3552
{
3653
mLayer = theLayer;
3754

@@ -50,9 +67,17 @@ BeataDialog::BeataDialog(QgsVectorLayer *theLayer, QWidget *parent, Qt::WindowFl
5067
mColumnBox = columnBox;
5168
columnBoxInit();
5269

53-
mShowBox = showBox;
54-
mShowBox->addItem("Show unselected rows");
55-
mShowBox->addItem("Hide unselected rows");
70+
QSettings mySettings;
71+
bool myDockFlag = mySettings.value( "/qgis/dockAttributeTable", false ).toBool();
72+
if ( myDockFlag )
73+
{
74+
mDock = new QBeataTableDock( tr( "Attribute table - %1" ).arg( mLayer->name() ), QgisApp::instance() );
75+
mDock->setAllowedAreas( Qt::BottomDockWidgetArea | Qt::TopDockWidgetArea );
76+
mDock->setWidget( this );
77+
QgisApp::instance()->addDockWidget( Qt::BottomDockWidgetArea, mDock );
78+
}
79+
80+
setWindowTitle( tr( "Attribute table - %1" ).arg( mLayer->name() ) );
5681

5782
mMenuActions = new QMenu();
5883
mMenuActions->addAction(tr("Advanced search"), this, SLOT(advancedSearch()));
@@ -69,19 +94,23 @@ BeataDialog::BeataDialog(QgsVectorLayer *theLayer, QWidget *parent, Qt::WindowFl
6994
mActionToggleEditing->setCheckable( true );
7095
mActionToggleEditing->setEnabled( mLayer->dataProvider()->capabilities() & QgsVectorDataProvider::ChangeAttributeValues );
7196
// info from table to application
72-
connect( this, SIGNAL( editingToggled( QgsMapLayer * ) ), parentWidget(), SLOT( toggleEditing( QgsMapLayer * ) ) );
97+
connect( this, SIGNAL( editingToggled( QgsMapLayer * ) ), QgisApp::instance(), SLOT( toggleEditing( QgsMapLayer * ) ) );
7398
// info from layer to table
7499
connect( mLayer, SIGNAL( editingStarted() ), this, SLOT( editingToggled() ) );
75100
connect( mLayer, SIGNAL( editingStopped() ), this, SLOT( editingToggled() ) );
76101

77-
connect(mShowBox, SIGNAL(currentIndexChanged(const QString &)), this, SLOT(toggleShowDeselected(const QString &)));
102+
connect(btnShowAll, SIGNAL(clicked()), this, SLOT(clickedShowAll()));
103+
connect(btnShowSelected, SIGNAL(clicked()), this, SLOT(clickedShowSelected()));
104+
78105
connect(searchButton, SIGNAL(clicked()), this, SLOT(search()));
79106
connect(actionsButton, SIGNAL(clicked()), this, SLOT(showAdvanced()));
80107

81108
connect(mLayer, SIGNAL(selectionChanged()), this, SLOT(updateSelectionFromLayer()));
82109
connect(mLayer, SIGNAL(layerDeleted()), this, SLOT( close()));
83110
connect(mView->verticalHeader(), SIGNAL(sectionClicked(int)), this, SLOT(updateRowSelection(int)));
84111
connect(mModel, SIGNAL(modelChanged()), this, SLOT(updateSelection()));
112+
113+
clickedShowAll(); // make sure the show all button is checked
85114

86115
mLastClickedHeaderIndex = 0;
87116
mSelectionModel = new QItemSelectionModel(mFilterModel);
@@ -96,8 +125,11 @@ void BeataDialog::closeEvent( QCloseEvent* event )
96125
{
97126
QDialog::closeEvent( event );
98127

99-
QSettings settings;
100-
settings.setValue( "/Windows/BetterAttributeTable/geometry", saveGeometry() );
128+
if ( mDock == NULL )
129+
{
130+
QSettings settings;
131+
settings.setValue( "/Windows/BetterAttributeTable/geometry", saveGeometry() );
132+
}
101133
}
102134

103135

@@ -188,18 +220,30 @@ void BeataDialog::removeSelection()
188220
mLayer->removeSelection();
189221
}
190222

191-
void BeataDialog::toggleShowDeselected(const QString &text)
223+
void BeataDialog::clickedShowAll()
192224
{
193-
if (text == "Show unselected rows")
225+
// the button can't be unchecked by clicking it
226+
// gets unchecked when show selected is clicked
227+
if (!btnShowAll->isChecked())
194228
{
195-
mFilterModel->mHideUnselected = false;
196-
//TODO: divne
197-
//mModel->changeLayout();
198-
mFilterModel->invalidate();
199-
return;
229+
btnShowAll->setChecked(true);
200230
}
231+
btnShowSelected->setChecked(false);
232+
233+
mFilterModel->mHideUnselected = false;
234+
mFilterModel->invalidate();
235+
//TODO: weird
236+
//mModel->changeLayout();
237+
}
201238

202-
// show only selected
239+
void BeataDialog::clickedShowSelected()
240+
{
241+
if (!btnShowSelected->isChecked())
242+
{
243+
btnShowSelected->setChecked(true);
244+
}
245+
btnShowAll->setChecked(false);
246+
203247
mFilterModel->mHideUnselected = true;
204248
mFilterModel->invalidate();
205249
//mModel->changeLayout();

src/app/attributetable/BeataDialog.h

+6-1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ class QPushButton;
3535
class QLineEdit;
3636
class QComboBox;
3737
class QMenu;
38+
class QDockWidget;
3839

3940
class BeataModel;
4041
class BeataFilterModel;
@@ -60,8 +61,10 @@ private slots:
6061
void updateSelectionFromLayer();
6162
void updateRowSelection(int index);
6263
void updateRowSelection(int first, int last, bool startNewSelection);
63-
void toggleShowDeselected(const QString &text);
6464

65+
void clickedShowAll();
66+
void clickedShowSelected();
67+
6568
void startEditing();
6669
void invertSelection();
6770
void removeSelection();
@@ -98,6 +101,8 @@ private slots:
98101

99102
QItemSelectionModel* mSelectionModel;
100103
int mLastClickedHeaderIndex;
104+
105+
QDockWidget *mDock;
101106
};
102107

103108
#endif

src/ui/BeataGui.ui

+52-11
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
<item>
2222
<widget class="QPushButton" name="searchButton" >
2323
<property name="text" >
24-
<string>Search</string>
24+
<string>&amp;Search</string>
2525
</property>
2626
</widget>
2727
</item>
@@ -46,21 +46,53 @@
4646
<widget class="QComboBox" name="columnBox" />
4747
</item>
4848
<item>
49-
<widget class="Line" name="line" >
49+
<spacer>
5050
<property name="orientation" >
51-
<enum>Qt::Vertical</enum>
51+
<enum>Qt::Horizontal</enum>
5252
</property>
53-
</widget>
54-
</item>
55-
<item>
56-
<widget class="QComboBox" name="showBox" />
53+
<property name="sizeHint" >
54+
<size>
55+
<width>40</width>
56+
<height>20</height>
57+
</size>
58+
</property>
59+
</spacer>
5760
</item>
5861
<item>
59-
<widget class="Line" name="line_2" >
60-
<property name="orientation" >
61-
<enum>Qt::Vertical</enum>
62+
<layout class="QHBoxLayout" >
63+
<property name="spacing" >
64+
<number>0</number>
6265
</property>
63-
</widget>
66+
<property name="leftMargin" >
67+
<number>0</number>
68+
</property>
69+
<item>
70+
<widget class="QPushButton" name="btnShowAll" >
71+
<property name="focusPolicy" >
72+
<enum>Qt::NoFocus</enum>
73+
</property>
74+
<property name="text" >
75+
<string>&amp;All</string>
76+
</property>
77+
<property name="checkable" >
78+
<bool>true</bool>
79+
</property>
80+
</widget>
81+
</item>
82+
<item>
83+
<widget class="QPushButton" name="btnShowSelected" >
84+
<property name="focusPolicy" >
85+
<enum>Qt::NoFocus</enum>
86+
</property>
87+
<property name="text" >
88+
<string>S&amp;elected</string>
89+
</property>
90+
<property name="checkable" >
91+
<bool>true</bool>
92+
</property>
93+
</widget>
94+
</item>
95+
</layout>
6496
</item>
6597
<item>
6698
<widget class="QPushButton" name="actionsButton" >
@@ -80,6 +112,15 @@
80112
<header>BeataView.h</header>
81113
</customwidget>
82114
</customwidgets>
115+
<tabstops>
116+
<tabstop>mView</tabstop>
117+
<tabstop>searchButton</tabstop>
118+
<tabstop>query</tabstop>
119+
<tabstop>columnBox</tabstop>
120+
<tabstop>btnShowAll</tabstop>
121+
<tabstop>btnShowSelected</tabstop>
122+
<tabstop>actionsButton</tabstop>
123+
</tabstops>
83124
<resources/>
84125
<connections/>
85126
</ui>

0 commit comments

Comments
 (0)