Skip to content

Commit 8d49b5e

Browse files
author
jef
committed
add file selection to attribute dialog
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@9276 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent 965b5c8 commit 8d49b5e

File tree

4 files changed

+52
-1
lines changed

4 files changed

+52
-1
lines changed

src/app/qgsattributedialog.cpp

+46
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@
3535
#include <QSlider>
3636
#include <QSpinBox>
3737
#include <QDoubleSpinBox>
38+
#include <QPushButton>
39+
#include <QHBoxLayout>
40+
#include <QFileDialog>
3841

3942
QgsAttributeDialog::QgsAttributeDialog( QgsVectorLayer *vl, QgsFeature *thepFeature )
4043
: QDialog(),
@@ -245,6 +248,22 @@ QgsAttributeDialog::QgsAttributeDialog( QgsVectorLayer *vl, QgsFeature *thepFeat
245248
myWidget = le;
246249
}
247250
break;
251+
252+
case QgsVectorLayer::FileName:
253+
{
254+
QLineEdit *le = new QLineEdit( myFieldValue.toString() );
255+
256+
QPushButton *pb = new QPushButton( tr("...") );
257+
connect(pb, SIGNAL(clicked()), this, SLOT(selectFileName()));
258+
259+
QHBoxLayout *hbl = new QHBoxLayout();
260+
hbl->addWidget(le);
261+
hbl->addWidget(pb);
262+
263+
myWidget = new QWidget;
264+
myWidget->setLayout(hbl);
265+
}
266+
break;
248267
}
249268

250269
if ( myFieldType == QVariant::Int )
@@ -274,6 +293,27 @@ QgsAttributeDialog::~QgsAttributeDialog()
274293
saveGeometry();
275294
}
276295

296+
void QgsAttributeDialog::selectFileName()
297+
{
298+
QPushButton *pb = dynamic_cast<QPushButton *>( sender() );
299+
if(!pb)
300+
return;
301+
302+
QWidget *hbox = dynamic_cast<QWidget *>( pb->parent() );
303+
if(!hbox)
304+
return;
305+
306+
QLineEdit *le = hbox->findChild<QLineEdit *>();
307+
if(!le)
308+
return;
309+
310+
QString fileName = QFileDialog::getOpenFileName(0 , tr("Select a file"));
311+
if(fileName.isNull())
312+
return;
313+
314+
le->setText(fileName);
315+
}
316+
277317
void QgsAttributeDialog::accept()
278318
{
279319
//write the new values back to the feature
@@ -328,6 +368,12 @@ void QgsAttributeDialog::accept()
328368
myFieldValue = QString::number( dsb->value() );
329369
}
330370

371+
le = mpWidgets.value( myIndex )->findChild<QLineEdit *>("lineEdit");
372+
if(le)
373+
{
374+
myFieldValue = le->text();
375+
}
376+
331377
switch ( theField.type() )
332378
{
333379
case QVariant::Int:

src/app/qgsattributedialog.h

+3
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ class QgsAttributeDialog: public QDialog, private Ui::QgsAttributeDialogBase
5050
*/
5151
void restoreGeometry();
5252

53+
public slots:
54+
void selectFileName();
55+
5356
private:
5457
QString mSettingsPath;
5558
QList<QWidget *> mpWidgets;

src/app/qgsvectorlayerproperties.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ void QgsVectorLayerProperties::setRow( int row, int idx, const QgsField &field )
168168
cb->addItem( tr( "classification" ), QgsVectorLayer::Classification );
169169
cb->addItem( tr( "range (editable)" ), QgsVectorLayer::EditRange );
170170
cb->addItem( tr( "range (slider)" ), QgsVectorLayer::SliderRange );
171+
cb->addItem( tr( "file name" ), QgsVectorLayer::FileName );
171172
cb->setSizeAdjustPolicy( QComboBox::AdjustToContentsOnFirstShow );
172173
cb->setCurrentIndex( layer->editType( idx ) );
173174

src/core/qgsvectorlayer.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer
6767
ValueMap,
6868
Classification,
6969
EditRange,
70-
SliderRange
70+
SliderRange,
71+
FileName
7172
};
7273

7374
struct RangeData

0 commit comments

Comments
 (0)