Skip to content

Commit

Permalink
Use a real toolbar for attribute table dialog
Browse files Browse the repository at this point in the history
- Fixes style issues on various platforms (esp. OSX)
- Allows resizing the window smaller and actions get moved
to overflow menu
  • Loading branch information
nyalldawson committed Jun 20, 2016
1 parent fcbaf7f commit 33d64dc
Show file tree
Hide file tree
Showing 3 changed files with 443 additions and 742 deletions.
131 changes: 66 additions & 65 deletions src/app/qgsattributetabledialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,10 @@ void QgsAttributeTableDialog::updateMultiEditButtonState()
if ( mLayer->editFormConfig()->layout() == QgsEditFormConfig::UiFileLayout )
return;

mToggleMultiEditButton->setEnabled( mLayer->isEditable() );
mActionToggleMultiEdit->setEnabled( mLayer->isEditable() );
if ( mLayer->isEditable() && mMainView->view() != QgsDualView::AttributeEditor )
{
mToggleMultiEditButton->setChecked( false );
mActionToggleMultiEdit->setChecked( false );
}
}

Expand Down Expand Up @@ -156,7 +156,7 @@ QgsAttributeTableDialog::QgsAttributeTableDialog( QgsVectorLayer *theLayer, QWid
connect( mFilterActionMapper, SIGNAL( mapped( QObject* ) ), SLOT( filterColumnChanged( QObject* ) ) );
connect( mFilterQuery, SIGNAL( returnPressed() ), SLOT( filterQueryAccepted() ) );
connect( mActionApplyFilter, SIGNAL( triggered() ), SLOT( filterQueryAccepted() ) );
connect( mSetStyles, SIGNAL( pressed() ), SLOT( openConditionalStyles() ) );
connect( mActionSetStyles, SIGNAL( triggered() ), SLOT( openConditionalStyles() ) );

// info from layer to table
connect( mLayer, SIGNAL( editingStarted() ), this, SLOT( editingToggled() ) );
Expand Down Expand Up @@ -188,23 +188,23 @@ QgsAttributeTableDialog::QgsAttributeTableDialog( QgsVectorLayer *theLayer, QWid
columnBoxInit();
updateTitle();

mRemoveSelectionButton->setIcon( QgsApplication::getThemeIcon( "/mActionUnselectAttributes.png" ) );
mSelectAllButton->setIcon( QgsApplication::getThemeIcon( "/mActionSelectAll.svg" ) );
mSelectedToTopButton->setIcon( QgsApplication::getThemeIcon( "/mActionSelectedToTop.png" ) );
mCopySelectedRowsButton->setIcon( QgsApplication::getThemeIcon( "/mActionCopySelected.png" ) );
mZoomMapToSelectedRowsButton->setIcon( QgsApplication::getThemeIcon( "/mActionZoomToSelected.svg" ) );
mPanMapToSelectedRowsButton->setIcon( QgsApplication::getThemeIcon( "/mActionPanToSelected.svg" ) );
mInvertSelectionButton->setIcon( QgsApplication::getThemeIcon( "/mActionInvertSelection.svg" ) );
mToggleEditingButton->setIcon( QgsApplication::getThemeIcon( "/mActionToggleEditing.svg" ) );
mSaveEditsButton->setIcon( QgsApplication::getThemeIcon( "/mActionSaveEdits.svg" ) );
mDeleteSelectedButton->setIcon( QgsApplication::getThemeIcon( "/mActionDeleteSelected.svg" ) );
mOpenFieldCalculator->setIcon( QgsApplication::getThemeIcon( "/mActionCalculateField.svg" ) );
mAddAttribute->setIcon( QgsApplication::getThemeIcon( "/mActionNewAttribute.png" ) );
mRemoveAttribute->setIcon( QgsApplication::getThemeIcon( "/mActionDeleteAttribute.png" ) );
mActionRemoveSelection->setIcon( QgsApplication::getThemeIcon( "/mActionUnselectAttributes.png" ) );
mActionSelectAll->setIcon( QgsApplication::getThemeIcon( "/mActionSelectAll.svg" ) );
mActionSelectedToTop->setIcon( QgsApplication::getThemeIcon( "/mActionSelectedToTop.png" ) );
mActionCopySelectedRows->setIcon( QgsApplication::getThemeIcon( "/mActionCopySelected.png" ) );
mActionZoomMapToSelectedRows->setIcon( QgsApplication::getThemeIcon( "/mActionZoomToSelected.svg" ) );
mActionPanMapToSelectedRows->setIcon( QgsApplication::getThemeIcon( "/mActionPanToSelected.svg" ) );
mActionInvertSelection->setIcon( QgsApplication::getThemeIcon( "/mActionInvertSelection.svg" ) );
mActionToggleEditing->setIcon( QgsApplication::getThemeIcon( "/mActionToggleEditing.svg" ) );
mActionSaveEdits->setIcon( QgsApplication::getThemeIcon( "/mActionSaveEdits.svg" ) );
mActionDeleteSelected->setIcon( QgsApplication::getThemeIcon( "/mActionDeleteSelected.svg" ) );
mActionOpenFieldCalculator->setIcon( QgsApplication::getThemeIcon( "/mActionCalculateField.svg" ) );
mActionAddAttribute->setIcon( QgsApplication::getThemeIcon( "/mActionNewAttribute.png" ) );
mActionRemoveAttribute->setIcon( QgsApplication::getThemeIcon( "/mActionDeleteAttribute.png" ) );
mTableViewButton->setIcon( QgsApplication::getThemeIcon( "/mActionOpenTable.svg" ) );
mAttributeViewButton->setIcon( QgsApplication::getThemeIcon( "/mActionPropertyItem.png" ) );
mExpressionSelectButton->setIcon( QgsApplication::getThemeIcon( "/mIconExpressionSelect.svg" ) );
mAddFeature->setIcon( QgsApplication::getThemeIcon( "/mActionNewTableRow.png" ) );
mActionExpressionSelect->setIcon( QgsApplication::getThemeIcon( "/mIconExpressionSelect.svg" ) );
mActionAddFeature->setIcon( QgsApplication::getThemeIcon( "/mActionNewTableRow.png" ) );

// toggle editing
bool canChangeAttributes = mLayer->dataProvider()->capabilities() & QgsVectorDataProvider::ChangeAttributeValues;
Expand All @@ -213,18 +213,19 @@ QgsAttributeTableDialog::QgsAttributeTableDialog( QgsVectorLayer *theLayer, QWid
bool canDeleteAttributes = mLayer->dataProvider()->capabilities() & QgsVectorDataProvider::DeleteAttributes;
bool canAddFeatures = mLayer->dataProvider()->capabilities() & QgsVectorDataProvider::AddFeatures;

mToggleEditingButton->blockSignals( true );
mToggleEditingButton->setCheckable( true );
mToggleEditingButton->setChecked( mLayer->isEditable() );
mToggleEditingButton->setEnabled(( canChangeAttributes || canDeleteFeatures || canAddAttributes || canDeleteAttributes || canAddFeatures ) && !mLayer->readOnly() );
mToggleEditingButton->blockSignals( false );
mActionToggleEditing->blockSignals( true );
mActionToggleEditing->setCheckable( true );
mActionToggleEditing->setChecked( mLayer->isEditable() );
mActionToggleEditing->setEnabled(( canChangeAttributes || canDeleteFeatures || canAddAttributes || canDeleteAttributes || canAddFeatures ) && !mLayer->readOnly() );
mActionToggleEditing->blockSignals( false );

mSaveEditsButton->setEnabled( mToggleEditingButton->isEnabled() && mLayer->isEditable() );
mReloadButton->setEnabled( ! mLayer->isEditable() );
mAddAttribute->setEnabled(( canChangeAttributes || canAddAttributes ) && mLayer->isEditable() );
mDeleteSelectedButton->setEnabled( canDeleteFeatures && mLayer->isEditable() );
mAddFeature->setEnabled( canAddFeatures && mLayer->isEditable() );
mAddFeature->setHidden( !canAddFeatures );
mActionSaveEdits->setEnabled( mActionToggleEditing->isEnabled() && mLayer->isEditable() );
mActionReload->setEnabled( ! mLayer->isEditable() );
mActionAddAttribute->setEnabled(( canChangeAttributes || canAddAttributes ) && mLayer->isEditable() );
mActionDeleteSelected->setEnabled( canDeleteFeatures && mLayer->isEditable() );
mActionAddFeature->setEnabled( canAddFeatures && mLayer->isEditable() );
if ( !canAddFeatures )
mToolbar->removeAction( mActionAddFeature );

mMainViewButtonGroup->setId( mTableViewButton, QgsDualView::AttributeTable );
mMainViewButtonGroup->setId( mAttributeViewButton, QgsDualView::AttributeEditor );
Expand Down Expand Up @@ -268,17 +269,17 @@ QgsAttributeTableDialog::QgsAttributeTableDialog( QgsVectorLayer *theLayer, QWid
mMainView->setView( static_cast< QgsDualView::ViewMode >( initialView ) );
mMainViewButtonGroup->button( initialView )->setChecked( true );

connect( mToggleMultiEditButton, SIGNAL( toggled( bool ) ), mMainView, SLOT( setMultiEditEnabled( bool ) ) );
connect( mSearchFormButton, SIGNAL( toggled( bool ) ), mMainView, SLOT( toggleSearchMode( bool ) ) );
connect( mActionToggleMultiEdit, SIGNAL( toggled( bool ) ), mMainView, SLOT( setMultiEditEnabled( bool ) ) );
connect( mActionSearchForm, SIGNAL( toggled( bool ) ), mMainView, SLOT( toggleSearchMode( bool ) ) );
updateMultiEditButtonState();

if ( mLayer->editFormConfig()->layout() == QgsEditFormConfig::UiFileLayout )
{
//not supported with custom UI
mToggleMultiEditButton->setEnabled( false );
mToggleMultiEditButton->setToolTip( tr( "Multiedit is not supported when using custom UI forms" ) );
mSearchFormButton->setEnabled( false );
mSearchFormButton->setToolTip( tr( "Search is not supported when using custom UI forms" ) );
mActionToggleMultiEdit->setEnabled( false );
mActionToggleMultiEdit->setToolTip( tr( "Multiedit is not supported when using custom UI forms" ) );
mActionSearchForm->setEnabled( false );
mActionSearchForm->setToolTip( tr( "Search is not supported when using custom UI forms" ) );
}

editingToggled();
Expand Down Expand Up @@ -331,7 +332,7 @@ void QgsAttributeTableDialog::keyPressEvent( QKeyEvent* event )
{
QDialog::keyPressEvent( event );

if (( event->key() == Qt::Key_Backspace || event->key() == Qt::Key_Delete ) && mDeleteSelectedButton->isEnabled() )
if (( event->key() == Qt::Key_Backspace || event->key() == Qt::Key_Delete ) && mActionDeleteSelected->isEnabled() )
{
QgisApp::instance()->deleteSelected( mLayer, this );
}
Expand Down Expand Up @@ -396,7 +397,7 @@ void QgsAttributeTableDialog::updateFieldFromExpressionSelected()
void QgsAttributeTableDialog::viewModeChanged( QgsAttributeForm::Mode mode )
{
if ( mode != QgsAttributeForm::SearchMode )
mSearchFormButton->setChecked( false );
mActionSearchForm->setChecked( false );
}

void QgsAttributeTableDialog::formFilterSet( const QString& filter, QgsAttributeForm::FilterType type )
Expand Down Expand Up @@ -590,9 +591,9 @@ void QgsAttributeTableDialog::filterEdited()
mMainView->setFilterMode( QgsAttributeTableFilterModel::ShowEdited );
}

void QgsAttributeTableDialog::on_mSelectedToTopButton_toggled()
void QgsAttributeTableDialog::on_mActionSelectedToTop_toggled( bool checked )
{
if ( mSelectedToTopButton->isChecked() )
if ( checked )
{
mMainView->setSelectedOnTop( true );
}
Expand All @@ -602,7 +603,7 @@ void QgsAttributeTableDialog::on_mSelectedToTopButton_toggled()
}
}

void QgsAttributeTableDialog::on_mOpenFieldCalculator_clicked()
void QgsAttributeTableDialog::on_mActionOpenFieldCalculator_triggered()
{
QgsAttributeTableModel* masterModel = mMainView->masterModel();

Expand All @@ -618,17 +619,17 @@ void QgsAttributeTableDialog::on_mOpenFieldCalculator_clicked()
}
}

void QgsAttributeTableDialog::on_mSaveEditsButton_clicked()
void QgsAttributeTableDialog::on_mActionSaveEdits_triggered()
{
QgisApp::instance()->saveEdits( mLayer, true, true );
}

void QgsAttributeTableDialog::on_mReloadButton_clicked()
void QgsAttributeTableDialog::on_mActionReload_triggered()
{
mMainView->masterModel()->layer()->dataProvider()->forceReload();
}

void QgsAttributeTableDialog::on_mAddFeature_clicked()
void QgsAttributeTableDialog::on_mActionAddFeature_triggered()
{
if ( !mLayer->isEditable() )
return;
Expand All @@ -643,50 +644,50 @@ void QgsAttributeTableDialog::on_mAddFeature_clicked()
}
}

void QgsAttributeTableDialog::on_mExpressionSelectButton_clicked()
void QgsAttributeTableDialog::on_mActionExpressionSelect_triggered()
{
QgsExpressionSelectionDialog* dlg = new QgsExpressionSelectionDialog( mLayer );
dlg->setAttribute( Qt::WA_DeleteOnClose );
dlg->show();
}

void QgsAttributeTableDialog::on_mCopySelectedRowsButton_clicked()
void QgsAttributeTableDialog::on_mActionCopySelectedRows_triggered()
{
QgisApp::instance()->editCopy( mLayer );
}

void QgsAttributeTableDialog::on_mPasteFeatures_clicked()
void QgsAttributeTableDialog::on_mActionPasteFeatures_triggered()
{
QgisApp::instance()->editPaste( mLayer );
}


void QgsAttributeTableDialog::on_mZoomMapToSelectedRowsButton_clicked()
void QgsAttributeTableDialog::on_mActionZoomMapToSelectedRows_triggered()
{
QgisApp::instance()->mapCanvas()->zoomToSelected( mLayer );
}

void QgsAttributeTableDialog::on_mPanMapToSelectedRowsButton_clicked()
void QgsAttributeTableDialog::on_mActionPanMapToSelectedRows_triggered()
{
QgisApp::instance()->mapCanvas()->panToSelected( mLayer );
}

void QgsAttributeTableDialog::on_mInvertSelectionButton_clicked()
void QgsAttributeTableDialog::on_mActionInvertSelection_triggered()
{
mLayer->invertSelection();
}

void QgsAttributeTableDialog::on_mRemoveSelectionButton_clicked()
void QgsAttributeTableDialog::on_mActionRemoveSelection_triggered()
{
mLayer->removeSelection();
}

void QgsAttributeTableDialog::on_mSelectAllButton_clicked()
void QgsAttributeTableDialog::on_mActionSelectAll_triggered()
{
mLayer->selectAll();
}

void QgsAttributeTableDialog::on_mDeleteSelectedButton_clicked()
void QgsAttributeTableDialog::on_mActionDeleteSelected_triggered()
{
QgisApp::instance()->deleteSelected( mLayer, this );
}
Expand All @@ -697,13 +698,13 @@ void QgsAttributeTableDialog::on_mMainView_currentChanged( int viewMode )
updateMultiEditButtonState();

if ( viewMode == 0 )
mSearchFormButton->setChecked( false );
mActionSearchForm->setChecked( false );

QSettings s;
s.setValue( "/qgis/attributeTableLastView", static_cast< int >( viewMode ) );
}

void QgsAttributeTableDialog::on_mToggleEditingButton_toggled()
void QgsAttributeTableDialog::on_mActionToggleEditing_toggled( bool )
{
if ( !mLayer )
return;
Expand All @@ -716,24 +717,24 @@ void QgsAttributeTableDialog::on_mToggleEditingButton_toggled()

void QgsAttributeTableDialog::editingToggled()
{
mToggleEditingButton->blockSignals( true );
mToggleEditingButton->setChecked( mLayer->isEditable() );
mSaveEditsButton->setEnabled( mLayer->isEditable() );
mReloadButton->setEnabled( ! mLayer->isEditable() );
mActionToggleEditing->blockSignals( true );
mActionToggleEditing->setChecked( mLayer->isEditable() );
mActionSaveEdits->setEnabled( mLayer->isEditable() );
mActionReload->setEnabled( ! mLayer->isEditable() );
updateMultiEditButtonState();
if ( mLayer->isEditable() )
{
mSearchFormButton->setChecked( false );
mActionSearchForm->setChecked( false );
}
mToggleEditingButton->blockSignals( false );
mActionToggleEditing->blockSignals( false );

bool canChangeAttributes = mLayer->dataProvider()->capabilities() & QgsVectorDataProvider::ChangeAttributeValues;
bool canDeleteFeatures = mLayer->dataProvider()->capabilities() & QgsVectorDataProvider::DeleteFeatures;
bool canAddAttributes = mLayer->dataProvider()->capabilities() & QgsVectorDataProvider::AddAttributes;
bool canAddFeatures = mLayer->dataProvider()->capabilities() & QgsVectorDataProvider::AddFeatures;
mAddAttribute->setEnabled(( canChangeAttributes || canAddAttributes ) && mLayer->isEditable() );
mDeleteSelectedButton->setEnabled( canDeleteFeatures && mLayer->isEditable() );
mAddFeature->setEnabled( canAddFeatures && mLayer->isEditable() );
mActionAddAttribute->setEnabled(( canChangeAttributes || canAddAttributes ) && mLayer->isEditable() );
mActionDeleteSelected->setEnabled( canDeleteFeatures && mLayer->isEditable() );
mActionAddFeature->setEnabled( canAddFeatures && mLayer->isEditable() );

mUpdateExpressionBox->setVisible( mLayer->isEditable() );
if ( mLayer->isEditable() && mFieldCombo->currentIndex() == -1 )
Expand All @@ -744,7 +745,7 @@ void QgsAttributeTableDialog::editingToggled()
// because model always reflects actual state when returning item flags
}

void QgsAttributeTableDialog::on_mAddAttribute_clicked()
void QgsAttributeTableDialog::on_mActionAddAttribute_triggered()
{
if ( !mLayer )
{
Expand Down Expand Up @@ -774,7 +775,7 @@ void QgsAttributeTableDialog::on_mAddAttribute_clicked()
}
}

void QgsAttributeTableDialog::on_mRemoveAttribute_clicked()
void QgsAttributeTableDialog::on_mActionRemoveAttribute_triggered()
{
if ( !mLayer )
{
Expand Down
Loading

0 comments on commit 33d64dc

Please sign in to comment.