146 changes: 138 additions & 8 deletions src/gui/qgsattributeeditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
#include <QUuid>
#include <QGroupBox>
#include <QLabel>
#include <QWebView>

void QgsAttributeEditor::selectFileName()
{
Expand All @@ -63,7 +64,7 @@ void QgsAttributeEditor::selectFileName()
if ( !le )
return;

QString fileName = QFileDialog::getOpenFileName( 0 , tr( "Select a file" ) );
QString fileName = QFileDialog::getOpenFileName( 0 , tr( "Select a file" ), QFileInfo( le->text() ).absolutePath() );
if ( fileName.isNull() )
return;

Expand Down Expand Up @@ -112,6 +113,80 @@ void QgsAttributeEditor::selectDate()
}
}

void QgsAttributeEditor::loadUrl( const QString &url )
{
QLineEdit *le = qobject_cast<QLineEdit *>( sender() );
if ( !le )
return;

QWidget *hbox = qobject_cast<QWidget *>( le->parent() );
if ( !hbox )
return;

QWebView *ww = hbox->findChild<QWebView *>();
if ( !ww )
return;

ww->load( url );
}

void QgsAttributeEditor::loadPixmap( const QString &name )
{
QLineEdit *le = qobject_cast<QLineEdit *>( sender() );
if ( !le )
return;

QWidget *hbox = qobject_cast<QWidget *>( le->parent() );
if ( !hbox )
return;

QLabel *lw = hbox->findChild<QLabel *>();
if ( !lw )
return;

QPixmap pm( name );
if ( pm.isNull() )
return;

QSize size( mLayer->widgetSize( mIdx ) );
if ( size.width() == 0 && size.height() > 0 )
{
size.setWidth( size.height() * pm.size().width() / pm.size().height() );
}
else if ( size.width() > 0 && size.height() == 0 )
{
size.setHeight( size.width() * pm.size().height() / pm.size().width() );
}

pm = pm.scaled( size, Qt::KeepAspectRatio );

lw->setPixmap( pm );
lw->setMinimumSize( size );
}

void QgsAttributeEditor::updateUrl()
{
QPushButton *pb = qobject_cast<QPushButton *>( sender() );
if ( !pb )
return;

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

QWebView *ww = hbox->findChild<QWebView *>();
if ( !ww )
return;

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

le->blockSignals( true );
le->setText( ww->url().toString() );
le->blockSignals( false );
}

QComboBox *QgsAttributeEditor::comboBox( QWidget *editor, QWidget *parent )
{
QComboBox *cb = 0;
Expand Down Expand Up @@ -595,6 +670,8 @@ QWidget *QgsAttributeEditor::createAttributeEditor( QWidget *parent, QWidget *ed

case QgsVectorLayer::FileName:
case QgsVectorLayer::Calendar:
case QgsVectorLayer::Photo:
case QgsVectorLayer::Webview:
{
QCalendarWidget *cw = qobject_cast<QCalendarWidget *>( editor );
if ( cw )
Expand All @@ -603,6 +680,19 @@ QWidget *QgsAttributeEditor::createAttributeEditor( QWidget *parent, QWidget *ed
break;
}

QWebView *ww = qobject_cast<QWebView *>( editor );
if ( ww )
{
myWidget = ww;
break;
}

QLabel *lw = qobject_cast<QLabel *>( editor );
if ( lw )
{
myWidget = lw;
break;
}

QPushButton *pb = 0;
QLineEdit *le = qobject_cast<QLineEdit *>( editor );
Expand All @@ -619,26 +709,51 @@ QWidget *QgsAttributeEditor::createAttributeEditor( QWidget *parent, QWidget *ed
else
{
le = new QgsFilterLineEdit();
if ( editType == QgsVectorLayer::FileName || editType == QgsVectorLayer::Photo )
pb = new QPushButton( tr( "..." ) );
else
pb = new QPushButton( tr( "<" ) );

pb = new QPushButton( tr( "..." ) );
int row = 0;
QGridLayout *layout = new QGridLayout();
if ( editType == QgsVectorLayer::Photo )
{
lw = new QLabel();
layout->addWidget( lw, 0, 0, 1, 2 );
row++;
}
else if ( editType == QgsVectorLayer::Webview )
{
ww = new QWebView();
layout->addWidget( ww, 0, 0, 1, 2 );
row++;
}

QHBoxLayout *hbl = new QHBoxLayout();
hbl->addWidget( le );
hbl->addWidget( pb );
layout->addWidget( le, row, 0 );
layout->addWidget( pb, row, 1 );

myWidget = new QWidget( parent );
myWidget->setBackgroundRole( QPalette::Window );
myWidget->setAutoFillBackground( true );
myWidget->setLayout( hbl );
myWidget->setLayout( layout );
}

if ( le )
{
le->setValidator( new QgsFieldValidator( le, field, vl->dateFormat( idx ) ) );

if ( ww )
connect( le, SIGNAL( textChanged( const QString & ) ), new QgsAttributeEditor( le, vl, idx ), SLOT( loadUrl( const QString & ) ) );
if ( lw )
connect( le, SIGNAL( textChanged( const QString & ) ), new QgsAttributeEditor( le, vl, idx ), SLOT( loadPixmap( const QString & ) ) );
}

if ( pb )
{
if ( editType == QgsVectorLayer::FileName )
if ( editType == QgsVectorLayer::FileName || editType == QgsVectorLayer::Photo )
connect( pb, SIGNAL( clicked() ), new QgsAttributeEditor( pb ), SLOT( selectFileName() ) );
if ( editType == QgsVectorLayer::Webview )
connect( pb, SIGNAL( clicked() ), new QgsAttributeEditor( pb ), SLOT( updateUrl() ) );
if ( editType == QgsVectorLayer::Calendar )
connect( pb, SIGNAL( clicked() ), new QgsAttributeEditor( pb ), SLOT( selectDate() ) );
}
Expand Down Expand Up @@ -1018,6 +1133,8 @@ bool QgsAttributeEditor::setValue( QWidget *editor, QgsVectorLayer *vl, int idx,

case QgsVectorLayer::FileName:
case QgsVectorLayer::Calendar:
case QgsVectorLayer::Photo:
case QgsVectorLayer::Webview:
{
QCalendarWidget *cw = qobject_cast<QCalendarWidget *>( editor );
if ( cw )
Expand All @@ -1026,6 +1143,20 @@ bool QgsAttributeEditor::setValue( QWidget *editor, QgsVectorLayer *vl, int idx,
break;
}

QWebView *ww = qobject_cast<QWebView *>( editor );
if ( ww )
{
ww->load( value.toString() );
break;
}

QLabel *lw = qobject_cast<QLabel *>( editor );
if ( lw )
{

break;
}

QgsFilterLineEdit *fle = qobject_cast<QgsFilterLineEdit*>( editor );
QLineEdit *le = qobject_cast<QLineEdit*>( editor );
if ( !le )
Expand Down Expand Up @@ -1060,7 +1191,6 @@ bool QgsAttributeEditor::setValue( QWidget *editor, QgsVectorLayer *vl, int idx,
text = value.toString();
}


le->setText( text );
}
break;
Expand Down
13 changes: 12 additions & 1 deletion src/gui/qgsattributeeditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@ class GUI_EXPORT QgsAttributeEditor : public QObject
Q_OBJECT

public:
QgsAttributeEditor( QObject *parent ) : QObject( parent ) {};
QgsAttributeEditor( QObject *parent, QgsVectorLayer *vl = 0, int idx = -1 )
: QObject( parent )
, mLayer( vl )
, mIdx( idx )
{};
/**
* Creates or prepares a attributre editor widget
* @param parent The parent object
Expand Down Expand Up @@ -78,6 +82,13 @@ class GUI_EXPORT QgsAttributeEditor : public QObject
public slots:
void selectFileName();
void selectDate();
void loadUrl( const QString & );
void loadPixmap( const QString & );
void updateUrl();

private:
QgsVectorLayer *mLayer;
int mIdx;
};

class QgsStringRelay : public QObject
Expand Down
294 changes: 193 additions & 101 deletions src/ui/qgsattributetypeedit.ui
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,118 @@
<rect>
<x>0</x>
<y>0</y>
<width>620</width>
<height>418</height>
<width>751</width>
<height>451</height>
</rect>
</property>
<property name="windowTitle">
<string>Attribute Edit Dialog</string>
</property>
<layout class="QGridLayout" name="gridLayout_4">
<item row="3" column="1">
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
<item row="0" column="0" rowspan="4">
<widget class="QListWidget" name="selectionListWidget">
<item>
<property name="text">
<string>Line edit</string>
</property>
</item>
<item>
<property name="text">
<string>Classification</string>
</property>
</item>
<item>
<property name="text">
<string>Range</string>
</property>
</item>
<item>
<property name="text">
<string>Unique values</string>
</property>
</item>
<item>
<property name="text">
<string>File name</string>
</property>
</item>
<item>
<property name="text">
<string>Value map</string>
</property>
</item>
<item>
<property name="text">
<string>Enumeration</string>
</property>
</item>
<item>
<property name="text">
<string>Immutable</string>
</property>
</item>
<item>
<property name="text">
<string>Hidden</string>
</property>
</item>
<item>
<property name="text">
<string>Checkbox</string>
</property>
</item>
<item>
<property name="text">
<string>Text edit</string>
</property>
</item>
<item>
<property name="text">
<string>Calendar</string>
</property>
</item>
<item>
<property name="text">
<string>Value relation</string>
</property>
</item>
<item>
<property name="text">
<string>UUID generator</string>
</property>
</item>
<item>
<property name="text">
<string>Photo</string>
</property>
</item>
<item>
<property name="text">
<string>Webview</string>
</property>
</item>
</widget>
</item>
<item row="0" column="1">
<widget class="QCheckBox" name="isFieldEditableCheckBox">
<property name="text">
<string>Editable</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QStackedWidget" name="stackedWidget">
<property name="sizePolicy">
Expand All @@ -23,7 +127,7 @@
</sizepolicy>
</property>
<property name="currentIndex">
<number>0</number>
<number>15</number>
</property>
<widget class="QWidget" name="lineEditPage">
<layout class="QVBoxLayout" name="verticalLayout_1">
Expand Down Expand Up @@ -677,100 +781,88 @@
</item>
</layout>
</widget>
</widget>
</item>
<item row="2" column="1">
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
<item row="0" column="0" rowspan="3">
<widget class="QListWidget" name="selectionListWidget">
<item>
<property name="text">
<string>Line edit</string>
</property>
</item>
<item>
<property name="text">
<string>Classification</string>
</property>
</item>
<item>
<property name="text">
<string>Range</string>
</property>
</item>
<item>
<property name="text">
<string>Unique values</string>
</property>
</item>
<item>
<property name="text">
<string>File name</string>
</property>
</item>
<item>
<property name="text">
<string>Value map</string>
</property>
</item>
<item>
<property name="text">
<string>Enumeration</string>
</property>
</item>
<item>
<property name="text">
<string>Immutable</string>
</property>
</item>
<item>
<property name="text">
<string>Hidden</string>
</property>
</item>
<item>
<property name="text">
<string>Checkbox</string>
</property>
</item>
<item>
<property name="text">
<string>Text edit</string>
</property>
</item>
<item>
<property name="text">
<string>Calendar</string>
</property>
</item>
<item>
<property name="text">
<string>Value relation</string>
</property>
</item>
<item>
<property name="text">
<string>UUID generator</string>
</property>
</item>
</widget>
</item>
<item row="0" column="1">
<widget class="QCheckBox" name="isFieldEditableCheckBox">
<property name="text">
<string>Editable</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
<widget class="QWidget" name="page">
<layout class="QGridLayout" name="gridLayout_6">
<item row="2" column="0">
<widget class="QLabel" name="label_13">
<property name="text">
<string>Height</string>
</property>
</widget>
</item>
<item row="3" column="1">
<spacer name="verticalSpacer_12">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_12">
<property name="text">
<string>Width</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QSpinBox" name="sbWidgetWidth">
<property name="maximum">
<number>10000</number>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QSpinBox" name="sbWidgetHeight">
<property name="suffix">
<string/>
</property>
<property name="prefix">
<string/>
</property>
<property name="maximum">
<number>10000</number>
</property>
</widget>
</item>
<item row="0" column="0" colspan="2">
<widget class="QLabel" name="label_11">
<property name="text">
<string>Field contains a filename for a picture</string>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="page_2">
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QLabel" name="label_14">
<property name="text">
<string>Fields contains an URL</string>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer_13">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</widget>
</item>
</layout>
Expand All @@ -784,8 +876,8 @@
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>403</x>
<y>388</y>
<x>520</x>
<y>435</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
Expand All @@ -800,8 +892,8 @@
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>471</x>
<y>388</y>
<x>588</x>
<y>435</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
Expand Down