Skip to content

Commit e27d809

Browse files
committedDec 8, 2014
dxf export:
* export layers in reversed rendering order * use checkboxes for layer selection * support for layers selection by visibility preset * improve selection of layer attribute * show busy cursor while exporting * fix duplicate end of entities section
1 parent 4980dba commit e27d809

File tree

9 files changed

+270
-256
lines changed

9 files changed

+270
-256
lines changed
 

‎src/app/qgisapp.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4078,6 +4078,7 @@ void QgisApp::dxfExport()
40784078
if ( !fileName.endsWith( ".dxf", Qt::CaseInsensitive ) )
40794079
fileName += ".dxf";
40804080
QFile dxfFile( fileName );
4081+
QApplication::setOverrideCursor( Qt::BusyCursor );
40814082
if ( dxfExport.writeToFile( &dxfFile ) == 0 )
40824083
{
40834084
messageBar()->pushMessage( tr( "DXF export completed" ), QgsMessageBar::INFO, 4 );
@@ -4086,6 +4087,7 @@ void QgisApp::dxfExport()
40864087
{
40874088
messageBar()->pushMessage( tr( "DXF export failed" ), QgsMessageBar::CRITICAL, 4 );
40884089
}
4090+
QApplication::restoreOverrideCursor();
40894091
}
40904092
}
40914093

‎src/app/qgsdxfexportdialog.cpp

Lines changed: 146 additions & 113 deletions
Large diffs are not rendered by default.

‎src/app/qgsdxfexportdialog.h

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@
2424

2525
#include <QList>
2626
#include <QPair>
27+
#include <QSet>
28+
#include <QItemDelegate>
2729

2830
class QgsLayerTreeGroup;
2931
class QgsLayerTreeNode;
3032

31-
#if 0
32-
#include <QItemDelegate>
3333
class FieldSelectorDelegate : public QItemDelegate
3434
{
3535
Q_OBJECT
@@ -40,7 +40,6 @@ class FieldSelectorDelegate : public QItemDelegate
4040
void setEditorData( QWidget *editor, const QModelIndex &index ) const;
4141
void setModelData( QWidget *editor, QAbstractItemModel *model, const QModelIndex &index ) const;
4242
};
43-
#endif
4443

4544
class QgsVectorLayerAndAttributeModel : public QgsLayerTreeModel
4645
{
@@ -49,21 +48,24 @@ class QgsVectorLayerAndAttributeModel : public QgsLayerTreeModel
4948
QgsVectorLayerAndAttributeModel( QgsLayerTreeGroup* rootNode, QObject *parent = 0 );
5049
~QgsVectorLayerAndAttributeModel();
5150

52-
QModelIndex index( int row, int column, const QModelIndex &parent ) const;
53-
QModelIndex parent( const QModelIndex &child ) const;
54-
int rowCount( const QModelIndex &index ) const;
51+
int columnCount( const QModelIndex &parent = QModelIndex() ) const;
52+
QVariant data( const QModelIndex &index, int role = Qt::DisplayRole ) const;
5553
Qt::ItemFlags flags( const QModelIndex &index ) const;
56-
QVariant data( const QModelIndex& index, int role ) const;
5754
bool setData( const QModelIndex &index, const QVariant &value, int role = Qt::EditRole );
5855

59-
QList< QPair<QgsVectorLayer *, int> > layers( const QModelIndexList &selectedIndexes ) const;
56+
QList< QPair<QgsVectorLayer *, int> > layers() const;
57+
58+
QgsVectorLayer *vectorLayer( const QModelIndex &index ) const;
59+
60+
void applyVisibilityPreset( const QString &name );
6061

6162
private:
6263
QHash<QgsVectorLayer *, int> mAttributeIdx;
64+
QModelIndexList mCheckedIndexes;
65+
66+
void applyVisibility( QSet<QString> &visibleLayers, QgsLayerTreeNode *node );
6367

64-
#if 0
6568
friend FieldSelectorDelegate;
66-
#endif
6769
};
6870

6971

@@ -86,20 +88,16 @@ class QgsDxfExportDialog : public QDialog, private Ui::QgsDxfExportDialogBase
8688
void selectAll();
8789
void unSelectAll();
8890

89-
void on_mTreeView_clicked( const QModelIndex & current );
90-
void on_mLayerAttributeComboBox_fieldChanged( QString );
91-
9291
private slots:
9392
void on_mFileSelectionButton_clicked();
9493
void setOkEnabled();
9594
void saveSettings();
95+
void on_mVisibilityPresets_currentIndexChanged( int index );
9696

9797
private:
9898
void cleanGroup( QgsLayerTreeNode *node );
9999
QgsLayerTreeGroup *mLayerTreeGroup;
100-
#if 0
101100
FieldSelectorDelegate *mFieldSelectorDelegate;
102-
#endif
103101
};
104102

105103
#endif // QGSDXFEXPORTDIALOG_H

‎src/app/qgsrasterlayerproperties.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -702,14 +702,16 @@ void QgsRasterLayerProperties::sync()
702702
// TODO fix legend + palette pixmap
703703

704704
//update the legend pixmap on this dialog
705-
//pixmapLegend->setPixmap( mRasterLayer->legendAsPixmap() );
706-
// pixmapLegend->setScaledContents( true );
707-
// pixmapLegend->repaint();
705+
#if 0
706+
pixmapLegend->setPixmap( mRasterLayer->legendAsPixmap() );
707+
pixmapLegend->setScaledContents( true );
708+
pixmapLegend->repaint();
708709

709710
//set the palette pixmap
710-
// pixmapPalette->setPixmap( mRasterLayer->paletteAsPixmap( mRasterLayer->bandNumber( mRasterLayer->grayBandName() ) ) );
711-
// pixmapPalette->setScaledContents( true );
712-
// pixmapPalette->repaint();
711+
pixmapPalette->setPixmap( mRasterLayer->paletteAsPixmap( mRasterLayer->bandNumber( mRasterLayer->grayBandName() ) ) );
712+
pixmapPalette->setScaledContents( true );
713+
pixmapPalette->repaint();
714+
#endif
713715

714716
QgsDebugMsg( "populate metadata tab" );
715717
/*

‎src/app/qgsvisibilitypresets.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ void QgsVisibilityPresets::applyState( const QString& presetName )
278278

279279
applyStateToLayerTreeGroup( QgsProject::instance()->layerTreeRoot(), mPresets[presetName] );
280280

281-
// also make sure that the preset is up-to-date (not containing any non-existant legend items)
281+
// also make sure that the preset is up-to-date (not containing any non-existent legend items)
282282
if ( mPresets[presetName] == currentState() )
283283
return; // no need for update
284284

‎src/browser/qgsbrowser.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ bool QgsBrowser::layerClicked( QgsLayerItem *item )
214214
if ( !item )
215215
return false;
216216

217-
mActionSetProjection->setEnabled( item->capabilities() & QgsLayerItem::SetCrs );
217+
mActionSetProjection->setEnabled( item->capabilities2().testFlag( QgsLayerItem::SetCrs ) );
218218

219219
QString uri = item->uri();
220220
if ( !uri.isEmpty() )

‎src/core/dxf/qgsdxfexport.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1024,8 +1024,6 @@ void QgsDxfExport::writeEndFile()
10241024
// From GDAL trailer.dxf
10251025
mTextStream << "\
10261026
0\n\
1027-
ENDSEC\n\
1028-
0\n\
10291027
SECTION\n\
10301028
2\n\
10311029
OBJECTS\n\

‎src/core/layertree/qgslayertreemodel.cpp

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -82,17 +82,12 @@ QModelIndex QgsLayerTreeModel::legendNode2index( QgsLayerTreeModelLegendNode* le
8282
int QgsLayerTreeModel::rowCount( const QModelIndex &parent ) const
8383
{
8484
if ( index2legendNode( parent ) )
85-
{
8685
return 0; // they are leaves
87-
}
8886

8987
QgsLayerTreeNode* n = index2node( parent );
9088
if ( !n )
9189
return 0;
9290

93-
if ( parent.isValid() && parent.column() != 0 )
94-
return 0;
95-
9691
if ( QgsLayerTree::isLayer( n ) )
9792
{
9893
if ( !testFlag( ShowLegend ) )
@@ -116,14 +111,13 @@ int QgsLayerTreeModel::columnCount( const QModelIndex &parent ) const
116111

117112
QModelIndex QgsLayerTreeModel::index( int row, int column, const QModelIndex &parent ) const
118113
{
119-
if ( column != 0 || row < 0 || row >= rowCount( parent ) )
114+
if ( column < 0 || column >= columnCount( parent ) ||
115+
row < 0 || row >= rowCount( parent ) )
120116
return QModelIndex();
121117

122-
QgsLayerTreeNode* n = index2node( parent );
118+
QgsLayerTreeNode *n = index2node( parent );
123119
if ( !n )
124-
{
125120
return QModelIndex(); // have no children
126-
}
127121

128122
if ( testFlag( ShowLegend ) && QgsLayerTree::isLayer( n ) )
129123
{
@@ -140,16 +134,18 @@ QModelIndex QgsLayerTreeModel::parent( const QModelIndex &child ) const
140134
if ( !child.isValid() )
141135
return QModelIndex();
142136

143-
QgsLayerTreeNode* parentNode = 0;
144-
QgsLayerTreeNode* n = index2node( child );
137+
QgsLayerTreeNode *parentNode = 0;
138+
QgsLayerTreeNode *n = index2node( child );
145139
if ( !n )
146140
{
147141
QgsLayerTreeModelLegendNode* sym = index2legendNode( child );
148142
Q_ASSERT( sym );
149143
parentNode = sym->layerNode();
150144
}
151145
else
146+
{
152147
parentNode = n->parent(); // must not be null
148+
}
153149

154150
Q_ASSERT( parentNode );
155151

@@ -165,7 +161,7 @@ QModelIndex QgsLayerTreeModel::parent( const QModelIndex &child ) const
165161

166162
QVariant QgsLayerTreeModel::data( const QModelIndex &index, int role ) const
167163
{
168-
if ( !index.isValid() )
164+
if ( !index.isValid() || index.column() > 1 )
169165
return QVariant();
170166

171167
if ( QgsLayerTreeModelLegendNode* sym = index2legendNode( index ) )
@@ -406,6 +402,7 @@ QModelIndex QgsLayerTreeModel::node2index( QgsLayerTreeNode* node ) const
406402
{
407403
if ( !node->parent() )
408404
return QModelIndex(); // this is the only root item -> invalid index
405+
409406
QModelIndex parentIndex = node2index( node->parent() );
410407

411408
int row = node->parent()->children().indexOf( node );
@@ -432,6 +429,7 @@ static bool _isChildOfNodes( QgsLayerTreeNode* child, QList<QgsLayerTreeNode*> n
432429
if ( _isChildOfNode( child, n ) )
433430
return true;
434431
}
432+
435433
return false;
436434
}
437435

@@ -989,7 +987,7 @@ bool QgsLayerTreeModel::dropMimeData( const QMimeData* data, Qt::DropAction acti
989987
if ( !data->hasFormat( "application/qgis.layertreemodeldata" ) )
990988
return false;
991989

992-
if ( column > 0 )
990+
if ( column >= columnCount( parent ) )
993991
return false;
994992

995993
QgsLayerTreeNode* nodeParent = index2node( parent );
@@ -1063,7 +1061,6 @@ bool QgsLayerTreeModel::testFlag( QgsLayerTreeModel::Flag f ) const
10631061
return mFlags.testFlag( f );
10641062
}
10651063

1066-
10671064
const QIcon& QgsLayerTreeModel::iconGroup()
10681065
{
10691066
static QIcon icon;
@@ -1104,6 +1101,9 @@ QList<QgsLayerTreeModelLegendNode*> QgsLayerTreeModel::filterLegendNodes( const
11041101
}
11051102
}
11061103
else
1104+
{
11071105
return nodes;
1106+
}
1107+
11081108
return filtered;
11091109
}

‎src/ui/qgsdxfexportdialogbase.ui

Lines changed: 85 additions & 104 deletions
Original file line numberDiff line numberDiff line change
@@ -7,120 +7,90 @@
77
<x>0</x>
88
<y>0</y>
99
<width>406</width>
10-
<height>319</height>
10+
<height>433</height>
1111
</rect>
1212
</property>
1313
<property name="windowTitle">
1414
<string>DXF export</string>
1515
</property>
1616
<layout class="QGridLayout" name="gridLayout_2">
17-
<item row="4" column="1">
18-
<widget class="QDialogButtonBox" name="buttonBox">
19-
<property name="orientation">
20-
<enum>Qt::Horizontal</enum>
17+
<item row="0" column="2">
18+
<widget class="QToolButton" name="mFileSelectionButton">
19+
<property name="text">
20+
<string>...</string>
2121
</property>
22-
<property name="standardButtons">
23-
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
22+
</widget>
23+
</item>
24+
<item row="4" column="0" colspan="3">
25+
<widget class="QgsLayerTreeView" name="mTreeView">
26+
<property name="selectionMode">
27+
<enum>QAbstractItemView::ExtendedSelection</enum>
2428
</property>
29+
<attribute name="headerDefaultSectionSize">
30+
<number>0</number>
31+
</attribute>
2532
</widget>
2633
</item>
27-
<item row="0" column="0" colspan="3">
28-
<layout class="QGridLayout" name="gridLayout">
29-
<item row="0" column="2">
30-
<widget class="QToolButton" name="mFileSelectionButton">
31-
<property name="text">
32-
<string>...</string>
33-
</property>
34-
</widget>
35-
</item>
36-
<item row="3" column="0" colspan="3">
37-
<widget class="QgsLayerTreeView" name="mTreeView">
38-
<property name="selectionMode">
39-
<enum>QAbstractItemView::ExtendedSelection</enum>
40-
</property>
41-
<attribute name="headerDefaultSectionSize">
42-
<number>0</number>
43-
</attribute>
44-
</widget>
45-
</item>
46-
<item row="0" column="0">
47-
<widget class="QLabel" name="mSaveAsLabel">
48-
<property name="text">
49-
<string>Save as</string>
50-
</property>
51-
</widget>
52-
</item>
53-
<item row="1" column="0">
54-
<widget class="QLabel" name="mSymbologyModeLabel">
55-
<property name="text">
56-
<string>Symbology mode</string>
57-
</property>
58-
</widget>
59-
</item>
60-
<item row="2" column="1" colspan="2">
61-
<widget class="QLineEdit" name="mSymbologyScaleLineEdit"/>
62-
</item>
63-
<item row="1" column="1" colspan="2">
64-
<widget class="QComboBox" name="mSymbologyModeComboBox">
65-
<item>
66-
<property name="text">
67-
<string>No symbology</string>
68-
</property>
69-
</item>
70-
<item>
71-
<property name="text">
72-
<string>Feature symbology</string>
73-
</property>
74-
</item>
75-
<item>
76-
<property name="text">
77-
<string>Symbol layer symbology</string>
78-
</property>
79-
</item>
80-
</widget>
34+
<item row="2" column="1" colspan="2">
35+
<widget class="QLineEdit" name="mSymbologyScaleLineEdit"/>
36+
</item>
37+
<item row="0" column="0">
38+
<widget class="QLabel" name="mSaveAsLabel">
39+
<property name="text">
40+
<string>Save as</string>
41+
</property>
42+
</widget>
43+
</item>
44+
<item row="2" column="0">
45+
<widget class="QLabel" name="mSymbologyScaleLabel">
46+
<property name="text">
47+
<string>Symbology scale</string>
48+
</property>
49+
</widget>
50+
</item>
51+
<item row="1" column="1" colspan="2">
52+
<widget class="QComboBox" name="mSymbologyModeComboBox">
53+
<item>
54+
<property name="text">
55+
<string>No symbology</string>
56+
</property>
8157
</item>
82-
<item row="2" column="0">
83-
<widget class="QLabel" name="mSymbologyScaleLabel">
84-
<property name="text">
85-
<string>Symbology scale</string>
86-
</property>
87-
</widget>
58+
<item>
59+
<property name="text">
60+
<string>Feature symbology</string>
61+
</property>
8862
</item>
89-
<item row="0" column="1">
90-
<widget class="QLineEdit" name="mFileLineEdit"/>
63+
<item>
64+
<property name="text">
65+
<string>Symbol layer symbology</string>
66+
</property>
9167
</item>
92-
<item row="4" column="0">
93-
<widget class="QLabel" name="label">
68+
</widget>
69+
</item>
70+
<item row="1" column="0">
71+
<widget class="QLabel" name="mSymbologyModeLabel">
72+
<property name="text">
73+
<string>Symbology mode</string>
74+
</property>
75+
</widget>
76+
</item>
77+
<item row="6" column="0" colspan="3">
78+
<layout class="QGridLayout" name="gridLayout_3">
79+
<item row="0" column="0">
80+
<widget class="QPushButton" name="mSelectAllButton">
9481
<property name="text">
95-
<string>Layer attribute</string>
96-
</property>
97-
<property name="buddy">
98-
<cstring>mLayerAttributeComboBox</cstring>
99-
</property>
100-
</widget>
101-
</item>
102-
<item row="4" column="1" colspan="2">
103-
<widget class="QgsFieldComboBox" name="mLayerAttributeComboBox">
104-
<property name="enabled">
105-
<bool>false</bool>
106-
</property>
107-
<property name="editable">
108-
<bool>false</bool>
82+
<string>Select all</string>
10983
</property>
11084
</widget>
11185
</item>
112-
</layout>
113-
</item>
114-
<item row="2" column="0" colspan="2">
115-
<layout class="QGridLayout" name="gridLayout_3">
116-
<item row="0" column="1">
86+
<item row="0" column="2">
11787
<widget class="QPushButton" name="mUnSelectAllButton">
11888
<property name="text">
11989
<string>Unselect all</string>
12090
</property>
12191
</widget>
12292
</item>
123-
<item row="0" column="2">
93+
<item row="0" column="1">
12494
<spacer name="horizontalSpacer">
12595
<property name="orientation">
12696
<enum>Qt::Horizontal</enum>
@@ -133,30 +103,41 @@
133103
</property>
134104
</spacer>
135105
</item>
136-
<item row="0" column="0">
137-
<widget class="QPushButton" name="mSelectAllButton">
138-
<property name="text">
139-
<string>Select all</string>
140-
</property>
141-
</widget>
142-
</item>
143106
</layout>
144107
</item>
145-
<item row="3" column="1">
108+
<item row="0" column="1">
109+
<widget class="QLineEdit" name="mFileLineEdit"/>
110+
</item>
111+
<item row="7" column="0" colspan="3">
146112
<widget class="QCheckBox" name="mMapExtentCheckBox">
147113
<property name="text">
148114
<string>Export features intersecting the current map extent</string>
149115
</property>
150116
</widget>
151117
</item>
118+
<item row="8" column="0" colspan="3">
119+
<widget class="QDialogButtonBox" name="buttonBox">
120+
<property name="orientation">
121+
<enum>Qt::Horizontal</enum>
122+
</property>
123+
<property name="standardButtons">
124+
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
125+
</property>
126+
</widget>
127+
</item>
128+
<item row="3" column="1" colspan="2">
129+
<widget class="QComboBox" name="mVisibilityPresets"/>
130+
</item>
131+
<item row="3" column="0">
132+
<widget class="QLabel" name="mSymbologyScaleLabel_2">
133+
<property name="text">
134+
<string>Visibility presets</string>
135+
</property>
136+
</widget>
137+
</item>
152138
</layout>
153139
</widget>
154140
<customwidgets>
155-
<customwidget>
156-
<class>QgsFieldComboBox</class>
157-
<extends>QComboBox</extends>
158-
<header>qgsfieldcombobox.h</header>
159-
</customwidget>
160141
<customwidget>
161142
<class>QgsLayerTreeView</class>
162143
<extends>QTreeView</extends>

0 commit comments

Comments
 (0)
Please sign in to comment.