Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
dxf improvements:
* save/restore dxf export dialog geometry
* reduce debugging noise
* output dxf in windows-1252 encoding
* fix label layer assignment
  • Loading branch information
jef-n committed Sep 26, 2014
1 parent 2f4489d commit bfb7569
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 78 deletions.
79 changes: 37 additions & 42 deletions src/app/qgsdxfexportdialog.cpp
Expand Up @@ -40,7 +40,7 @@ QWidget *FieldSelectorDelegate::createEditor( QWidget *parent, const QStyleOptio
Q_UNUSED( option );

QgsVectorLayer *vl = qobject_cast<QgsVectorLayer *>( reinterpret_cast<QObject*>( index.internalPointer() ) );
if( !vl )
if ( !vl )
return 0;

QgsFieldComboBox *w = new QgsFieldComboBox( parent );
Expand All @@ -52,39 +52,39 @@ void FieldSelectorDelegate::setEditorData( QWidget *editor, const QModelIndex &i
{
QgsDebugCall;
QgsVectorLayer *vl = qobject_cast<QgsVectorLayer *>( reinterpret_cast<QObject*>( index.internalPointer() ) );
if( !vl )
if ( !vl )
return;

const QgsVectorLayerAndAttributeModel *model = dynamic_cast< const QgsVectorLayerAndAttributeModel *>( index.model() );
if( !model )
if ( !model )
return;

QgsFieldComboBox *fcb = qobject_cast<QgsFieldComboBox *>( editor );
if( !fcb )
if ( !fcb )
return;

int idx = model->mAttributeIdx.value( vl, -1 );
if( vl->pendingFields().exists( idx ) )
if ( vl->pendingFields().exists( idx ) )
fcb->setField( vl->pendingFields()[ idx ].name() );
}

void FieldSelectorDelegate::setModelData( QWidget *editor, QAbstractItemModel *model, const QModelIndex &index ) const
{
QgsDebugCall;
QgsVectorLayer *vl = qobject_cast<QgsVectorLayer *>( reinterpret_cast<QObject*>( index.internalPointer() ) );
if( !vl )
if ( !vl )
return;

QgsFieldComboBox *fcb = qobject_cast<QgsFieldComboBox *>( editor );
if( !fcb )
if ( !fcb )
return;

model->setData( index, vl->fieldNameIndex( fcb->currentField() ) );
}
#endif

QgsVectorLayerAndAttributeModel::QgsVectorLayerAndAttributeModel( QgsLayerTreeGroup* rootNode, QObject *parent )
: QgsLayerTreeModel( rootNode, parent )
: QgsLayerTreeModel( rootNode, parent )
{
}

Expand All @@ -95,10 +95,10 @@ QgsVectorLayerAndAttributeModel::~QgsVectorLayerAndAttributeModel()
QModelIndex QgsVectorLayerAndAttributeModel::index( int row, int column, const QModelIndex &parent ) const
{
QgsLayerTreeNode *n = index2node( parent );
if( !QgsLayerTree::isLayer( n ) )
if ( !QgsLayerTree::isLayer( n ) )
return QgsLayerTreeModel::index( row, column, parent );

if( row != 0 || column != 0 )
if ( row != 0 || column != 0 )
return QModelIndex();

return createIndex( 0, 0, QgsLayerTree::toLayer( n )->layer() );
Expand All @@ -107,7 +107,7 @@ QModelIndex QgsVectorLayerAndAttributeModel::index( int row, int column, const Q
QModelIndex QgsVectorLayerAndAttributeModel::parent( const QModelIndex &child ) const
{
QgsVectorLayer *vl = qobject_cast<QgsVectorLayer *>( reinterpret_cast<QObject*>( child.internalPointer() ) );
if( !vl )
if ( !vl )
return QgsLayerTreeModel::parent( child );

QgsLayerTreeLayer *layer = rootGroup()->findLayer( vl->id() );
Expand All @@ -124,11 +124,11 @@ QModelIndex QgsVectorLayerAndAttributeModel::parent( const QModelIndex &child )
int QgsVectorLayerAndAttributeModel::rowCount( const QModelIndex &index ) const
{
QgsVectorLayer *vl = qobject_cast<QgsVectorLayer *>( reinterpret_cast<QObject*>( index.internalPointer() ) );
if( vl )
if ( vl )
return 0;

QgsLayerTreeNode *n = index2node( index );
if( QgsLayerTree::isLayer( n ) )
if ( QgsLayerTree::isLayer( n ) )
return 1;

return QgsLayerTreeModel::rowCount( index );
Expand All @@ -137,7 +137,7 @@ int QgsVectorLayerAndAttributeModel::rowCount( const QModelIndex &index ) const
Qt::ItemFlags QgsVectorLayerAndAttributeModel::flags( const QModelIndex &index ) const
{
QgsVectorLayer *vl = qobject_cast<QgsVectorLayer *>( reinterpret_cast<QObject*>( index.internalPointer() ) );
if( !vl )
if ( !vl )
return QgsLayerTreeModel::flags( index );

return Qt::ItemIsEnabled /* | Qt::ItemIsEditable */;
Expand All @@ -147,17 +147,17 @@ Qt::ItemFlags QgsVectorLayerAndAttributeModel::flags( const QModelIndex &index )
QVariant QgsVectorLayerAndAttributeModel::data( const QModelIndex& index, int role ) const
{
QgsVectorLayer *vl = qobject_cast<QgsVectorLayer *>( reinterpret_cast<QObject*>( index.internalPointer() ) );
if( !vl )
if ( !vl )
return QgsLayerTreeModel::data( index, role );

int idx = mAttributeIdx.value( vl, -1 );
if( role == Qt::EditRole )
if ( role == Qt::EditRole )
return idx;

if( role != Qt::DisplayRole )
if ( role != Qt::DisplayRole )
return QVariant();

if( vl->pendingFields().exists( idx ) )
if ( vl->pendingFields().exists( idx ) )
return vl->pendingFields()[ idx ].name();

return vl->name();
Expand All @@ -166,11 +166,11 @@ QVariant QgsVectorLayerAndAttributeModel::data( const QModelIndex& index, int ro

bool QgsVectorLayerAndAttributeModel::setData( const QModelIndex &index, const QVariant &value, int role )
{
if( role != Qt::EditRole )
if ( role != Qt::EditRole )
return false;

QgsVectorLayer *vl = qobject_cast<QgsVectorLayer *>( reinterpret_cast<QObject*>( index.internalPointer() ) );
if( !vl )
if ( !vl )
return QgsLayerTreeModel::setData( index, value, role );

mAttributeIdx[ vl ] = value.toInt();
Expand All @@ -182,23 +182,23 @@ QList< QPair<QgsVectorLayer *, int> > QgsVectorLayerAndAttributeModel::layers( c
{
QList< QPair<QgsVectorLayer *, int> > layers;

foreach( const QModelIndex &idx, selectedIndexes )
foreach ( const QModelIndex &idx, selectedIndexes )
{
QgsLayerTreeNode *node = index2node( idx );
if( QgsLayerTree::isGroup( node ) )
if ( QgsLayerTree::isGroup( node ) )
{
foreach( QgsLayerTreeLayer *treeLayer, QgsLayerTree::toGroup( node )->findLayers() )
foreach ( QgsLayerTreeLayer *treeLayer, QgsLayerTree::toGroup( node )->findLayers() )
{
QgsVectorLayer *vl = qobject_cast<QgsVectorLayer *>( treeLayer->layer() );
Q_ASSERT( vl );
Q_ASSERT( vl );
layers << qMakePair<QgsVectorLayer *, int>( vl, mAttributeIdx.value( vl, -1 ) );
}
}
else if( QgsLayerTree::isLayer( node ) )
else if ( QgsLayerTree::isLayer( node ) )
{
QgsVectorLayer *vl = qobject_cast< QgsVectorLayer *>( QgsLayerTree::toLayer( node )->layer() );
Q_ASSERT( vl );
layers << qMakePair<QgsVectorLayer *, int>( vl,mAttributeIdx.value( vl, -1 ) );
layers << qMakePair<QgsVectorLayer *, int>( vl, mAttributeIdx.value( vl, -1 ) );
}
}

Expand Down Expand Up @@ -235,6 +235,8 @@ QgsDxfExportDialog::QgsDxfExportDialog( QWidget* parent, Qt::WindowFlags f ): QD
#endif

buttonBox->button( QDialogButtonBox::Ok )->setEnabled( false );

restoreGeometry( s.value( "/Windows/DxfExport/geometry" ).toByteArray() );
}

QgsDxfExportDialog::~QgsDxfExportDialog()
Expand All @@ -243,15 +245,16 @@ QgsDxfExportDialog::~QgsDxfExportDialog()
#if 0
delete mFieldSelectorDelegate;
#endif

QSettings().setValue( "/Windows/DxfExport/geometry", saveGeometry() );
}

void QgsDxfExportDialog::on_mTreeView_clicked( const QModelIndex & current )
{
QgsDebugCall;
QgsVectorLayer *vl = qobject_cast<QgsVectorLayer *>( reinterpret_cast<QObject*>( current.internalPointer() ) );
if( !vl )
if ( !vl )
{
QgsDebugMsg( "No vector layer" );
mLayerAttributeComboBox->setDisabled( true );
return;
}
Expand All @@ -261,7 +264,7 @@ void QgsDxfExportDialog::on_mTreeView_clicked( const QModelIndex & current )
int idx = mTreeView->model()->data( current, Qt::EditRole ).toInt();

mLayerAttributeComboBox->setLayer( vl );
if( vl->pendingFields().exists( idx ) )
if ( vl->pendingFields().exists( idx ) )
mLayerAttributeComboBox->setField( vl->pendingFields()[ idx ].name() );
}

Expand All @@ -274,25 +277,25 @@ void QgsDxfExportDialog::on_mLayerAttributeComboBox_fieldChanged( QString fieldN
void QgsDxfExportDialog::cleanGroup( QgsLayerTreeNode *node )
{
QgsLayerTreeGroup *group = QgsLayerTree::toGroup( node );
if( !group )
if ( !group )
return;

QList<QgsLayerTreeNode *> toRemove;
foreach( QgsLayerTreeNode *child, node->children() )
foreach ( QgsLayerTreeNode *child, node->children() )
{
if( QgsLayerTree::isLayer( child ) && QgsLayerTree::toLayer( child )->layer()->type() != QgsMapLayer::VectorLayer )
if ( QgsLayerTree::isLayer( child ) && QgsLayerTree::toLayer( child )->layer()->type() != QgsMapLayer::VectorLayer )
{
toRemove << child;
continue;
}

cleanGroup( child );

if( QgsLayerTree::isGroup( child ) && child->children().isEmpty() )
if ( QgsLayerTree::isGroup( child ) && child->children().isEmpty() )
toRemove << child;
}

foreach( QgsLayerTreeNode *child, toRemove )
foreach ( QgsLayerTreeNode *child, toRemove )
group->removeChildNode( child );
}

Expand Down Expand Up @@ -348,14 +351,6 @@ void QgsDxfExportDialog::on_mFileSelectionButton_clicked()

void QgsDxfExportDialog::setOkEnabled()
{
QModelIndex idx = mTreeView->currentIndex();
QgsDebugMsg( QString( "current index:%1" ).arg( idx.isValid() ) );
while( idx.isValid() )
{
QgsDebugMsg( QString( " row=%1 column=%2" ).arg( idx.row() ).arg( idx.column() ) );
idx = idx.parent();
}

QPushButton* btn = buttonBox->button( QDialogButtonBox::Ok );

QString filePath = mFileLineEdit->text();
Expand Down
6 changes: 3 additions & 3 deletions src/app/qgsdxfexportdialog.h
Expand Up @@ -31,11 +31,11 @@ class QgsLayerTreeNode;
#if 0
#include <QItemDelegate>
class FieldSelectorDelegate : public QItemDelegate
{
{
Q_OBJECT
public:
FieldSelectorDelegate( QObject *parent = 0 );

QWidget *createEditor( QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index ) const;
void setEditorData( QWidget *editor, const QModelIndex &index ) const;
void setModelData( QWidget *editor, QAbstractItemModel *model, const QModelIndex &index ) const;
Expand All @@ -51,7 +51,7 @@ class QgsVectorLayerAndAttributeModel : public QgsLayerTreeModel

QModelIndex index( int row, int column, const QModelIndex &parent ) const;
QModelIndex parent( const QModelIndex &child ) const;
int rowCount( const QModelIndex &index ) const;
int rowCount( const QModelIndex &index ) const;
Qt::ItemFlags flags( const QModelIndex &index ) const;
QVariant data( const QModelIndex& index, int role ) const;
bool setData( const QModelIndex &index, const QVariant &value, int role = Qt::EditRole );
Expand Down
6 changes: 3 additions & 3 deletions src/app/qgsprojectlayergroupdialog.cpp
Expand Up @@ -28,9 +28,9 @@
#include <QSettings>

QgsProjectLayerGroupDialog::QgsProjectLayerGroupDialog( QWidget * parent, const QString& projectFile, Qt::WindowFlags f )
: QDialog( parent, f )
, mShowEmbeddedContent( false )
, mRootGroup( new QgsLayerTreeGroup )
: QDialog( parent, f )
, mShowEmbeddedContent( false )
, mRootGroup( new QgsLayerTreeGroup )
{
setupUi( this );

Expand Down

0 comments on commit bfb7569

Please sign in to comment.