Skip to content

Commit

Permalink
[FIX #7508] drag'n'drop form generator wrong creation of group container
Browse files Browse the repository at this point in the history
  • Loading branch information
m-kuhn committed Apr 12, 2013
1 parent a290fa2 commit 5432618
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 27 deletions.
29 changes: 16 additions & 13 deletions src/app/qgsaddtaborgroup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,26 @@
#include "qgsvectorlayer.h"
#include "qgsaddtaborgroup.h"

#include <QTreeWidgetItem>
#include <QComboBox>

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

mTabButton->setChecked( true );
mTabList->setEnabled( false );
if ( tabList.size() > 0 )
if ( mTabs.size() > 0 )
{
for ( QList<QString>::iterator tab = tabList.begin(); tab != tabList.end(); tab++ )
mTabList->addItem( *tab );
int i = 0;
foreach ( TabPair tab, mTabs )
{
mTabList->addItem( tab.first, i );
++i;
}
}
else
{
Expand All @@ -48,7 +50,7 @@ QgsAddTabOrGroup::QgsAddTabOrGroup(
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() ) );
setWindowTitle( tr( "Add tab or group for %1" ).arg( mLayer->name() ) );
} // QgsVectorLayerProperties ctor

QgsAddTabOrGroup::~QgsAddTabOrGroup()
Expand All @@ -60,9 +62,10 @@ QString QgsAddTabOrGroup::name()
return mName->text();
}

int QgsAddTabOrGroup::tabId()
QTreeWidgetItem* QgsAddTabOrGroup::tab()
{
return mTabList->currentIndex();
TabPair tab = mTabs.at( mTabList->itemData( mTabList->currentIndex() ).toInt() );
return tab.second;
}

bool QgsAddTabOrGroup::tabButtonIsChecked()
Expand Down
11 changes: 8 additions & 3 deletions src/app/qgsaddtaborgroup.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,23 @@
#include "ui_qgsaddtaborgroupbase.h"
#include "qgisgui.h"

class QTreeWidgetItem;
class QgsVectorLayer;

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

public:
QgsAddTabOrGroup( QgsVectorLayer *lyr = 0, QWidget *parent = 0, QList<QString> tabList = QList<QString>() );
typedef QPair<QString,QTreeWidgetItem*> TabPair;

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

QString name();

int tabId();
QTreeWidgetItem* tab();

bool tabButtonIsChecked();

Expand All @@ -43,7 +47,8 @@ class QgsAddTabOrGroup : public QDialog, private Ui::QgsAddTabOrGroupBase
void on_mTabButton_toggled( bool checked );

protected:
QgsVectorLayer *layer;
QgsVectorLayer *mLayer;
QList< TabPair > mTabs;
};

#endif
21 changes: 10 additions & 11 deletions src/app/qgsfieldsproperties.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -356,17 +356,17 @@ void QgsFieldsProperties::on_mAddItemButton_clicked()

void QgsFieldsProperties::on_mAddTabOrGroupButton_clicked()
{
QList<QString> tabList;
QList<QTreeWidgetItem*> tabWidgetList;
QTreeWidgetItemIterator it( mAttributesTree );
while ( *it )
QList<QgsAddTabOrGroup::TabPair> tabList;


for( QTreeWidgetItemIterator it( mAttributesTree ); *it; ++it )
{
if (( *it )->data( 0 , Qt::UserRole ) == "container" )
tabList.append(( *it )->text( 0 ) );
tabWidgetList.append( *it );
++it;
if ( ( *it )->data( 0 , Qt::UserRole ) == "container" )
{
tabList.append( QgsAddTabOrGroup::TabPair( (*it)->text( 0 ), *it ) );
}
}
QgsAddTabOrGroup addTabOrGroup( mLayer , this, tabList );
QgsAddTabOrGroup addTabOrGroup( mLayer, tabList, this );

if ( !addTabOrGroup.exec() )
return;
Expand All @@ -378,8 +378,7 @@ void QgsFieldsProperties::on_mAddTabOrGroupButton_clicked()
}
else
{
int tabId = addTabOrGroup.tabId();
QTreeWidgetItem* tabItem = tabWidgetList[tabId];
QTreeWidgetItem* tabItem = addTabOrGroup.tab();
mAttributesTree->addContainer( tabItem , name );
}
}
Expand Down

0 comments on commit 5432618

Please sign in to comment.