From a300fde9adcb04f1d57269c2849e7337a6d3d4a3 Mon Sep 17 00:00:00 2001 From: mzn Date: Thu, 23 Oct 2014 09:26:35 +0000 Subject: [PATCH] Harmonisation of GUI. --- src/HYDROGUI/HYDROGUI_PriorityWidget.cxx | 52 +++++++++++++----------- src/HYDROGUI/HYDROGUI_PriorityWidget.h | 22 ++++++++++ 2 files changed, 51 insertions(+), 23 deletions(-) diff --git a/src/HYDROGUI/HYDROGUI_PriorityWidget.cxx b/src/HYDROGUI/HYDROGUI_PriorityWidget.cxx index f842733b..fe011338 100644 --- a/src/HYDROGUI/HYDROGUI_PriorityWidget.cxx +++ b/src/HYDROGUI/HYDROGUI_PriorityWidget.cxx @@ -29,27 +29,12 @@ #include #include +#include #include -#include #include #include -/** - Custom item delegate (combobox) - */ -class HYDROGUI_PriorityWidget::Delegate : public QStyledItemDelegate -{ -public: - Delegate( QObject* theParent = 0 ); - - QWidget* createEditor( QWidget*, const QStyleOptionViewItem&, - const QModelIndex& ) const; - - void setEditorData( QWidget*, const QModelIndex& ) const; - void setModelData( QWidget*, QAbstractItemModel*, const QModelIndex& ) const; -}; - /** Constructor. @param theParent the parent object @@ -73,11 +58,12 @@ QWidget* HYDROGUI_PriorityWidget::Delegate::createEditor( aComboBox->addItem( aText, aMap.value( aText ).toInt() ); } } else if ( theIndex.column() == 0 || theIndex.column() == 2 ) { - QStringList anItems = theIndex.data( Qt::UserRole ).toStringList(); QStringList anObjNames = theIndex.data( Qt::UserRole ).toStringList(); aComboBox->addItems( anObjNames ); } + connect( aComboBox, SIGNAL( activated( int ) ), this, SLOT( finishEditing() ) ); + return aComboBox; } @@ -126,6 +112,18 @@ void HYDROGUI_PriorityWidget::Delegate::setModelData( } } +/** + Emit signal indicating that the user has finished editing. + */ +void HYDROGUI_PriorityWidget::Delegate::finishEditing() +{ + QWidget* anEditor = qobject_cast( sender() ); + if ( anEditor ) { + emit commitData( anEditor ); + emit closeEditor( anEditor ); + } +} + /** Constructor. @@ -150,12 +148,23 @@ HYDROGUI_PriorityWidget::HYDROGUI_PriorityWidget( QWidget* theParent ) // Table view myTable = new QTableView( this ); myTable->setItemDelegate( new Delegate( this ) ); - myTable->setEditTriggers( QAbstractItemView::DoubleClicked | QAbstractItemView::SelectedClicked ); - + myTable->setEditTriggers( QAbstractItemView::DoubleClicked | + QAbstractItemView::SelectedClicked | + QAbstractItemView::EditKeyPressed ); + // Set the custom model HYDROGUI_PriorityTableModel* aModel = new HYDROGUI_PriorityTableModel(); myTable->setModel( aModel ); + // Set resize mode + myTable->horizontalHeader()->setStretchLastSection( false); + myTable->horizontalHeader()->setResizeMode( 0, QHeaderView::Stretch ); + myTable->horizontalHeader()->setResizeMode( 1, QHeaderView::ResizeToContents ); + myTable->horizontalHeader()->setResizeMode( 2, QHeaderView::Stretch ); + myTable->horizontalHeader()->setResizeMode( 3, QHeaderView::ResizeToContents ); + + myTable->verticalHeader()->setResizeMode( QHeaderView::ResizeToContents ); + // Layout // buttons QHBoxLayout* aButtonsLayout = new QHBoxLayout(); @@ -301,9 +310,6 @@ void HYDROGUI_PriorityWidget::updateControls() myAdd->setEnabled( aModel->canCreateNewRule() ); bool isTableNotEmpty = aModel->rowCount() > 0; myClear->setEnabled( isTableNotEmpty ); - if ( isTableNotEmpty ) { - myTable->resizeColumnsToContents(); - } } onSelectionChanged(); } @@ -312,5 +318,5 @@ void HYDROGUI_PriorityWidget::updateControls() Show error message. */ void HYDROGUI_PriorityWidget::onShowError( const QString& theMsg ) { - SUIT_MessageBox::critical( this, tr( "ERROR" ), theMsg ); + SUIT_MessageBox::warning( this, tr( "INCORRECT_INPUT" ), theMsg ); } \ No newline at end of file diff --git a/src/HYDROGUI/HYDROGUI_PriorityWidget.h b/src/HYDROGUI/HYDROGUI_PriorityWidget.h index 39b45a3b..4162327c 100644 --- a/src/HYDROGUI/HYDROGUI_PriorityWidget.h +++ b/src/HYDROGUI/HYDROGUI_PriorityWidget.h @@ -28,6 +28,7 @@ #include #include +#include #include class QTableView; @@ -74,4 +75,25 @@ private: QToolButton* myClear; ///< the clear all rules button }; +/** + * \class HYDROGUI_PriorityWidget::Delegate + * \brief The class representing custom item delegate (combobox) + */ +class HYDROGUI_PriorityWidget::Delegate : public QStyledItemDelegate +{ + Q_OBJECT + +public: + Delegate( QObject* theParent = 0 ); + + QWidget* createEditor( QWidget*, const QStyleOptionViewItem&, + const QModelIndex& ) const; + + void setEditorData( QWidget*, const QModelIndex& ) const; + void setModelData( QWidget*, QAbstractItemModel*, const QModelIndex& ) const; + +protected slots: + void finishEditing(); +}; + #endif -- 2.39.2