Skip to content

Commit de2efa7

Browse files
committedApr 8, 2013
Attribute editor, form view: Change selection behavior
Text background is now used for the current edit selection The icon shows the feature selection state
1 parent 43dfeb5 commit de2efa7

File tree

6 files changed

+1858
-24
lines changed

6 files changed

+1858
-24
lines changed
 

‎images/images.qrc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -545,6 +545,8 @@
545545
<file>themes/gis/mIconSelectAdd.svg</file>
546546
<file>themes/gis/mIconSelectIntersect.svg</file>
547547
<file>themes/gis/mIconSelectRemove.svg</file>
548+
<file>themes/gis/mIconSelected.svg</file>
549+
<file>themes/gis/mIconDeselected.svg</file>
548550
</qresource>
549551
<qresource prefix="/images/tips">
550552
<file alias="symbol_levels.png">qgis_tips/symbol_levels.png</file>

‎images/themes/gis/mIconDeselected.svg

Lines changed: 915 additions & 0 deletions
Loading

‎images/themes/gis/mIconSelected.svg

Lines changed: 915 additions & 0 deletions
Loading

‎src/gui/attributetable/qgsfeaturelistview.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ void QgsFeatureListView::mousePressEvent( QMouseEvent *event )
106106
{
107107
QPoint pos = event->pos();
108108

109-
if ( QgsFeatureListViewDelegate::EditButtonElement == mItemDelegate->positionToElement( event->pos() ) )
109+
if ( QgsFeatureListViewDelegate::EditElement == mItemDelegate->positionToElement( event->pos() ) )
110110
{
111111
mEditSelectionDrag = true;
112112
QModelIndex index = mModel->mapToMaster( indexAt( pos ) );

‎src/gui/attributetable/qgsfeaturelistviewdelegate.cpp

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@ QgsFeatureListViewDelegate::QgsFeatureListViewDelegate( QgsFeatureListModel *lis
2020

2121
QgsFeatureListViewDelegate::Element QgsFeatureListViewDelegate::positionToElement( const QPoint &pos )
2222
{
23-
if ( pos.x() < sIconSize )
23+
if ( pos.x() > sIconSize )
2424
{
25-
return EditButtonElement;
25+
return EditElement;
2626
}
2727
else
2828
{
29-
return TextElement;
29+
return SelectionElement;
3030
}
3131
}
3232

@@ -45,46 +45,48 @@ void QgsFeatureListViewDelegate::paint( QPainter *painter, const QStyleOptionVie
4545
{
4646
QString text = index.model()->data( index, Qt::EditRole ).toString();
4747
QgsFeatureListModel::FeatureInfo featInfo = index.model()->data( index, Qt::UserRole ).value<QgsFeatureListModel::FeatureInfo>();
48+
bool isEdited = mEditSelectionModel->isSelected( mListModel->mapToMaster( index ) );
4849

49-
// Edit button state
50-
bool checked = mEditSelectionModel->isSelected( mListModel->mapToMaster( index ) );
50+
// Icon layout options
51+
QStyleOptionViewItem iconOption;
5152

52-
QStyleOptionButton pbn1Opts;
53+
QRect iconLayoutBounds( option.rect.x(), option.rect.y(), option.rect.height(), option.rect.height() );
5354

54-
pbn1Opts.iconSize = QSize( sIconSize, sIconSize );
55+
QPixmap icon;
5556

56-
pbn1Opts.state |= QStyle::State_Enabled;
57-
if ( checked )
57+
if ( option.state.testFlag( QStyle::State_Selected ) )
5858
{
59-
pbn1Opts.icon = QgsApplication::getThemeIcon( "/mIconEditableEdits.png" );
60-
pbn1Opts.state |= QStyle::State_On;
59+
// Item is selected
60+
icon = QgsApplication::getThemePixmap( "/mIconSelected.svg" );
6161
}
6262
else
6363
{
64-
pbn1Opts.icon = QgsApplication::getThemeIcon( "/mIconEditable.png" );
65-
pbn1Opts.state |= QStyle::State_Off;
64+
icon = QgsApplication::getThemePixmap( "/mIconDeselected.svg" );
6665
}
6766

68-
QRect pbn1Rect( option.rect.x(), option.rect.y(), option.rect.height(), option.rect.height() );
69-
pbn1Opts.rect = pbn1Rect;
67+
// Text layout options
68+
QRect textLayoutBounds( iconLayoutBounds.x() + iconLayoutBounds.width(), option.rect.y(), option.rect.width() - ( iconLayoutBounds.x() + iconLayoutBounds.width() ), option.rect.height() );
7069

71-
QApplication::style()->drawControl( QStyle::CE_PushButton, &pbn1Opts, painter );
72-
73-
QRect textLayoutBounds( pbn1Rect.x() + pbn1Rect.width(), option.rect.y(), option.rect.width() - ( pbn1Rect.x() + pbn1Rect.width() ), option.rect.height() );
74-
75-
QStyleOptionViewItem textOption = option;
70+
QStyleOptionViewItem textOption;
71+
textOption.state |= QStyle::State_Enabled;
72+
if ( isEdited )
73+
{
74+
textOption.state |= QStyle::State_Selected;
75+
}
7676

7777
if ( featInfo.isNew )
7878
{
7979
textOption.font.setStyle( QFont::StyleItalic );
8080
textOption.palette.setColor( QPalette::Text, Qt::darkGreen );
8181
textOption.palette.setColor( QPalette::HighlightedText, Qt::darkGreen );
8282
}
83-
else if ( featInfo.isEdited || checked )
83+
else if ( featInfo.isEdited || isEdited )
8484
{
8585
textOption.font.setStyle( QFont::StyleItalic );
8686
textOption.palette.setColor( QPalette::Text, Qt::red );
8787
textOption.palette.setColor( QPalette::HighlightedText, Qt::red );
8888
}
89+
8990
drawDisplay( painter, textOption, textLayoutBounds, text );
91+
drawDecoration( painter, iconOption, iconLayoutBounds, icon );
9092
}

‎src/gui/attributetable/qgsfeaturelistviewdelegate.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ class QgsFeatureListViewDelegate : public QItemDelegate
1919

2020
enum Element
2121
{
22-
EditButtonElement,
23-
TextElement
22+
EditElement,
23+
SelectionElement
2424
};
2525

2626
explicit QgsFeatureListViewDelegate( QgsFeatureListModel* listModel, QObject *parent = 0 );

0 commit comments

Comments
 (0)
Please sign in to comment.