mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
AppFwk : ComboBox : Add previous/next buttons, controlled by attributes
This commit is contained in:
parent
e388a58fae
commit
c001a0008f
@ -43,6 +43,7 @@
|
|||||||
|
|
||||||
#include "cafFactory.h"
|
#include "cafFactory.h"
|
||||||
|
|
||||||
|
#include <QApplication>
|
||||||
#include <QComboBox>
|
#include <QComboBox>
|
||||||
#include <QLabel>
|
#include <QLabel>
|
||||||
#include <QWheelEvent>
|
#include <QWheelEvent>
|
||||||
@ -63,6 +64,14 @@ void PdmUiComboBoxEditor::configureAndUpdateUi(const QString& uiConfigName)
|
|||||||
PdmUiFieldEditorHandle::updateLabelFromField(m_label, uiConfigName);
|
PdmUiFieldEditorHandle::updateLabelFromField(m_label, uiConfigName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Handle attributes
|
||||||
|
PdmUiComboBoxEditorAttribute attributes;
|
||||||
|
caf::PdmUiObjectHandle* uiObject = uiObj(field()->fieldHandle()->ownerObject());
|
||||||
|
if (uiObject)
|
||||||
|
{
|
||||||
|
uiObject->editorAttribute(field()->fieldHandle(), uiConfigName, &attributes);
|
||||||
|
}
|
||||||
|
|
||||||
if (!m_comboBox.isNull())
|
if (!m_comboBox.isNull())
|
||||||
{
|
{
|
||||||
m_comboBox->setEnabled(!field()->isUiReadOnly(uiConfigName));
|
m_comboBox->setEnabled(!field()->isUiReadOnly(uiConfigName));
|
||||||
@ -87,14 +96,6 @@ void PdmUiComboBoxEditor::configureAndUpdateUi(const QString& uiConfigName)
|
|||||||
m_comboBox->setCurrentIndex(0);
|
m_comboBox->setCurrentIndex(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle attributes
|
|
||||||
PdmUiComboBoxEditorAttribute attributes;
|
|
||||||
caf::PdmUiObjectHandle* uiObject = uiObj(field()->fieldHandle()->ownerObject());
|
|
||||||
if (uiObject)
|
|
||||||
{
|
|
||||||
uiObject->editorAttribute(field()->fieldHandle(), uiConfigName, &attributes);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (attributes.adjustWidthToContents)
|
if (attributes.adjustWidthToContents)
|
||||||
{
|
{
|
||||||
m_comboBox->setSizeAdjustPolicy(QComboBox::AdjustToContents);
|
m_comboBox->setSizeAdjustPolicy(QComboBox::AdjustToContents);
|
||||||
@ -102,6 +103,43 @@ void PdmUiComboBoxEditor::configureAndUpdateUi(const QString& uiConfigName)
|
|||||||
|
|
||||||
m_comboBox->blockSignals(false);
|
m_comboBox->blockSignals(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (attributes.showPreviousAndNextButtons)
|
||||||
|
{
|
||||||
|
if (m_previousItemButton.isNull())
|
||||||
|
{
|
||||||
|
m_previousItemButton = new QToolButton(m_placeholder);
|
||||||
|
connect(m_previousItemButton, SIGNAL(clicked()), this, SLOT(slotPreviousButtonPressed()));
|
||||||
|
|
||||||
|
m_previousItemButton->setToolTip("Previous");
|
||||||
|
m_previousItemButton->setIcon(QApplication::style()->standardIcon(QStyle::SP_ArrowUp));
|
||||||
|
}
|
||||||
|
if (m_nextItemButton.isNull())
|
||||||
|
{
|
||||||
|
m_nextItemButton = new QToolButton(m_placeholder);
|
||||||
|
connect(m_nextItemButton, SIGNAL(clicked()), this, SLOT(slotNextButtonPressed()));
|
||||||
|
|
||||||
|
m_nextItemButton->setToolTip("Next");
|
||||||
|
m_nextItemButton->setIcon(QApplication::style()->standardIcon(QStyle::SP_ArrowDown));
|
||||||
|
}
|
||||||
|
|
||||||
|
m_layout->insertWidget(1, m_previousItemButton);
|
||||||
|
m_layout->insertWidget(2, m_nextItemButton);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (m_previousItemButton)
|
||||||
|
{
|
||||||
|
m_layout->removeWidget(m_previousItemButton);
|
||||||
|
m_previousItemButton->deleteLater();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (m_nextItemButton)
|
||||||
|
{
|
||||||
|
m_layout->removeWidget(m_nextItemButton);
|
||||||
|
m_nextItemButton->deleteLater();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
@ -162,9 +200,16 @@ QWidget* PdmUiComboBoxEditor::createEditorWidget(QWidget * parent)
|
|||||||
m_comboBox = new CustomQComboBox(parent);
|
m_comboBox = new CustomQComboBox(parent);
|
||||||
m_comboBox->setFocusPolicy(Qt::StrongFocus);
|
m_comboBox->setFocusPolicy(Qt::StrongFocus);
|
||||||
|
|
||||||
|
m_placeholder = new QWidget(parent);
|
||||||
|
|
||||||
|
m_layout = new QHBoxLayout(m_placeholder);
|
||||||
|
m_layout->setContentsMargins(0,0,0,0);
|
||||||
|
m_layout->setSpacing(0);
|
||||||
|
m_layout->addWidget(m_comboBox);
|
||||||
|
|
||||||
connect(m_comboBox, SIGNAL(activated(int)), this, SLOT(slotIndexActivated(int)));
|
connect(m_comboBox, SIGNAL(activated(int)), this, SLOT(slotIndexActivated(int)));
|
||||||
|
|
||||||
return m_comboBox;
|
return m_placeholder;
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
@ -190,4 +235,30 @@ void PdmUiComboBoxEditor::slotIndexActivated(int index)
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
void PdmUiComboBoxEditor::slotNextButtonPressed()
|
||||||
|
{
|
||||||
|
int indexCandidate = m_comboBox->currentIndex() + 1;
|
||||||
|
|
||||||
|
if (indexCandidate < m_comboBox->count())
|
||||||
|
{
|
||||||
|
slotIndexActivated(indexCandidate);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
///
|
||||||
|
//--------------------------------------------------------------------------------------------------
|
||||||
|
void PdmUiComboBoxEditor::slotPreviousButtonPressed()
|
||||||
|
{
|
||||||
|
int indexCandidate = m_comboBox->currentIndex() - 1;
|
||||||
|
|
||||||
|
if (indexCandidate > -1 && indexCandidate < m_comboBox->count())
|
||||||
|
{
|
||||||
|
slotIndexActivated(indexCandidate);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
} // end namespace caf
|
} // end namespace caf
|
||||||
|
@ -39,12 +39,14 @@
|
|||||||
|
|
||||||
#include "cafPdmUiFieldEditorHandle.h"
|
#include "cafPdmUiFieldEditorHandle.h"
|
||||||
|
|
||||||
#include <QString>
|
|
||||||
#include <QWidget>
|
|
||||||
#include <QPointer>
|
|
||||||
#include <QComboBox>
|
|
||||||
#include <QLabel>
|
|
||||||
|
|
||||||
|
#include <QComboBox>
|
||||||
|
#include <QHBoxLayout>
|
||||||
|
#include <QLabel>
|
||||||
|
#include <QPointer>
|
||||||
|
#include <QString>
|
||||||
|
#include <QToolButton>
|
||||||
|
#include <QWidget>
|
||||||
|
|
||||||
namespace caf
|
namespace caf
|
||||||
{
|
{
|
||||||
@ -56,12 +58,15 @@ namespace caf
|
|||||||
class PdmUiComboBoxEditorAttribute : public PdmUiEditorAttribute
|
class PdmUiComboBoxEditorAttribute : public PdmUiEditorAttribute
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
bool adjustWidthToContents;
|
|
||||||
|
|
||||||
PdmUiComboBoxEditorAttribute()
|
PdmUiComboBoxEditorAttribute()
|
||||||
{
|
{
|
||||||
adjustWidthToContents = false;
|
adjustWidthToContents = false;
|
||||||
|
showPreviousAndNextButtons = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public:
|
||||||
|
bool adjustWidthToContents;
|
||||||
|
bool showPreviousAndNextButtons;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@ -82,9 +87,17 @@ protected:
|
|||||||
protected slots:
|
protected slots:
|
||||||
void slotIndexActivated(int index);
|
void slotIndexActivated(int index);
|
||||||
|
|
||||||
|
void slotNextButtonPressed();
|
||||||
|
void slotPreviousButtonPressed();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QPointer<QComboBox> m_comboBox;
|
QPointer<QComboBox> m_comboBox;
|
||||||
QPointer<QLabel> m_label;
|
QPointer<QLabel> m_label;
|
||||||
|
|
||||||
|
QPointer<QToolButton> m_previousItemButton;
|
||||||
|
QPointer<QToolButton> m_nextItemButton;
|
||||||
|
QPointer<QHBoxLayout> m_layout;
|
||||||
|
QPointer<QWidget> m_placeholder;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user