mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
Merge branch 'dev' into pre-proto
This commit is contained in:
@@ -37,9 +37,12 @@ PdmUiObjectHandle* uiObj(PdmObjectHandle* obj)
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void PdmUiObjectHandle::uiOrdering(QString uiConfigName, PdmUiOrdering& uiOrdering)
|
||||
{
|
||||
#if 1
|
||||
// Restore state for includeRemainingFields, as this flag
|
||||
// can be changed in defineUiOrdering()
|
||||
bool includeRemaining_originalState = uiOrdering.isIncludingRemainingFields();
|
||||
|
||||
this->defineUiOrdering(uiConfigName, uiOrdering);
|
||||
if (!uiOrdering.forgetRemainingFields())
|
||||
if (uiOrdering.isIncludingRemainingFields())
|
||||
{
|
||||
// Add the remaining Fields To UiConfig
|
||||
std::vector<PdmFieldHandle*> fields;
|
||||
@@ -53,7 +56,11 @@ void PdmUiObjectHandle::uiOrdering(QString uiConfigName, PdmUiOrdering& uiOrderi
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
// Restore incoming value
|
||||
uiOrdering.skipRemainingFields(!includeRemaining_originalState);
|
||||
|
||||
CAF_ASSERT(includeRemaining_originalState == uiOrdering.isIncludingRemainingFields());
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@@ -103,7 +110,7 @@ PdmUiTreeOrdering* PdmUiObjectHandle::uiTreeOrdering(QString uiConfigName /*= ""
|
||||
void PdmUiObjectHandle::addDefaultUiTreeChildren(PdmUiTreeOrdering* uiTreeOrdering)
|
||||
{
|
||||
#if 1
|
||||
if (!uiTreeOrdering->forgetRemainingFields())
|
||||
if (uiTreeOrdering->isIncludingRemainingChildren())
|
||||
{
|
||||
// Add the remaining Fields To UiConfig
|
||||
std::vector<PdmFieldHandle*> fields;
|
||||
|
||||
@@ -111,5 +111,29 @@ void PdmUiOrdering::add(const PdmObjectHandle* obj)
|
||||
m_ordering.push_back(uiItem);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool PdmUiOrdering::isIncludingRemainingFields() const
|
||||
{
|
||||
return !m_skipRemainingFields;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void PdmUiOrdering::skipRemainingFields(bool doSkip /*= true*/)
|
||||
{
|
||||
m_skipRemainingFields = doSkip;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
const std::vector<PdmUiItem*>& PdmUiOrdering::uiItems() const
|
||||
{
|
||||
return m_ordering;
|
||||
}
|
||||
|
||||
} //End of namespace caf
|
||||
|
||||
|
||||
@@ -55,7 +55,7 @@ class PdmObjectHandle;
|
||||
class PdmUiOrdering
|
||||
{
|
||||
public:
|
||||
PdmUiOrdering(): m_forgetRemainingFields(false) { };
|
||||
PdmUiOrdering(): m_skipRemainingFields(false) { };
|
||||
virtual ~PdmUiOrdering();
|
||||
|
||||
PdmUiOrdering(const PdmUiOrdering&) = delete;
|
||||
@@ -63,30 +63,48 @@ public:
|
||||
|
||||
PdmUiGroup* addNewGroup(QString displayName);
|
||||
|
||||
/// HACK constness of this class and functions must be revisited
|
||||
//void add(const PdmUiItem* item) { m_ordering.push_back(const_cast<PdmUiItem*>(item)); }
|
||||
void add(const PdmFieldHandle* field);
|
||||
void add(const PdmObjectHandle* obj);
|
||||
|
||||
bool forgetRemainingFields() const { return m_forgetRemainingFields; }
|
||||
void setForgetRemainingFields(bool val) { m_forgetRemainingFields = val; }
|
||||
void skipRemainingFields(bool doSkip = true);
|
||||
|
||||
const std::vector<PdmUiItem*>& uiItems() const { return m_ordering; }
|
||||
// Pdm internal methods
|
||||
|
||||
const std::vector<PdmUiItem*>& uiItems() const;
|
||||
bool contains(const PdmUiItem* item) const;
|
||||
bool isIncludingRemainingFields() const;
|
||||
|
||||
private:
|
||||
std::vector<PdmUiItem*> m_ordering; ///< The order of groups and fields
|
||||
std::vector<PdmUiGroup*> m_createdGroups; ///< Owned PdmUiGroups, for mem management
|
||||
bool m_forgetRemainingFields;
|
||||
std::vector<PdmUiItem*> m_ordering; ///< The order of groups and fields
|
||||
std::vector<PdmUiGroup*> m_createdGroups; ///< Owned PdmUiGroups, for memory management only
|
||||
bool m_skipRemainingFields;
|
||||
};
|
||||
|
||||
//==================================================================================================
|
||||
/// Class representing a group of fields
|
||||
/// Class representing a group of fields communicated to the Gui
|
||||
//==================================================================================================
|
||||
|
||||
class PdmUiGroup : public PdmUiItem, public PdmUiOrdering
|
||||
{
|
||||
public:
|
||||
PdmUiGroup() { m_isCollapsedByDefault = false; m_hasForcedExpandedState = false; m_forcedCollapseState = false;}
|
||||
|
||||
virtual bool isUiGroup() { return true; }
|
||||
|
||||
/// Set this group to be collapsed by default. When the user expands the group, the default no longer has any effect.
|
||||
void setCollapsedByDefault(bool doCollapse) { m_isCollapsedByDefault = doCollapse;}
|
||||
/// Forcifully set the collapsed state of the group, overriding the previous user actions and the default
|
||||
void setCollapsed(bool doCollapse) { m_hasForcedExpandedState = true; m_forcedCollapseState = doCollapse;}
|
||||
|
||||
// Pdm internal methods
|
||||
bool isExpandedByDefault() const { return !m_isCollapsedByDefault;}
|
||||
bool hasForcedExpandedState() const { return m_hasForcedExpandedState;}
|
||||
bool forcedExpandedState() const { return !m_forcedCollapseState;}
|
||||
|
||||
private:
|
||||
bool m_isCollapsedByDefault;
|
||||
bool m_hasForcedExpandedState;
|
||||
bool m_forcedCollapseState;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -76,9 +76,9 @@ public:
|
||||
void add(PdmObjectHandle* object);
|
||||
PdmUiTreeOrdering* add(const QString & title, const QString& iconResourceName );
|
||||
|
||||
/// If the rest of the fields containing children is supposed to be omitted, setForgetRemainingFileds to true.
|
||||
void setForgetRemainingFields(bool val) { m_forgetRemainingFields = val; }
|
||||
/// To stop the tree generation at this level, doIgnoreSubTree to true
|
||||
/// If the rest of the fields containing children is supposed to be omitted, set skipRemainingFields to true.
|
||||
void skipRemainingChildren(bool doSkip = true) { m_forgetRemainingFields = doSkip; }
|
||||
/// To stop the tree generation at this level, setIgnoreSubTree to true
|
||||
void setIgnoreSubTree(bool doIgnoreSubTree ) { m_isToIgnoreSubTree = doIgnoreSubTree; }
|
||||
|
||||
// Testing for the PdmItem being represented
|
||||
@@ -89,7 +89,7 @@ public:
|
||||
|
||||
// Access to the PdmItem being represented
|
||||
PdmUiItem* activeItem() const;
|
||||
PdmObjectHandle* object() const;
|
||||
PdmObjectHandle* object() const;
|
||||
PdmFieldHandle* field() const;
|
||||
PdmUiItem* uiItem() const;
|
||||
|
||||
@@ -104,8 +104,8 @@ public:
|
||||
|
||||
private:
|
||||
friend class PdmObjectHandle; friend class PdmUiObjectHandle;
|
||||
bool forgetRemainingFields() const { return m_forgetRemainingFields; }
|
||||
bool ignoreSubTree() const { return m_isToIgnoreSubTree; }
|
||||
bool isIncludingRemainingChildren() const { return !m_forgetRemainingFields; }
|
||||
bool ignoreSubTree() const { return m_isToIgnoreSubTree; }
|
||||
bool containsField(const PdmFieldHandle* field);
|
||||
bool containsObject(const PdmObjectHandle* object);
|
||||
void appendChild( PdmUiTreeOrdering* child);
|
||||
|
||||
@@ -23,6 +23,7 @@ set( QOBJECT_HEADERS
|
||||
cafPdmUiCheckBoxTristateEditor.h
|
||||
cafPdmUiColorEditor.h
|
||||
cafPdmUiComboBoxEditor.h
|
||||
cafPdmUiDefaultObjectEditor.h
|
||||
cafPdmUiDoubleSliderEditor.h
|
||||
cafPdmUiFilePathEditor.h
|
||||
cafPdmUiLineEditor.h
|
||||
@@ -42,6 +43,7 @@ set( QOBJECT_HEADERS
|
||||
cafPdmUiTreeViewModel.h
|
||||
cafPdmUiTreeViewEditor.h
|
||||
cafUiProcess.h
|
||||
QMinimizePanel.h
|
||||
)
|
||||
|
||||
if ( (${CMAKE_VERSION} VERSION_LESS 2.8.6) OR (NOT CMAKE_AUTOMOC) )
|
||||
@@ -121,6 +123,8 @@ set( PROJECT_FILES
|
||||
cafProgressInfo.h
|
||||
cafUiProcess.cpp
|
||||
cafUiProcess.h
|
||||
QMinimizePanel.cpp
|
||||
QMinimizePanel.h
|
||||
)
|
||||
|
||||
add_library( ${PROJECT_NAME}
|
||||
@@ -137,7 +141,7 @@ target_link_libraries ( ${PROJECT_NAME}
|
||||
${QT_LIBRARIES}
|
||||
)
|
||||
|
||||
if (CAF_USE_COTIRE)
|
||||
if (COMMAND cotire)
|
||||
cotire(${PROJECT_NAME})
|
||||
|
||||
# make sure the unity target is included in the active builds to trigger rebuild before debug
|
||||
|
||||
295
Fwk/AppFwk/cafUserInterface/QMinimizePanel.cpp
Normal file
295
Fwk/AppFwk/cafUserInterface/QMinimizePanel.cpp
Normal file
@@ -0,0 +1,295 @@
|
||||
//##################################################################################################
|
||||
//
|
||||
// QMinimizePanel
|
||||
// Copyright (C) 2017 Ceetron Solutions AS
|
||||
//
|
||||
// This class may be used under the terms of either the GNU General Public License or
|
||||
// the GNU Lesser General Public License as follows:
|
||||
//
|
||||
// GNU General Public License Usage
|
||||
// This library is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
// FITNESS FOR A PARTICULAR PURPOSE.
|
||||
//
|
||||
// See the GNU General Public License at <<http://www.gnu.org/licenses/gpl.html>>
|
||||
// for more details.
|
||||
//
|
||||
// GNU Lesser General Public License Usage
|
||||
// This library is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Lesser General Public License as published by
|
||||
// the Free Software Foundation; either version 2.1 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
// FITNESS FOR A PARTICULAR PURPOSE.
|
||||
//
|
||||
// See the GNU Lesser General Public License at <<http://www.gnu.org/licenses/lgpl-2.1.html>>
|
||||
// for more details.
|
||||
//
|
||||
//##################################################################################################
|
||||
|
||||
#include "QMinimizePanel.h"
|
||||
|
||||
#include <QApplication>
|
||||
#include <QFrame>
|
||||
#include <QLabel>
|
||||
#include <QPixmap>
|
||||
#include <QPushButton>
|
||||
#include <QResizeEvent>
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
|
||||
static const struct {
|
||||
unsigned int width;
|
||||
unsigned int height;
|
||||
unsigned int bytes_per_pixel; /* 2:RGB16, 3:RGB, 4:RGBA */
|
||||
unsigned char pixel_data[7 * 10 * 4 + 1];
|
||||
} expandDownArrow = {
|
||||
7, 10, 4,
|
||||
"QRY\317445A\0\0\0\0\0\0\0\0\0\0\0\0""445AJJN\317OQW\256OPW\317445#\0\0\0"
|
||||
"\0""445#IJP\317HIN\256445#MOT\317LMS\317445#IJP\317GHM\317445#\0\0\0\0""4"
|
||||
"45#DEK\317??C\317BBG\317445#\0\0\0\0\0\0\0\0\0\0\0\0""445#>?B\317445#\0\0"
|
||||
"\0\0\0\0\0\0LNT\317445A\0\0\0\0\0\0\0\0\0\0\0\0""445ACEI\317JKR\256IJP\317"
|
||||
"445#\0\0\0\0""445#DEH\317BCJ\256445#GHO\317EGK\317445#DEH\317BDI\317445#"
|
||||
"\0\0\0\0""445#@AE\317??C\317??B\317445#\0\0\0\0\0\0\0\0\0\0\0\0""445#<<?"
|
||||
"\317445#\0\0\0\0\0\0\0\0",
|
||||
};
|
||||
|
||||
QIcon createExpandDownIcon()
|
||||
{
|
||||
QImage img(expandDownArrow.pixel_data,expandDownArrow.width, expandDownArrow.height, QImage::Format_ARGB32 );
|
||||
QPixmap pxMap;
|
||||
pxMap = QPixmap::fromImage(img);
|
||||
|
||||
return QIcon(pxMap);
|
||||
}
|
||||
|
||||
static const QIcon& expandDownIcon()
|
||||
{
|
||||
static QIcon expandDownIcon(createExpandDownIcon());
|
||||
return expandDownIcon;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
|
||||
static const struct {
|
||||
unsigned int width;
|
||||
unsigned int height;
|
||||
unsigned int bytes_per_pixel; /* 2:RGB16, 3:RGB, 4:RGBA */
|
||||
unsigned char pixel_data[7 * 10 * 4 + 1];
|
||||
} expandUpArrow = {
|
||||
7, 10, 4,
|
||||
"\0\0\0\0\0\0\0\0""445#<<?\317445#\0\0\0\0\0\0\0\0\0\0\0\0""445#@AE\317??"
|
||||
"C\317??B\317445#\0\0\0\0""445#GHO\317EGK\317445#DEH\317BDI\317445#JKR\256"
|
||||
"IJP\317445#\0\0\0\0""445#DEH\317BCJ\256LNT\317445A\0\0\0\0\0\0\0\0\0\0\0"
|
||||
"\0""445ACEI\317\0\0\0\0\0\0\0\0""445#>?B\317445#\0\0\0\0\0\0\0\0\0\0\0\0"
|
||||
"""445#DEK\317??C\317BBG\317445#\0\0\0\0""445#MOT\317LMS\317445#IJP\317GH"
|
||||
"M\317445#OQW\256OPW\317445#\0\0\0\0""445#IJP\317HIN\256QRY\317445A\0\0\0"
|
||||
"\0\0\0\0\0\0\0\0\0""445AJJN\317",
|
||||
};
|
||||
|
||||
QIcon createExpandUpIcon()
|
||||
{
|
||||
QImage img(expandUpArrow.pixel_data,expandUpArrow.width, expandUpArrow.height, QImage::Format_ARGB32 );
|
||||
QPixmap pxMap;
|
||||
pxMap = QPixmap::fromImage(img);
|
||||
|
||||
return QIcon(pxMap);
|
||||
}
|
||||
|
||||
static const QIcon& expandUpIcon()
|
||||
{
|
||||
static QIcon expandUpIcon(createExpandUpIcon());
|
||||
return expandUpIcon;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QMinimizePanel::QMinimizePanel(QWidget* parent/*=0*/)
|
||||
{
|
||||
this->initialize("");
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QMinimizePanel::QMinimizePanel(const QString &title, QWidget* parent/*=0*/)
|
||||
{
|
||||
this->initialize(title);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void QMinimizePanel::initialize(const QString &title)
|
||||
{
|
||||
m_titleFrame = new QFrame(this);
|
||||
m_titleFrame->setFrameStyle(QFrame::Box | QFrame::Plain);
|
||||
m_titleFrame->setAutoFillBackground(true);
|
||||
|
||||
{
|
||||
QLinearGradient titleGrad(QPointF(0, 0), QPointF(0, 1));
|
||||
titleGrad.setCoordinateMode(QGradient::StretchToDeviceMode);
|
||||
titleGrad.setColorAt(0, QColor(255, 255, 255, 20));
|
||||
titleGrad.setColorAt(1, QColor(0, 0, 0, 30));
|
||||
|
||||
QPalette titleFramePalette = m_titleFrame->palette();
|
||||
titleFramePalette.setBrush(QPalette::Window, titleGrad);
|
||||
titleFramePalette.setBrush(QPalette::Foreground, titleFramePalette.dark());
|
||||
m_titleFrame->setPalette(titleFramePalette);
|
||||
}
|
||||
|
||||
m_titleLabel = new QLabel(title, m_titleFrame);
|
||||
m_titleLabel->setPalette(QApplication::palette()); // To avoid title foreground color bleeding through
|
||||
|
||||
m_collapseButton = new QPushButton( m_titleFrame);
|
||||
m_collapseButton->setFlat(true);
|
||||
m_collapseButton->setIcon(expandUpIcon());
|
||||
|
||||
m_contentFrame = new QFrame(this);
|
||||
m_contentFrame->setFrameStyle(QFrame::StyledPanel | QFrame::Plain);
|
||||
m_contentFrame->setAutoFillBackground(true);
|
||||
|
||||
QPalette contentFramePalette = m_contentFrame->palette();
|
||||
contentFramePalette.setBrush(QPalette::Window, QColor(255,250,250,85));
|
||||
m_contentFrame->setPalette(contentFramePalette);
|
||||
|
||||
connect(m_collapseButton, SIGNAL(clicked()),this, SLOT(toggleExpanded()) );
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QMinimizePanel::~QMinimizePanel()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void QMinimizePanel::setTitle(const QString& title)
|
||||
{
|
||||
m_titleLabel->setText(title);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QString QMinimizePanel::title() const
|
||||
{
|
||||
return m_titleLabel->text();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QSize QMinimizePanel::sizeHint() const
|
||||
{
|
||||
QSize labelSize = m_titleLabel->sizeHint();
|
||||
QSize titleBarHint = labelSize + QSize(4 + labelSize.height() + 8 - 2 + 1, 8);
|
||||
|
||||
if (!m_contentFrame->isHidden())
|
||||
{
|
||||
QSize titleBarMin(0, labelSize.height() + 8);
|
||||
QSize contentsMin(m_contentFrame->sizeHint());
|
||||
QSize total = contentsMin.expandedTo(titleBarMin);
|
||||
total.rheight() += titleBarMin.height();
|
||||
|
||||
return total;
|
||||
}
|
||||
else
|
||||
{
|
||||
return titleBarHint;
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void QMinimizePanel::setExpanded(bool isExpanded)
|
||||
{
|
||||
if (m_contentFrame->isHidden() != isExpanded) return;
|
||||
|
||||
m_contentFrame->setVisible(isExpanded);
|
||||
isExpanded ? m_collapseButton->setIcon(expandUpIcon()) : m_collapseButton->setIcon(expandDownIcon());
|
||||
this->QWidget::updateGeometry();
|
||||
|
||||
emit expandedChanged(isExpanded);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void QMinimizePanel::toggleExpanded()
|
||||
{
|
||||
setExpanded(m_contentFrame->isHidden());
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QSize QMinimizePanel::minimumSizeHint() const
|
||||
{
|
||||
QSize labelSize = m_titleLabel->sizeHint();
|
||||
QSize titleBarHint = labelSize + QSize(4 + labelSize.height() + 8 - 2 + 1, 8);
|
||||
|
||||
if (!m_contentFrame->isHidden())
|
||||
{
|
||||
QSize titleBarMin(0, labelSize.height() + 8 );
|
||||
QSize contentsMin(m_contentFrame->minimumSizeHint());
|
||||
QSize total = contentsMin.expandedTo(titleBarMin);
|
||||
total.rheight() += titleBarMin.height();
|
||||
|
||||
return total;
|
||||
}
|
||||
else
|
||||
{
|
||||
return titleBarHint;
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void QMinimizePanel::resizeEvent(QResizeEvent *resizeEv )
|
||||
{
|
||||
QWidget::updateGeometry();
|
||||
|
||||
int width = resizeEv->size().width();
|
||||
int heigth = resizeEv->size().height();
|
||||
int labelHeight = m_titleLabel->sizeHint().height();
|
||||
int titleHeight = labelHeight + 8;
|
||||
|
||||
int buttonSize = titleHeight - 2;
|
||||
|
||||
m_titleFrame->setGeometry(0,0,width, titleHeight);
|
||||
m_titleLabel->setGeometry( 4, titleHeight - labelHeight - 4, width - 4 - buttonSize - 1, labelHeight);
|
||||
m_collapseButton->setGeometry(width - buttonSize - 1, 1, buttonSize, buttonSize);
|
||||
|
||||
m_contentFrame->setGeometry(0, titleHeight-1, width, heigth - (titleHeight-1));
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool QMinimizePanel::event(QEvent* event)
|
||||
{
|
||||
if (event->type() == QEvent::LayoutRequest)
|
||||
{
|
||||
this->QWidget::updateGeometry();
|
||||
}
|
||||
|
||||
return this->QWidget::event(event);
|
||||
}
|
||||
85
Fwk/AppFwk/cafUserInterface/QMinimizePanel.h
Normal file
85
Fwk/AppFwk/cafUserInterface/QMinimizePanel.h
Normal file
@@ -0,0 +1,85 @@
|
||||
//##################################################################################################
|
||||
//
|
||||
// QMinimizePanel
|
||||
// Copyright (C) 2017 Ceetron Solutions AS
|
||||
//
|
||||
// This class may be used under the terms of either the GNU General Public License or
|
||||
// the GNU Lesser General Public License as follows:
|
||||
//
|
||||
// GNU General Public License Usage
|
||||
// This library is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
// FITNESS FOR A PARTICULAR PURPOSE.
|
||||
//
|
||||
// See the GNU General Public License at <<http://www.gnu.org/licenses/gpl.html>>
|
||||
// for more details.
|
||||
//
|
||||
// GNU Lesser General Public License Usage
|
||||
// This library is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Lesser General Public License as published by
|
||||
// the Free Software Foundation; either version 2.1 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful, but WITHOUT ANY
|
||||
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
// FITNESS FOR A PARTICULAR PURPOSE.
|
||||
//
|
||||
// See the GNU Lesser General Public License at <<http://www.gnu.org/licenses/lgpl-2.1.html>>
|
||||
// for more details.
|
||||
//
|
||||
//##################################################################################################
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QWidget>
|
||||
|
||||
class QFrame;
|
||||
class QLabel;
|
||||
class QPushButton;
|
||||
|
||||
//==================================================================================================
|
||||
//
|
||||
//
|
||||
//
|
||||
//==================================================================================================
|
||||
class QMinimizePanel : public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit QMinimizePanel(QWidget* parent=0);
|
||||
explicit QMinimizePanel(const QString &title, QWidget* parent=0);
|
||||
~QMinimizePanel();
|
||||
|
||||
QFrame* contentFrame() { return m_contentFrame; }
|
||||
void setTitle (const QString& title);
|
||||
QString title() const;
|
||||
|
||||
virtual QSize sizeHint() const override;
|
||||
|
||||
public slots:
|
||||
void setExpanded(bool isExpanded);
|
||||
void toggleExpanded();
|
||||
|
||||
signals:
|
||||
void expandedChanged(bool isExpanded);
|
||||
|
||||
public:
|
||||
virtual QSize minimumSizeHint() const override;
|
||||
|
||||
protected:
|
||||
QFrame* m_titleFrame;
|
||||
QLabel* m_titleLabel;
|
||||
QPushButton* m_collapseButton;
|
||||
QFrame* m_contentFrame;
|
||||
|
||||
virtual void resizeEvent(QResizeEvent *) override;
|
||||
virtual bool event(QEvent* event) override; // To catch QEvent::LayoutRequest
|
||||
|
||||
private:
|
||||
void initialize(const QString &title);
|
||||
};
|
||||
@@ -157,8 +157,8 @@ void PdmUiDefaultObjectEditor::configureAndUpdateUi(const QString& uiConfigName)
|
||||
|
||||
// Remove all unmentioned group boxes
|
||||
|
||||
std::map<QString, QPointer<QGroupBox> >::iterator itOld;
|
||||
std::map<QString, QPointer<QGroupBox> >::iterator itNew;
|
||||
std::map<QString, QPointer<QMinimizePanel> >::iterator itOld;
|
||||
std::map<QString, QPointer<QMinimizePanel> >::iterator itNew;
|
||||
|
||||
for (itOld = m_groupBoxes.begin(); itOld != m_groupBoxes.end(); ++itOld )
|
||||
{
|
||||
@@ -187,7 +187,7 @@ void PdmUiDefaultObjectEditor::cleanupBeforeSettingPdmObject()
|
||||
|
||||
m_newGroupBoxes.clear();
|
||||
|
||||
std::map<QString, QPointer<QGroupBox> >::iterator groupIt;
|
||||
std::map<QString, QPointer<QMinimizePanel> >::iterator groupIt;
|
||||
for (groupIt = m_groupBoxes.begin(); groupIt != m_groupBoxes.end(); ++groupIt)
|
||||
{
|
||||
if (!groupIt->second.isNull()) groupIt->second->deleteLater();
|
||||
@@ -214,19 +214,20 @@ void PdmUiDefaultObjectEditor::recursiveSetupFieldsAndGroups(const std::vector<P
|
||||
const std::vector<PdmUiItem*>& groupChildren = group->uiItems();
|
||||
|
||||
QString groupBoxKey = uiItems[i]->uiName();
|
||||
QGroupBox* groupBox = NULL;
|
||||
QMinimizePanel* groupBox = NULL;
|
||||
QGridLayout* groupBoxLayout = NULL;
|
||||
|
||||
// Find or create groupBox
|
||||
std::map<QString, QPointer<QGroupBox> >::iterator it;
|
||||
std::map<QString, QPointer<QMinimizePanel> >::iterator it;
|
||||
it = m_groupBoxes.find(groupBoxKey);
|
||||
|
||||
if (it == m_groupBoxes.end())
|
||||
{
|
||||
groupBox = new QGroupBox( parent );
|
||||
groupBox = new QMinimizePanel( parent );
|
||||
groupBox->setTitle(uiItems[i]->uiName());
|
||||
groupBoxLayout = new QGridLayout();
|
||||
groupBox->setLayout(groupBoxLayout);
|
||||
groupBox->contentFrame()->setLayout(groupBoxLayout);
|
||||
connect(groupBox, SIGNAL(expandedChanged(bool)), this, SLOT(groupBoxExpandedStateToggled(bool)));
|
||||
|
||||
m_newGroupBoxes[groupBoxKey] = groupBox;
|
||||
}
|
||||
@@ -235,7 +236,7 @@ void PdmUiDefaultObjectEditor::recursiveSetupFieldsAndGroups(const std::vector<P
|
||||
groupBox = it->second;
|
||||
CAF_ASSERT(groupBox);
|
||||
|
||||
groupBoxLayout = dynamic_cast<QGridLayout*>(groupBox->layout());
|
||||
groupBoxLayout = dynamic_cast<QGridLayout*>(groupBox->contentFrame()->layout());
|
||||
CAF_ASSERT(groupBoxLayout);
|
||||
|
||||
m_newGroupBoxes[groupBoxKey] = groupBox;
|
||||
@@ -244,7 +245,12 @@ void PdmUiDefaultObjectEditor::recursiveSetupFieldsAndGroups(const std::vector<P
|
||||
/// Insert the group box at the correct position of the parent layout
|
||||
|
||||
parentLayout->addWidget(groupBox, currentRowIndex, 0, 1, 2);
|
||||
recursiveSetupFieldsAndGroups(groupChildren, groupBox, groupBoxLayout, uiConfigName);
|
||||
|
||||
// Set Expanded state
|
||||
bool isExpanded = isUiGroupExpanded(group);
|
||||
groupBox->setExpanded(isExpanded);
|
||||
|
||||
recursiveSetupFieldsAndGroups(groupChildren, groupBox->contentFrame(), groupBoxLayout, uiConfigName);
|
||||
currentRowIndex++;
|
||||
}
|
||||
else
|
||||
@@ -358,6 +364,28 @@ void PdmUiDefaultObjectEditor::recursiveSetupFieldsAndGroups(const std::vector<P
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool PdmUiDefaultObjectEditor::isUiGroupExpanded(const PdmUiGroup* uiGroup)
|
||||
{
|
||||
if (uiGroup->hasForcedExpandedState()) return uiGroup->forcedExpandedState();
|
||||
|
||||
auto kwMapPair = m_objectKeywordGroupUiNameExpandedState.find(pdmObject()->xmlCapability()->classKeyword());
|
||||
if ( kwMapPair != m_objectKeywordGroupUiNameExpandedState.end() )
|
||||
{
|
||||
QString uiName = uiGroup->uiName();
|
||||
|
||||
auto uiNameExpStatePair = kwMapPair->second.find(uiName);
|
||||
if ( uiNameExpStatePair != kwMapPair->second.end() )
|
||||
{
|
||||
return uiNameExpStatePair->second;
|
||||
}
|
||||
}
|
||||
|
||||
return uiGroup->isExpandedByDefault();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@@ -447,4 +475,20 @@ caf::PdmUiFieldEditorHandle* PdmUiFieldEditorHelper::fieldEditorForField(PdmUiFi
|
||||
return fieldEditor;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void PdmUiDefaultObjectEditor::groupBoxExpandedStateToggled(bool isExpanded)
|
||||
{
|
||||
if (!this->pdmObject()->xmlCapability()) return;
|
||||
|
||||
QString objKeyword = this->pdmObject()->xmlCapability()->classKeyword();
|
||||
QMinimizePanel* panel = dynamic_cast<QMinimizePanel*>(this->sender());
|
||||
|
||||
if (!panel) return;
|
||||
|
||||
m_objectKeywordGroupUiNameExpandedState[objKeyword][panel->title()] = isExpanded;
|
||||
|
||||
}
|
||||
|
||||
} // end namespace caf
|
||||
|
||||
@@ -45,6 +45,7 @@
|
||||
#include <QPointer>
|
||||
#include <QString>
|
||||
#include <QWidget>
|
||||
#include "QMinimizePanel.h"
|
||||
|
||||
class QGridLayout;
|
||||
|
||||
@@ -52,6 +53,7 @@ namespace caf
|
||||
{
|
||||
class PdmUiFieldEditorHandle;
|
||||
class PdmUiItem;
|
||||
class PdmUiGroup;
|
||||
|
||||
|
||||
class PdmUiFieldEditorHelper
|
||||
@@ -67,6 +69,7 @@ public:
|
||||
|
||||
class PdmUiDefaultObjectEditor : public PdmUiObjectEditorHandle
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
PdmUiDefaultObjectEditor();
|
||||
~PdmUiDefaultObjectEditor();
|
||||
@@ -76,16 +79,22 @@ protected:
|
||||
virtual void configureAndUpdateUi(const QString& uiConfigName) override;
|
||||
virtual void cleanupBeforeSettingPdmObject() override;
|
||||
|
||||
protected slots:
|
||||
void groupBoxExpandedStateToggled(bool isExpanded);
|
||||
|
||||
private:
|
||||
void recursiveSetupFieldsAndGroups(const std::vector<PdmUiItem*>& uiItems, QWidget* parent, QGridLayout* parentLayout, const QString& uiConfigName);
|
||||
void recursiveVerifyUniqueNames(const std::vector<PdmUiItem*>& uiItems, const QString& uiConfigName, std::set<QString>* fieldKeywordNames, std::set<QString>* groupNames);
|
||||
void recursiveSetupFieldsAndGroups(const std::vector<PdmUiItem*>& uiItems, QWidget* parent, QGridLayout* parentLayout, const QString& uiConfigName);
|
||||
bool isUiGroupExpanded(const PdmUiGroup* uiGroup);
|
||||
void recursiveVerifyUniqueNames(const std::vector<PdmUiItem*>& uiItems, const QString& uiConfigName, std::set<QString>* fieldKeywordNames, std::set<QString>* groupNames);
|
||||
|
||||
std::map<PdmFieldHandle*, PdmUiFieldEditorHandle*> m_fieldViews;
|
||||
std::map<QString, QPointer<QGroupBox> > m_groupBoxes;
|
||||
std::map<QString, QPointer<QGroupBox> > m_newGroupBoxes; ///< used temporarily to store the new(complete) set of group boxes
|
||||
std::map<QString, QPointer<QMinimizePanel> > m_groupBoxes;
|
||||
std::map<QString, QPointer<QMinimizePanel> > m_newGroupBoxes; ///< used temporarily to store the new(complete) set of group boxes
|
||||
|
||||
QPointer<QWidget> m_mainWidget;
|
||||
QPointer<QGridLayout> m_layout;
|
||||
QPointer<QWidget> m_mainWidget;
|
||||
QPointer<QGridLayout> m_layout;
|
||||
|
||||
std::map<QString, std::map<QString, bool> > m_objectKeywordGroupUiNameExpandedState;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -58,7 +58,6 @@
|
||||
|
||||
|
||||
|
||||
|
||||
//==================================================================================================
|
||||
/// Helper class used to override flags to disable editable items
|
||||
//==================================================================================================
|
||||
@@ -85,6 +84,45 @@ private:
|
||||
};
|
||||
|
||||
|
||||
//==================================================================================================
|
||||
/// Helper class used to control height of size hint
|
||||
//==================================================================================================
|
||||
class QListViewHeightHint : public QListView
|
||||
{
|
||||
public:
|
||||
explicit QListViewHeightHint(QWidget *parent = 0)
|
||||
: m_heightHint(-1)
|
||||
{
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
virtual QSize sizeHint() const override
|
||||
{
|
||||
QSize mySize = QListView::sizeHint();
|
||||
|
||||
if (m_heightHint > 0)
|
||||
{
|
||||
mySize.setHeight(m_heightHint);
|
||||
}
|
||||
|
||||
return mySize;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void setHeightHint(int heightHint)
|
||||
{
|
||||
m_heightHint = heightHint;
|
||||
}
|
||||
|
||||
private:
|
||||
int m_heightHint;
|
||||
};
|
||||
|
||||
|
||||
|
||||
namespace caf
|
||||
{
|
||||
@@ -98,12 +136,12 @@ CAF_PDM_UI_FIELD_EDITOR_SOURCE_INIT(PdmUiListEditor);
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
PdmUiListEditor::PdmUiListEditor(): m_optionsOnly(true)
|
||||
PdmUiListEditor::PdmUiListEditor() :
|
||||
m_isEditOperationsAvailable(true),
|
||||
m_optionItemCount(0)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
@@ -141,6 +179,14 @@ void PdmUiListEditor::configureAndUpdateUi(const QString& uiConfigName)
|
||||
m_listView->setEnabled(!field()->isUiReadOnly(uiConfigName));
|
||||
m_listView->setToolTip(field()->uiToolTip(uiConfigName));
|
||||
|
||||
bool optionsOnly = true;
|
||||
QList<PdmOptionItemInfo> options = field()->valueOptions(&optionsOnly);
|
||||
m_optionItemCount = options.size();
|
||||
if (options.size() > 0 || field()->isUiReadOnly(uiConfigName))
|
||||
{
|
||||
m_isEditOperationsAvailable = false;
|
||||
}
|
||||
|
||||
PdmUiListEditorAttribute attributes;
|
||||
caf::PdmUiObjectHandle* uiObject = uiObj(field()->fieldHandle()->ownerObject());
|
||||
if (uiObject)
|
||||
@@ -151,20 +197,20 @@ void PdmUiListEditor::configureAndUpdateUi(const QString& uiConfigName)
|
||||
myPalette.setColor(QPalette::Base, attributes.m_baseColor);
|
||||
|
||||
m_listView->setPalette(myPalette);
|
||||
m_listView->setHeightHint(attributes.m_heightHint);
|
||||
}
|
||||
|
||||
MyStringListModel* strListModel = dynamic_cast<MyStringListModel*>(m_model.data());
|
||||
|
||||
CAF_ASSERT(strListModel);
|
||||
|
||||
m_options = field()->valueOptions(&m_optionsOnly);
|
||||
if (!m_options.isEmpty())
|
||||
if (!options.isEmpty())
|
||||
{
|
||||
CAF_ASSERT(m_optionsOnly); // Handling Additions on the fly not implemented
|
||||
CAF_ASSERT(optionsOnly); // Handling Additions on the fly not implemented
|
||||
|
||||
strListModel->setItemsEditable(false);
|
||||
QModelIndex currentItem = m_listView->selectionModel()->currentIndex();
|
||||
QStringList texts = PdmOptionItemInfo::extractUiTexts(m_options);
|
||||
QStringList texts = PdmOptionItemInfo::extractUiTexts(options);
|
||||
strListModel->setStringList(texts);
|
||||
|
||||
QVariant fieldValue = field()->uiValue();
|
||||
@@ -230,21 +276,25 @@ void PdmUiListEditor::configureAndUpdateUi(const QString& uiConfigName)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QWidget* PdmUiListEditor::createEditorWidget(QWidget * parent)
|
||||
{
|
||||
m_listView = new QListView(parent);
|
||||
m_listView = new QListViewHeightHint(parent);
|
||||
|
||||
m_model = new MyStringListModel(m_listView);
|
||||
m_listView->setModel(m_model);
|
||||
|
||||
connect(m_listView->selectionModel(), SIGNAL(selectionChanged(const QItemSelection&, const QItemSelection& )), this, SLOT(slotSelectionChanged(const QItemSelection&, const QItemSelection& )));
|
||||
connect(m_model, SIGNAL(dataChanged(const QModelIndex&, const QModelIndex&)), this, SLOT(slotListItemEdited(const QModelIndex&, const QModelIndex&)));
|
||||
|
||||
// Used to track key press
|
||||
m_listView->installEventFilter(this);
|
||||
|
||||
// Used to track mouse events
|
||||
m_listView->viewport()->installEventFilter(this);
|
||||
|
||||
return m_listView;
|
||||
}
|
||||
|
||||
@@ -262,7 +312,7 @@ QWidget* PdmUiListEditor::createLabelWidget(QWidget * parent)
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void PdmUiListEditor::slotSelectionChanged(const QItemSelection & selected, const QItemSelection & deselected)
|
||||
{
|
||||
if (m_options.isEmpty()) return;
|
||||
if (m_optionItemCount == 0) return;
|
||||
|
||||
QVariant fieldValue = field()->uiValue();
|
||||
if (fieldValue.type() == QVariant::Int || fieldValue.type() == QVariant::UInt)
|
||||
@@ -279,7 +329,7 @@ void PdmUiListEditor::slotSelectionChanged(const QItemSelection & selected, cons
|
||||
QModelIndexList idxList = m_listView->selectionModel()->selectedIndexes();
|
||||
if (idxList.size() >= 1)
|
||||
{
|
||||
if (idxList[0].row() < m_options.size())
|
||||
if (idxList[0].row() < m_optionItemCount)
|
||||
{
|
||||
this->setValueToField(QVariant(static_cast<unsigned int>(idxList[0].row())));
|
||||
}
|
||||
@@ -310,7 +360,7 @@ void PdmUiListEditor::slotSelectionChanged(const QItemSelection & selected, cons
|
||||
QList<QVariant> valuesToSetInField;
|
||||
for (int i = 0; i < idxList.size(); ++i)
|
||||
{
|
||||
if (idxList[i].row() < m_options.size())
|
||||
if (idxList[i].row() < m_optionItemCount)
|
||||
{
|
||||
valuesToSetInField.push_back(QVariant(static_cast<unsigned int>(idxList[i].row())));
|
||||
}
|
||||
@@ -319,13 +369,13 @@ void PdmUiListEditor::slotSelectionChanged(const QItemSelection & selected, cons
|
||||
this->setValueToField(valuesToSetInField);
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void PdmUiListEditor::slotListItemEdited(const QModelIndex&, const QModelIndex&)
|
||||
{
|
||||
if (m_optionsOnly) return;
|
||||
CAF_ASSERT(m_options.isEmpty()); // Not supported yet
|
||||
CAF_ASSERT(m_isEditOperationsAvailable);
|
||||
|
||||
QStringList uiList = m_model->stringList();
|
||||
|
||||
@@ -370,41 +420,66 @@ void PdmUiListEditor::pasteFromString(const QString& content)
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool PdmUiListEditor::eventFilter(QObject * listView, QEvent * event)
|
||||
bool PdmUiListEditor::eventFilter(QObject* object, QEvent * event)
|
||||
{
|
||||
if (listView == m_listView && event->type() == QEvent::KeyPress)
|
||||
if (!m_listView)
|
||||
{
|
||||
if (m_optionsOnly) return false;
|
||||
CAF_ASSERT(m_options.isEmpty()); // Not supported yet
|
||||
|
||||
QKeyEvent* keyEv = static_cast<QKeyEvent*>(event);
|
||||
if (keyEv->key() == Qt::Key_Delete || keyEv->key() == Qt::Key_Backspace )
|
||||
return false;
|
||||
}
|
||||
if (object == m_listView->viewport() && event->type() == QEvent::MouseMove)
|
||||
{
|
||||
QMouseEvent* mouseEvent = dynamic_cast<QMouseEvent*>(event);
|
||||
if (mouseEvent)
|
||||
{
|
||||
QModelIndexList idxList = m_listView->selectionModel()->selectedIndexes();
|
||||
bool isAnyDeleted = false;
|
||||
while(idxList.size())
|
||||
if (mouseEvent->buttons() & Qt::LeftButton
|
||||
&& mouseEvent->modifiers() & Qt::ControlModifier)
|
||||
{
|
||||
m_model->removeRow(idxList[0].row());
|
||||
idxList = m_listView->selectionModel()->selectedIndexes();
|
||||
isAnyDeleted = true;
|
||||
// When Ctrl button is pressed, left mouse button is pressed, and the mouse is moving,
|
||||
// a possible bug in Qt is observed causing the selection to end up with single item selection
|
||||
// When returning here without doing anything, system behaves as expected
|
||||
|
||||
// NOTE: The mouse event is handled by the viewport() of the list view, not the list view itself
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
if (isAnyDeleted)
|
||||
{
|
||||
QStringList uiList = m_model->stringList();
|
||||
|
||||
// Remove dummy elements specifically at the end of list.
|
||||
|
||||
QStringList result;
|
||||
foreach (const QString &str, uiList)
|
||||
{
|
||||
if (str != "" && str != " ") result += str;
|
||||
}
|
||||
this->setValueToField(result);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
else if (keyEv->modifiers() & Qt::ControlModifier)
|
||||
}
|
||||
|
||||
if (object == m_listView && event->type() == QEvent::KeyPress)
|
||||
{
|
||||
QKeyEvent* keyEv = static_cast<QKeyEvent*>(event);
|
||||
|
||||
if (m_isEditOperationsAvailable)
|
||||
{
|
||||
if (keyEv->key() == Qt::Key_Delete || keyEv->key() == Qt::Key_Backspace )
|
||||
{
|
||||
QModelIndexList idxList = m_listView->selectionModel()->selectedIndexes();
|
||||
bool isAnyDeleted = false;
|
||||
while(idxList.size())
|
||||
{
|
||||
m_model->removeRow(idxList[0].row());
|
||||
idxList = m_listView->selectionModel()->selectedIndexes();
|
||||
isAnyDeleted = true;
|
||||
}
|
||||
|
||||
if (isAnyDeleted)
|
||||
{
|
||||
QStringList uiList = m_model->stringList();
|
||||
|
||||
// Remove dummy elements specifically at the end of list.
|
||||
|
||||
QStringList result;
|
||||
foreach (const QString &str, uiList)
|
||||
{
|
||||
if (str != "" && str != " ") result += str;
|
||||
}
|
||||
this->setValueToField(result);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if (keyEv->modifiers() & Qt::ControlModifier)
|
||||
{
|
||||
if (keyEv->key() == Qt::Key_C)
|
||||
{
|
||||
@@ -417,7 +492,7 @@ bool PdmUiListEditor::eventFilter(QObject * listView, QEvent * event)
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else if (keyEv->key() == Qt::Key_V)
|
||||
else if (m_isEditOperationsAvailable && keyEv->key() == Qt::Key_V)
|
||||
{
|
||||
QClipboard* clipboard = QApplication::clipboard();
|
||||
if (clipboard)
|
||||
|
||||
@@ -39,10 +39,9 @@
|
||||
|
||||
#include "cafPdmUiFieldEditorHandle.h"
|
||||
|
||||
class QGridLayout;
|
||||
class QStringListModel;
|
||||
class QItemSelection;
|
||||
class QListView;
|
||||
class QListViewHeightHint;
|
||||
class QLabel;
|
||||
class QModelIndex;
|
||||
|
||||
@@ -56,7 +55,7 @@ class PdmUiListEditorAttribute : public PdmUiEditorAttribute
|
||||
{
|
||||
public:
|
||||
PdmUiListEditorAttribute()
|
||||
: m_baseColor(Qt::white)
|
||||
: m_heightHint(2000)
|
||||
{
|
||||
QPalette myPalette;
|
||||
|
||||
@@ -64,7 +63,8 @@ public:
|
||||
}
|
||||
|
||||
public:
|
||||
QColor m_baseColor;
|
||||
QColor m_baseColor;
|
||||
int m_heightHint;
|
||||
};
|
||||
|
||||
|
||||
@@ -95,15 +95,12 @@ private:
|
||||
void pasteFromString(const QString& content);
|
||||
|
||||
private:
|
||||
QPointer<QListView> m_listView;
|
||||
QPointer<QListViewHeightHint> m_listView;
|
||||
QPointer<QLabel> m_label;
|
||||
QPointer<QStringListModel> m_model;
|
||||
|
||||
QList<PdmOptionItemInfo> m_options;
|
||||
bool m_optionsOnly;
|
||||
|
||||
|
||||
|
||||
bool m_isEditOperationsAvailable;
|
||||
int m_optionItemCount;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -40,8 +40,37 @@
|
||||
#include "cafPdmObject.h"
|
||||
#include "cafPdmUiDefaultObjectEditor.h"
|
||||
|
||||
#include <QEvent>
|
||||
#include <QHBoxLayout>
|
||||
#include <QScrollArea>
|
||||
#include <QScrollBar>
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
QVerticalScrollArea::QVerticalScrollArea(QWidget* parent) :
|
||||
QScrollArea(parent)
|
||||
{
|
||||
setWidgetResizable(true);
|
||||
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||
setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
bool QVerticalScrollArea::eventFilter(QObject* object, QEvent* event)
|
||||
{
|
||||
// This works because QScrollArea::setWidget installs an eventFilter on the widget
|
||||
if (object && object == widget() && event->type() == QEvent::Resize)
|
||||
{
|
||||
setMinimumWidth(widget()->minimumSizeHint().width() + verticalScrollBar()->width());
|
||||
}
|
||||
|
||||
return QScrollArea::eventFilter(object, event);
|
||||
}
|
||||
|
||||
|
||||
namespace caf
|
||||
@@ -54,7 +83,7 @@ namespace caf
|
||||
PdmUiPropertyView::PdmUiPropertyView(QWidget* parent, Qt::WindowFlags f)
|
||||
: QWidget (parent, f)
|
||||
{
|
||||
QScrollArea* scrollArea = new QScrollArea(this);
|
||||
QVerticalScrollArea* scrollArea = new QVerticalScrollArea(this);
|
||||
scrollArea->setFrameStyle(QFrame::NoFrame);
|
||||
scrollArea->setWidgetResizable(true);
|
||||
|
||||
|
||||
@@ -43,6 +43,21 @@
|
||||
|
||||
class QVBoxLayout;
|
||||
|
||||
|
||||
#include <QScrollArea>
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
class QVerticalScrollArea : public QScrollArea
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit QVerticalScrollArea(QWidget* parent = 0);
|
||||
virtual bool eventFilter(QObject* object, QEvent* event) override;
|
||||
};
|
||||
|
||||
|
||||
namespace caf
|
||||
{
|
||||
|
||||
|
||||
Reference in New Issue
Block a user