Skip to content
Permalink
Browse files

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 9ffca57e2f066d21073cb3f42e18bf9589d02206
@@ -44,4 +44,5 @@ scripts/RelWithDebInfo
qgis-test.ctest
i18n/*.qm
.project
.idea
.pydevproject
.idea
@@ -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>
@@ -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>
@@ -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>
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -5,6 +5,7 @@ SET(QGIS_APP_SRCS
qgsabout.cpp
qgssponsors.cpp
qgsaddattrdialog.cpp
qgsaddtaborgroup.cpp
qgsaddjoindialog.cpp
qgsannotationwidget.cpp
qgsattributeactiondialog.cpp
@@ -34,6 +35,7 @@ SET(QGIS_APP_SRCS
qgsdiagramproperties.cpp
qgsdisplayangle.cpp
qgsfieldcalculator.cpp
qgsfieldsproperties.cpp
qgsgraduatedsymboldialog.cpp
qgsidentifyresults.cpp
qgsfeatureaction.cpp
@@ -165,6 +167,7 @@ SET (QGIS_APP_MOC_HDRS
qgsabout.h
qgsaddattrdialog.h
qgsaddjoindialog.h
qgsaddtaborgroup.h
qgsannotationwidget.h
qgsattributeactiondialog.h
qgsattributedialog.h
@@ -191,6 +194,7 @@ SET (QGIS_APP_MOC_HDRS
qgsdisplayangle.h
qgsfeatureaction.h
qgsfieldcalculator.h
qgsfieldsproperties.h
qgsformannotationdialog.h
qgshtmlannotationdialog.h
qgsgraduatedsymboldialog.h
@@ -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 );
}
@@ -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
@@ -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() );

@@ -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 )
{
@@ -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;

@@ -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*>() )
@@ -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;
}
}

@@ -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;

0 comments on commit 9ffca57

Please sign in to comment.
You can’t perform that action at this time.