Skip to content

Commit

Permalink
attribute table: docking available again, better switching between al…
Browse files Browse the repository at this point in the history
…l/selected rows, fixed editing toggle

git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@10374 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
wonder committed Mar 21, 2009
1 parent 51bf1a1 commit 1187a1a
Show file tree
Hide file tree
Showing 3 changed files with 118 additions and 28 deletions.
76 changes: 60 additions & 16 deletions src/app/attributetable/BeataDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,25 @@
#include "qgisapp.h"
#include "qgssearchquerybuilder.h"


class QBeataTableDock : public QDockWidget
{
public:
QBeataTableDock( const QString & title, QWidget * parent = 0, Qt::WindowFlags flags = 0 )
: QDockWidget( title, parent, flags )
{
setObjectName("AttributeTable"); // set object name so the position can be saved
}

virtual void closeEvent( QCloseEvent * ev )
{
deleteLater();
}
};


BeataDialog::BeataDialog(QgsVectorLayer *theLayer, QWidget *parent, Qt::WindowFlags flags)
: QDialog(parent, flags)
: QDialog(parent, flags), mDock(NULL)
{
mLayer = theLayer;

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

mShowBox = showBox;
mShowBox->addItem("Show unselected rows");
mShowBox->addItem("Hide unselected rows");
QSettings mySettings;
bool myDockFlag = mySettings.value( "/qgis/dockAttributeTable", false ).toBool();
if ( myDockFlag )
{
mDock = new QBeataTableDock( tr( "Attribute table - %1" ).arg( mLayer->name() ), QgisApp::instance() );
mDock->setAllowedAreas( Qt::BottomDockWidgetArea | Qt::TopDockWidgetArea );
mDock->setWidget( this );
QgisApp::instance()->addDockWidget( Qt::BottomDockWidgetArea, mDock );
}

setWindowTitle( tr( "Attribute table - %1" ).arg( mLayer->name() ) );

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

connect(mShowBox, SIGNAL(currentIndexChanged(const QString &)), this, SLOT(toggleShowDeselected(const QString &)));
connect(btnShowAll, SIGNAL(clicked()), this, SLOT(clickedShowAll()));
connect(btnShowSelected, SIGNAL(clicked()), this, SLOT(clickedShowSelected()));

connect(searchButton, SIGNAL(clicked()), this, SLOT(search()));
connect(actionsButton, SIGNAL(clicked()), this, SLOT(showAdvanced()));

connect(mLayer, SIGNAL(selectionChanged()), this, SLOT(updateSelectionFromLayer()));
connect(mLayer, SIGNAL(layerDeleted()), this, SLOT( close()));
connect(mView->verticalHeader(), SIGNAL(sectionClicked(int)), this, SLOT(updateRowSelection(int)));
connect(mModel, SIGNAL(modelChanged()), this, SLOT(updateSelection()));

clickedShowAll(); // make sure the show all button is checked

mLastClickedHeaderIndex = 0;
mSelectionModel = new QItemSelectionModel(mFilterModel);
Expand All @@ -96,8 +125,11 @@ void BeataDialog::closeEvent( QCloseEvent* event )
{
QDialog::closeEvent( event );

QSettings settings;
settings.setValue( "/Windows/BetterAttributeTable/geometry", saveGeometry() );
if ( mDock == NULL )
{
QSettings settings;
settings.setValue( "/Windows/BetterAttributeTable/geometry", saveGeometry() );
}
}


Expand Down Expand Up @@ -188,18 +220,30 @@ void BeataDialog::removeSelection()
mLayer->removeSelection();
}

void BeataDialog::toggleShowDeselected(const QString &text)
void BeataDialog::clickedShowAll()
{
if (text == "Show unselected rows")
// the button can't be unchecked by clicking it
// gets unchecked when show selected is clicked
if (!btnShowAll->isChecked())
{
mFilterModel->mHideUnselected = false;
//TODO: divne
//mModel->changeLayout();
mFilterModel->invalidate();
return;
btnShowAll->setChecked(true);
}
btnShowSelected->setChecked(false);

mFilterModel->mHideUnselected = false;
mFilterModel->invalidate();
//TODO: weird
//mModel->changeLayout();
}

// show only selected
void BeataDialog::clickedShowSelected()
{
if (!btnShowSelected->isChecked())
{
btnShowSelected->setChecked(true);
}
btnShowAll->setChecked(false);

mFilterModel->mHideUnselected = true;
mFilterModel->invalidate();
//mModel->changeLayout();
Expand Down
7 changes: 6 additions & 1 deletion src/app/attributetable/BeataDialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class QPushButton;
class QLineEdit;
class QComboBox;
class QMenu;
class QDockWidget;

class BeataModel;
class BeataFilterModel;
Expand All @@ -60,8 +61,10 @@ private slots:
void updateSelectionFromLayer();
void updateRowSelection(int index);
void updateRowSelection(int first, int last, bool startNewSelection);
void toggleShowDeselected(const QString &text);

void clickedShowAll();
void clickedShowSelected();

void startEditing();
void invertSelection();
void removeSelection();
Expand Down Expand Up @@ -98,6 +101,8 @@ private slots:

QItemSelectionModel* mSelectionModel;
int mLastClickedHeaderIndex;

QDockWidget *mDock;
};

#endif
63 changes: 52 additions & 11 deletions src/ui/BeataGui.ui
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<item>
<widget class="QPushButton" name="searchButton" >
<property name="text" >
<string>Search</string>
<string>&amp;Search</string>
</property>
</widget>
</item>
Expand All @@ -46,21 +46,53 @@
<widget class="QComboBox" name="columnBox" />
</item>
<item>
<widget class="Line" name="line" >
<spacer>
<property name="orientation" >
<enum>Qt::Vertical</enum>
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="showBox" />
<property name="sizeHint" >
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="Line" name="line_2" >
<property name="orientation" >
<enum>Qt::Vertical</enum>
<layout class="QHBoxLayout" >
<property name="spacing" >
<number>0</number>
</property>
</widget>
<property name="leftMargin" >
<number>0</number>
</property>
<item>
<widget class="QPushButton" name="btnShowAll" >
<property name="focusPolicy" >
<enum>Qt::NoFocus</enum>
</property>
<property name="text" >
<string>&amp;All</string>
</property>
<property name="checkable" >
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="btnShowSelected" >
<property name="focusPolicy" >
<enum>Qt::NoFocus</enum>
</property>
<property name="text" >
<string>S&amp;elected</string>
</property>
<property name="checkable" >
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QPushButton" name="actionsButton" >
Expand All @@ -80,6 +112,15 @@
<header>BeataView.h</header>
</customwidget>
</customwidgets>
<tabstops>
<tabstop>mView</tabstop>
<tabstop>searchButton</tabstop>
<tabstop>query</tabstop>
<tabstop>columnBox</tabstop>
<tabstop>btnShowAll</tabstop>
<tabstop>btnShowSelected</tabstop>
<tabstop>actionsButton</tabstop>
</tabstops>
<resources/>
<connections/>
</ui>

0 comments on commit 1187a1a

Please sign in to comment.