Skip to content

Commit

Permalink
widget fixes:
Browse files Browse the repository at this point in the history
- add sip bindings for new widgets (and some other missing pieces)
- change Webview to WebView (like in QWebView)
- use proxy settings also for webview widget
- don't disable Photo and webview widget
- use smooth transformation in photo widget
- show disabled color button with dotted border in actual color instead of
  grayed-out
  • Loading branch information
jef-n committed Apr 2, 2013
1 parent 45b931b commit 6e6b8fe
Show file tree
Hide file tree
Showing 9 changed files with 125 additions and 52 deletions.
4 changes: 2 additions & 2 deletions i18n/qgis_de.ts
Expand Up @@ -11534,8 +11534,8 @@ Fehler war:%2</translation>
</message>
<message>
<location filename="../src/ui/qgsattributetypeedit.ui" line="106"/>
<source>Webview</source>
<translation>Webview</translation>
<source>Web view</source>
<translation>Webansicht</translation>
</message>
<message>
<location filename="../src/ui/qgsattributetypeedit.ui" line="137"/>
Expand Down
21 changes: 21 additions & 0 deletions python/core/qgsvectorlayer.sip
Expand Up @@ -115,6 +115,9 @@ class QgsVectorLayer : QgsMapLayer
DialRange, /* dial range @added in 1.5 */
ValueRelation, /* value map from an table @added in 1.8 */
UuidGenerator, /* uuid generator - readonly and automatically intialized @added in 1.9 */
Photo, /* phote widget @added in 1.9 */
WebView, /* webview widget @added in 1.9 */
Color, /* color @added in 1.9 */
};

struct RangeData
Expand Down Expand Up @@ -595,6 +598,15 @@ class QgsVectorLayer : QgsMapLayer
/** delete an attribute field (but does not commit it) */
bool deleteAttribute( int attr );

/**
* Deletes a list of attribute fields (but does not commit it)
*
* @param attrs the indices of the attributes to delete
* @return true if at least one attribute has been deleted
*
*/
bool deleteAttributes( QList<int> attrs );

/** Insert a copy of the given features into the layer (but does not commit it) */
bool addFeatures( QList<QgsFeature> features, bool makeSelected = true );

Expand Down Expand Up @@ -679,6 +691,11 @@ class QgsVectorLayer : QgsMapLayer
*/
QString &dateFormat( int idx );

/**access widget size for photo and webview widget
* @note added in 1.9
*/
QSize &widgetSize( int idx );

/**is edit widget editable
* @note added in 1.9
**/
Expand Down Expand Up @@ -742,6 +759,10 @@ class QgsVectorLayer : QgsMapLayer
@note public and static from version 1.4 */
static void drawVertexMarker( double x, double y, QPainter& p, QgsVectorLayer::VertexMarkerType type, int vertexSize );

/** Assembles mUpdatedFields considering provider fields, joined fields and added fields
@note added in 1.7 */
void updateFields();

/** Caches joined attributes if required (and not already done)
@note added in 1.7 */
void createJoinCaches();
Expand Down
6 changes: 3 additions & 3 deletions src/app/qgsattributetypedialog.cpp
Expand Up @@ -335,7 +335,7 @@ void QgsAttributeTypeDialog::setPageForEditType( QgsVectorLayer::EditType editTy
setPage( 14 );
break;

case QgsVectorLayer::Webview:
case QgsVectorLayer::WebView:
setPage( 15 );
break;

Expand Down Expand Up @@ -527,7 +527,7 @@ void QgsAttributeTypeDialog::setIndex( int index, QgsVectorLayer::EditType editT
case QgsVectorLayer::Hidden:
case QgsVectorLayer::TextEdit:
case QgsVectorLayer::UuidGenerator:
case QgsVectorLayer::Webview:
case QgsVectorLayer::WebView:
case QgsVectorLayer::Color:
break;
}
Expand Down Expand Up @@ -702,7 +702,7 @@ void QgsAttributeTypeDialog::accept()
mWidgetSize = QSize( sbWidgetWidth->value(), sbWidgetHeight->value() );
break;
case 15:
mEditType = QgsVectorLayer::Webview;
mEditType = QgsVectorLayer::WebView;
break;
case 16:
mEditType = QgsVectorLayer::Color;
Expand Down
6 changes: 3 additions & 3 deletions src/app/qgsfieldsproperties.cpp
Expand Up @@ -534,7 +534,7 @@ void QgsFieldsProperties::attributeTypeDialog()
case QgsVectorLayer::Immutable:
case QgsVectorLayer::Hidden:
case QgsVectorLayer::UuidGenerator:
case QgsVectorLayer::Webview:
case QgsVectorLayer::WebView:
case QgsVectorLayer::Color:
break;
}
Expand Down Expand Up @@ -746,7 +746,7 @@ void QgsFieldsProperties::setupEditTypes()
editTypeMap.insert( QgsVectorLayer::ValueRelation, tr( "Value relation" ) );
editTypeMap.insert( QgsVectorLayer::UuidGenerator, tr( "UUID generator" ) );
editTypeMap.insert( QgsVectorLayer::Photo, tr( "Photo" ) );
editTypeMap.insert( QgsVectorLayer::Webview, tr( "Webview" ) );
editTypeMap.insert( QgsVectorLayer::WebView, tr( "Web view" ) );
editTypeMap.insert( QgsVectorLayer::Color, tr( "Color" ) );
}

Expand Down Expand Up @@ -892,7 +892,7 @@ void QgsFieldsProperties::apply()
case QgsVectorLayer::Hidden:
case QgsVectorLayer::TextEdit:
case QgsVectorLayer::UuidGenerator:
case QgsVectorLayer::Webview:
case QgsVectorLayer::WebView:
case QgsVectorLayer::Color:
break;
}
Expand Down
4 changes: 2 additions & 2 deletions src/core/qgsvectorlayer.cpp
Expand Up @@ -2424,7 +2424,7 @@ bool QgsVectorLayer::readSymbology( const QDomNode& node, QString& errorMessage
case UniqueValues:
case UniqueValuesEditable:
case UuidGenerator:
case Webview:
case WebView:
case Color:
break;
}
Expand Down Expand Up @@ -2750,7 +2750,7 @@ bool QgsVectorLayer::writeSymbology( QDomNode& node, QDomDocument& doc, QString&
case Enumeration:
case Immutable:
case UuidGenerator:
case Webview:
case WebView:
case Color:
break;
}
Expand Down
2 changes: 1 addition & 1 deletion src/core/qgsvectorlayer.h
Expand Up @@ -178,7 +178,7 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer
ValueRelation, /* value map from an table @added in 1.8 */
UuidGenerator, /* uuid generator - readonly and automatically intialized @added in 1.9 */
Photo, /* phote widget @added in 1.9 */
Webview, /* webview widget @added in 1.9 */
WebView, /* webview widget @added in 1.9 */
Color, /* color @added in 1.9 */
};

Expand Down
53 changes: 48 additions & 5 deletions src/gui/qgsattributedialog.cpp
Expand Up @@ -41,6 +41,7 @@
#include <QDialog>
#include <QVBoxLayout>
#include <QLineEdit>
#include <QWebView>

int QgsAttributeDialog::smFormCounter = 0;

Expand Down Expand Up @@ -202,7 +203,28 @@ QgsAttributeDialog::QgsAttributeDialog( QgsVectorLayer *vl, QgsFeature *thepFeat

if ( vl->editType( fldIdx ) != QgsVectorLayer::Immutable )
{
myWidget->setEnabled( vl->isEditable() && vl->fieldEditable( fldIdx ) );
if ( vl->isEditable() && vl->fieldEditable( fldIdx ) )
{
myWidget->setEnabled( true );
}
else if ( vl->editType( fldIdx ) == QgsVectorLayer::Photo )
{
foreach ( QWidget *w, myWidget->findChildren<QWidget *>() )
{
w->setEnabled( qobject_cast<QLabel *>( w ) ? true : false );
}
}
else if ( vl->editType( fldIdx ) == QgsVectorLayer::WebView )
{
foreach ( QWidget *w, myWidget->findChildren<QWidget *>() )
{
w->setEnabled( qobject_cast<QWebView *>( w ) ? true : false );
}
}
else
{
myWidget->setEnabled( false );
}
}

mypInnerLayout->addWidget( myWidget, index, 1 );
Expand Down Expand Up @@ -232,13 +254,34 @@ QgsAttributeDialog::QgsAttributeDialog( QgsVectorLayer *vl, QgsFeature *thepFeat
if ( myWidgets.isEmpty() )
continue;

foreach ( QWidget *w, myWidgets )
foreach ( QWidget *myWidget, myWidgets )
{
QgsAttributeEditor::createAttributeEditor( mDialog, w, vl, fldIdx, myAttributes[fldIdx], mProxyWidgets );
QgsAttributeEditor::createAttributeEditor( mDialog, myWidget, vl, fldIdx, myAttributes[fldIdx], mProxyWidgets );

if ( vl->editType( fldIdx ) != QgsVectorLayer::Immutable && w->isEnabled() )
if ( vl->editType( fldIdx ) != QgsVectorLayer::Immutable )
{
w->setEnabled( vl->isEditable() && vl->fieldEditable( fldIdx ) );
if ( vl->isEditable() && vl->fieldEditable( fldIdx ) )
{
myWidget->setEnabled( true );
}
else if ( vl->editType( fldIdx ) == QgsVectorLayer::Photo )
{
foreach ( QWidget *w, myWidget->findChildren<QWidget *>() )
{
w->setEnabled( qobject_cast<QLabel *>( w ) ? true : false );
}
}
else if ( vl->editType( fldIdx ) == QgsVectorLayer::WebView )
{
foreach ( QWidget *w, myWidget->findChildren<QWidget *>() )
{
w->setEnabled( qobject_cast<QWebView *>( w ) ? true : false );
}
}
else
{
myWidget->setEnabled( false );
}
}
}
}
Expand Down
49 changes: 33 additions & 16 deletions src/gui/qgsattributeeditor.cpp
Expand Up @@ -28,6 +28,7 @@
#include <qgsexpression.h>
#include <qgsfilterlineedit.h>
#include <qgscolorbutton.h>
#include <qgsnetworkaccessmanager.h>

#include <QScrollArea>
#include <QPushButton>
Expand Down Expand Up @@ -159,7 +160,7 @@ void QgsAttributeEditor::loadPixmap( const QString &name )
size.setHeight( size.width() * pm.size().height() / pm.size().width() );
}

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

lw->setPixmap( pm );
lw->setMinimumSize( size );
Expand Down Expand Up @@ -652,7 +653,9 @@ QWidget *QgsAttributeEditor::createAttributeEditor( QWidget *parent, QWidget *ed
if ( myWidget )
{
if ( editType == QgsVectorLayer::Immutable )
{
myWidget->setDisabled( true );
}

QgsStringRelay* relay = NULL;

Expand Down Expand Up @@ -708,7 +711,7 @@ QWidget *QgsAttributeEditor::createAttributeEditor( QWidget *parent, QWidget *ed
case QgsVectorLayer::FileName:
case QgsVectorLayer::Calendar:
case QgsVectorLayer::Photo:
case QgsVectorLayer::Webview:
case QgsVectorLayer::WebView:
case QgsVectorLayer::Color:
{
QCalendarWidget *cw = qobject_cast<QCalendarWidget *>( editor );
Expand All @@ -721,6 +724,12 @@ QWidget *QgsAttributeEditor::createAttributeEditor( QWidget *parent, QWidget *ed
QWebView *ww = qobject_cast<QWebView *>( editor );
if ( ww )
{
ww->page()->setNetworkAccessManager( QgsNetworkAccessManager::instance() );
ww->page()->setLinkDelegationPolicy( QWebPage::DelegateAllLinks );
ww->settings()->setAttribute( QWebSettings::LocalContentCanAccessRemoteUrls, true );
#ifdef QGISDEBUG
ww->settings()->setAttribute( QWebSettings::DeveloperExtrasEnabled, true );
#endif
myWidget = ww;
break;
}
Expand Down Expand Up @@ -753,47 +762,55 @@ QWidget *QgsAttributeEditor::createAttributeEditor( QWidget *parent, QWidget *ed
}
else
{
le = new QgsFilterLineEdit();
myWidget = new QWidget( parent );
myWidget->setBackgroundRole( QPalette::Window );
myWidget->setAutoFillBackground( true );

le = new QgsFilterLineEdit( myWidget );
switch ( editType )
{
case QgsVectorLayer::FileName:
case QgsVectorLayer::Photo:
pb = new QPushButton( tr( "..." ) );
pb = new QPushButton( tr( "..." ), myWidget );
break;

case QgsVectorLayer::Webview:
pb = new QPushButton( tr( "<" ) );
case QgsVectorLayer::WebView:
pb = new QPushButton( tr( "<" ), myWidget );
break;

case QgsVectorLayer::Color:
pb = new QgsColorButton();
pb = new QgsColorButton( myWidget );
break;

default:
break;
}


int row = 0;
QGridLayout *layout = new QGridLayout();
QGridLayout *layout = new QGridLayout( myWidget );
if ( editType == QgsVectorLayer::Photo )
{
lw = new QLabel();
lw = new QLabel( myWidget );
layout->addWidget( lw, 0, 0, 1, 2 );
row++;
}
else if ( editType == QgsVectorLayer::Webview )
else if ( editType == QgsVectorLayer::WebView )
{
ww = new QWebView();
ww = new QWebView( myWidget );
ww->page()->setNetworkAccessManager( QgsNetworkAccessManager::instance() );
ww->page()->setLinkDelegationPolicy( QWebPage::DelegateAllLinks );
ww->settings()->setAttribute( QWebSettings::LocalContentCanAccessRemoteUrls, true );
#ifdef QGISDEBUG
ww->settings()->setAttribute( QWebSettings::DeveloperExtrasEnabled, true );
#endif
layout->addWidget( ww, 0, 0, 1, 2 );
row++;
}

layout->addWidget( le, row, 0 );
layout->addWidget( pb, row, 1 );

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

Expand All @@ -813,7 +830,7 @@ QWidget *QgsAttributeEditor::createAttributeEditor( QWidget *parent, QWidget *ed
{
if ( editType == QgsVectorLayer::FileName || editType == QgsVectorLayer::Photo )
connect( pb, SIGNAL( clicked() ), new QgsAttributeEditor( pb ), SLOT( selectFileName() ) );
if ( editType == QgsVectorLayer::Webview )
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 @@ -1197,7 +1214,7 @@ bool QgsAttributeEditor::setValue( QWidget *editor, QgsVectorLayer *vl, int idx,
case QgsVectorLayer::FileName:
case QgsVectorLayer::Calendar:
case QgsVectorLayer::Photo:
case QgsVectorLayer::Webview:
case QgsVectorLayer::WebView:
case QgsVectorLayer::Color:
{
QCalendarWidget *cw = qobject_cast<QCalendarWidget *>( editor );
Expand Down

1 comment on commit 6e6b8fe

@dakcarto
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice touch on the color button edit, Juergen. Keeps the color while still showing it's disabled. Much better than the color shifts I was getting with the fake-disabled method, and helpful when multiple color buttons are next to each other and some are disabled.

Please sign in to comment.