Skip to content

Commit

Permalink
add file selection to attribute dialog
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@9276 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
jef committed Sep 7, 2008
1 parent 965b5c8 commit 8d49b5e
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 1 deletion.
46 changes: 46 additions & 0 deletions src/app/qgsattributedialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@
#include <QSlider>
#include <QSpinBox>
#include <QDoubleSpinBox>
#include <QPushButton>
#include <QHBoxLayout>
#include <QFileDialog>

QgsAttributeDialog::QgsAttributeDialog( QgsVectorLayer *vl, QgsFeature *thepFeature )
: QDialog(),
Expand Down Expand Up @@ -245,6 +248,22 @@ QgsAttributeDialog::QgsAttributeDialog( QgsVectorLayer *vl, QgsFeature *thepFeat
myWidget = le;
}
break;

case QgsVectorLayer::FileName:
{
QLineEdit *le = new QLineEdit( myFieldValue.toString() );

QPushButton *pb = new QPushButton( tr("...") );
connect(pb, SIGNAL(clicked()), this, SLOT(selectFileName()));

QHBoxLayout *hbl = new QHBoxLayout();
hbl->addWidget(le);
hbl->addWidget(pb);

myWidget = new QWidget;
myWidget->setLayout(hbl);
}
break;
}

if ( myFieldType == QVariant::Int )
Expand Down Expand Up @@ -274,6 +293,27 @@ QgsAttributeDialog::~QgsAttributeDialog()
saveGeometry();
}

void QgsAttributeDialog::selectFileName()
{
QPushButton *pb = dynamic_cast<QPushButton *>( sender() );
if(!pb)
return;

QWidget *hbox = dynamic_cast<QWidget *>( pb->parent() );
if(!hbox)
return;

QLineEdit *le = hbox->findChild<QLineEdit *>();
if(!le)
return;

QString fileName = QFileDialog::getOpenFileName(0 , tr("Select a file"));
if(fileName.isNull())
return;

le->setText(fileName);
}

void QgsAttributeDialog::accept()
{
//write the new values back to the feature
Expand Down Expand Up @@ -328,6 +368,12 @@ void QgsAttributeDialog::accept()
myFieldValue = QString::number( dsb->value() );
}

le = mpWidgets.value( myIndex )->findChild<QLineEdit *>("lineEdit");
if(le)
{
myFieldValue = le->text();
}

switch ( theField.type() )
{
case QVariant::Int:
Expand Down
3 changes: 3 additions & 0 deletions src/app/qgsattributedialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ class QgsAttributeDialog: public QDialog, private Ui::QgsAttributeDialogBase
*/
void restoreGeometry();

public slots:
void selectFileName();

private:
QString mSettingsPath;
QList<QWidget *> mpWidgets;
Expand Down
1 change: 1 addition & 0 deletions src/app/qgsvectorlayerproperties.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ void QgsVectorLayerProperties::setRow( int row, int idx, const QgsField &field )
cb->addItem( tr( "classification" ), QgsVectorLayer::Classification );
cb->addItem( tr( "range (editable)" ), QgsVectorLayer::EditRange );
cb->addItem( tr( "range (slider)" ), QgsVectorLayer::SliderRange );
cb->addItem( tr( "file name" ), QgsVectorLayer::FileName );
cb->setSizeAdjustPolicy( QComboBox::AdjustToContentsOnFirstShow );
cb->setCurrentIndex( layer->editType( idx ) );

Expand Down
3 changes: 2 additions & 1 deletion src/core/qgsvectorlayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer
ValueMap,
Classification,
EditRange,
SliderRange
SliderRange,
FileName
};

struct RangeData
Expand Down

0 comments on commit 8d49b5e

Please sign in to comment.