Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merged Squashed pull request #296 (tabs and groups for feature form)
  • Loading branch information
m-kuhn authored and jef-n committed Nov 4, 2012
1 parent 67dd499 commit 9ffca57
Show file tree
Hide file tree
Showing 23 changed files with 2,171 additions and 641 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Expand Up @@ -44,4 +44,5 @@ scripts/RelWithDebInfo
qgis-test.ctest
i18n/*.qm
.project
.idea
.pydevproject
.idea
6 changes: 5 additions & 1 deletion images/images.qrc
Expand Up @@ -46,6 +46,8 @@
<file>themes/default/mActionAnnotation.png</file>
<file>themes/default/mActionArrowDown.png</file>
<file>themes/default/mActionArrowUp.png</file>
<file>themes/default/mActionArrowLeft.png</file>
<file>themes/default/mActionArrowRight.png</file>
<file>themes/default/mActionCalculateField.png</file>
<file>themes/default/mActionCaptureLine.png</file>
<file>themes/default/mActionCapturePoint.png</file>
Expand Down Expand Up @@ -151,6 +153,8 @@
<file>themes/default/mActionSelectPolygon.svg</file>
<file>themes/default/mActionSelectRadius.png</file>
<file>themes/default/mActionSelectRectangle.png</file>
<file>themes/default/mActionSignPlus.png</file>
<file>themes/default/mActionSignMinus.png</file>
<file>themes/default/mActionShowAllLayers.png</file>
<file>themes/default/mActionShowBookmarks.png</file>
<file>themes/default/mActionShowHideLabels.svg</file>
Expand All @@ -175,7 +179,7 @@
<file>themes/default/mIconClose.png</file>
<file>themes/default/mIconCollapse.png</file>
<file>themes/default/mIconConnect.png</file>
<file>themes/default/mIconClear.png</file>
<file>themes/default/mIconClear.png</file>
<file>themes/default/mIconDbSchema.png</file>
<file>themes/default/mIconDelete.png</file>
<file>themes/default/mIconEditable.png</file>
Expand Down
Binary file added images/themes/default/mActionArrowLeft.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/themes/default/mActionArrowRight.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/themes/default/mActionSignMinus.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/themes/default/mActionSignPlus.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions src/app/CMakeLists.txt
Expand Up @@ -5,6 +5,7 @@ SET(QGIS_APP_SRCS
qgsabout.cpp
qgssponsors.cpp
qgsaddattrdialog.cpp
qgsaddtaborgroup.cpp
qgsaddjoindialog.cpp
qgsannotationwidget.cpp
qgsattributeactiondialog.cpp
Expand Down Expand Up @@ -34,6 +35,7 @@ SET(QGIS_APP_SRCS
qgsdiagramproperties.cpp
qgsdisplayangle.cpp
qgsfieldcalculator.cpp
qgsfieldsproperties.cpp
qgsgraduatedsymboldialog.cpp
qgsidentifyresults.cpp
qgsfeatureaction.cpp
Expand Down Expand Up @@ -165,6 +167,7 @@ SET (QGIS_APP_MOC_HDRS
qgsabout.h
qgsaddattrdialog.h
qgsaddjoindialog.h
qgsaddtaborgroup.h
qgsannotationwidget.h
qgsattributeactiondialog.h
qgsattributedialog.h
Expand All @@ -191,6 +194,7 @@ SET (QGIS_APP_MOC_HDRS
qgsdisplayangle.h
qgsfeatureaction.h
qgsfieldcalculator.h
qgsfieldsproperties.h
qgsformannotationdialog.h
qgshtmlannotationdialog.h
qgsgraduatedsymboldialog.h
Expand Down
81 changes: 81 additions & 0 deletions src/app/qgsaddtaborgroup.cpp
@@ -0,0 +1,81 @@
/***************************************************************************
qgsaddtaborgroup.h
Add a tab or a group for the tab and group display of fields
-------------------
begin : 2012-07-30
copyright : (C) 2012 by Denis Rouzaud
email : denis dot rouzaud at gmail dot com
***************************************************************************/

/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

#include "qgisapp.h"
#include "qgsapplication.h"
#include "qgsvectorlayer.h"
#include "qgsaddtaborgroup.h"

#include <QComboBox>

QgsAddTabOrGroup::QgsAddTabOrGroup(
QgsVectorLayer *lyr,
QWidget * parent,
QList<QString> tabList
)
: QDialog( parent )
, layer( lyr )
{
setupUi( this );

mTabButton->setChecked( true );
mTabList->setEnabled( false );
if ( tabList.size() > 0 )
{
for ( QList<QString>::iterator tab = tabList.begin(); tab != tabList.end(); tab++ )
mTabList->addItem( *tab );
}
else
{
mGroupButton->setEnabled( false );
}

connect( mTabButton, SIGNAL( toggled( bool ) ), this, SLOT( on_mTabButton_toggled( bool ) ) );
connect( mGroupButton, SIGNAL( toggled( bool ) ), this, SLOT( on_mGroupButton_toggled( bool ) ) );

setWindowTitle( tr( "Add tab or group for %1" ).arg( layer->name() ) );
} // QgsVectorLayerProperties ctor

QgsAddTabOrGroup::~QgsAddTabOrGroup()
{
}

QString QgsAddTabOrGroup::name()
{
return mName->text();
}

int QgsAddTabOrGroup::tabId()
{
return mTabList->currentIndex();
}

bool QgsAddTabOrGroup::tabButtonIsChecked()
{
return mTabButton->isChecked();
}

void QgsAddTabOrGroup::on_mGroupButton_toggled( bool checked )
{
mTabList->setEnabled( checked );
}

void QgsAddTabOrGroup::on_mTabButton_toggled( bool checked )
{
mTabList->setEnabled( not checked );
}
49 changes: 49 additions & 0 deletions src/app/qgsaddtaborgroup.h
@@ -0,0 +1,49 @@
/***************************************************************************
qgsaddtaborgroup.h
Add a tab or a group for the tab and group display of fields
-------------------
begin : 2012-07-30
copyright : (C) 2012 by Denis Rouzaud
email : denis dot rouzaud at gmail dot com
***************************************************************************/

/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

#ifndef QGSADDTABORGROUP
#define QGSADDTABORGROUP

#include "ui_qgsaddtaborgroupbase.h"
#include "qgisgui.h"
#include "qgsrenderer.h"


class QgsAddTabOrGroup : public QDialog, private Ui::QgsAddTabOrGroupBase
{
Q_OBJECT

public:
QgsAddTabOrGroup( QgsVectorLayer *lyr = 0, QWidget *parent = 0, QList<QString> tabList = QList<QString>() );
~QgsAddTabOrGroup();

QString name();

int tabId();

bool tabButtonIsChecked();

public slots:
void on_mGroupButton_toggled( bool checked );
void on_mTabButton_toggled( bool checked );

protected:
QgsVectorLayer *layer;
};

#endif
74 changes: 54 additions & 20 deletions src/app/qgsattributedialog.cpp
Expand Up @@ -65,7 +65,8 @@ QgsAttributeDialog::QgsAttributeDialog( QgsVectorLayer *vl, QgsFeature *thepFeat

QDialogButtonBox *buttonBox = NULL;

if ( !vl->editForm().isEmpty() )
// UI-File defined layout
if ( !vl->editorLayout() == QgsVectorLayer::UiFileLayout && !vl->editForm().isEmpty() )
{
QFile file( vl->editForm() );

Expand All @@ -82,6 +83,43 @@ QgsAttributeDialog::QgsAttributeDialog( QgsVectorLayer *vl, QgsFeature *thepFeat
buttonBox = myWidget->findChild<QDialogButtonBox*>();
}
}
// Tab display
if ( vl->editorLayout() == QgsVectorLayer::TabLayout )
{
mDialog = new QDialog( QgisApp::instance() );

QGridLayout *gridLayout;
QTabWidget *tabWidget;

mDialog->resize( 447, 343 );
gridLayout = new QGridLayout( mDialog );
gridLayout->setObjectName( QString::fromUtf8( "gridLayout" ) );

tabWidget = new QTabWidget( mDialog );
gridLayout->addWidget( tabWidget );

for ( QList<QgsAttributeEditorElement*>::const_iterator tIt = vl->attributeEditorElements().begin(); tIt != vl->attributeEditorElements().end(); ++tIt )
{
QgsAttributeEditorElement* widgDef = *tIt;

QWidget* tabPage = new QWidget( tabWidget );
tabWidget->addTab( tabPage, widgDef->name() );
QGridLayout *tabPageLayout = new QGridLayout( tabPage );

if ( widgDef->type() == QgsAttributeEditorElement::AeTypeContainer )
{
tabPageLayout->addWidget( QgsAttributeEditor::createWidgetFromDef( widgDef, tabPage, vl, myAttributes, mProxyWidgets, false ) );
}
else
{
QgsDebugMsg( "No support for fields in attribute editor on top level" );
}
}

buttonBox = new QDialogButtonBox( mDialog );
buttonBox->setObjectName( QString::fromUtf8( "buttonBox" ) );
gridLayout->addWidget( buttonBox );
}

if ( !mDialog )
{
Expand Down Expand Up @@ -134,7 +172,7 @@ QgsAttributeDialog::QgsAttributeDialog( QgsVectorLayer *vl, QgsFeature *thepFeat
QString myFieldName = vl->attributeDisplayName( it.key() );
int myFieldType = it->type();

QWidget *myWidget = QgsAttributeEditor::createAttributeEditor( 0, 0, vl, it.key(), myAttributes.value( it.key(), QVariant() ) );
QWidget *myWidget = QgsAttributeEditor::createAttributeEditor( 0, 0, vl, it.key(), myAttributes.value( it.key(), QVariant() ), mProxyWidgets );
if ( !myWidget )
continue;

Expand Down Expand Up @@ -164,34 +202,32 @@ QgsAttributeDialog::QgsAttributeDialog( QgsVectorLayer *vl, QgsFeature *thepFeat
}

mypInnerLayout->addWidget( myWidget, index, 1 );
mpIndizes << it.key();
mpWidgets << myWidget;
++index;
}

// Set focus to first widget in list, to help entering data without moving the mouse.
if ( mpWidgets.size() > 0 )
if ( mProxyWidgets.size() > 0 )
{
mpWidgets.first()->setFocus( Qt::OtherFocusReason );
(*mProxyWidgets.begin())->setFocus( Qt::OtherFocusReason );
}
}
else
{
for ( QgsFieldMap::const_iterator it = theFieldMap.begin(); it != theFieldMap.end(); ++it )
{
QWidget *myWidget = mDialog->findChild<QWidget*>( it->name() );
if ( !myWidget )
QList<QWidget *> myWidgets = mDialog->findChildren<QWidget*>( it->name() );
if ( !myWidgets.size() )
continue;

QgsAttributeEditor::createAttributeEditor( mDialog, myWidget, vl, it.key(), myAttributes.value( it.key(), QVariant() ) );

if ( vl->editType( it.key() ) != QgsVectorLayer::Immutable )
for ( QList<QWidget *>::const_iterator itw = myWidgets.begin(); itw != myWidgets.end(); ++itw )
{
myWidget->setEnabled( vl->isEditable() );
}
QgsAttributeEditor::createAttributeEditor( mDialog, *itw, vl, it.key(), myAttributes.value( it.key(), QVariant() ), mProxyWidgets );

mpIndizes << it.key();
mpWidgets << myWidget;
if ( vl->editType( it.key() ) != QgsVectorLayer::Immutable )
{
( *itw )->setEnabled(( *itw )->isEnabled() && vl->isEditable() );
}
}
}

foreach ( QLineEdit *le, mDialog->findChildren<QLineEdit*>() )
Expand Down Expand Up @@ -344,16 +380,14 @@ void QgsAttributeDialog::accept()
return;

//write the new values back to the feature
int myIndex = 0;
for ( QgsFieldMap::const_iterator it = mLayer->pendingFields().begin(); it != mLayer->pendingFields().end(); ++it )
{
int idx = it.key();

QVariant value;

int idx = mpIndizes.value( myIndex );
if ( QgsAttributeEditor::retrieveValue( mpWidgets.value( myIndex ), mLayer, idx, value ) )
if ( QgsAttributeEditor::retrieveValue( mProxyWidgets.value( idx ), mLayer, idx, value ) )
mFeature->changeAttribute( idx, value );

++myIndex;
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/app/qgsattributedialog.h
Expand Up @@ -62,8 +62,8 @@ class QgsAttributeDialog : public QObject

QDialog *mDialog;
QString mSettingsPath;
QList<QWidget *> mpWidgets;
QList<int> mpIndizes;
// Used to sync multiple widgets for the same field
QMap<int, QWidget*> mProxyWidgets;
QgsVectorLayer *mLayer;
QgsFeature *mFeature;
bool mFeatureOwner;
Expand Down

0 comments on commit 9ffca57

Please sign in to comment.