2012-06-26 09:10:41 -05:00
|
|
|
//##################################################################################################
|
|
|
|
//
|
|
|
|
// Custom Visualization Core library
|
2013-09-20 08:22:29 -05:00
|
|
|
// Copyright (C) 2011-2013 Ceetron AS
|
|
|
|
//
|
|
|
|
// This library 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.
|
2012-06-26 09:10:41 -05:00
|
|
|
//
|
|
|
|
//##################################################################################################
|
|
|
|
|
|
|
|
#include "cafPdmUiPropertyView.h"
|
|
|
|
|
|
|
|
#include "cafPdmObject.h"
|
|
|
|
#include "cafPdmUiDefaultObjectEditor.h"
|
|
|
|
|
2017-03-21 09:32:07 -05:00
|
|
|
#include <QEvent>
|
2012-06-26 09:10:41 -05:00
|
|
|
#include <QHBoxLayout>
|
2019-02-27 08:29:41 -06:00
|
|
|
#include <QResizeEvent>
|
2017-02-20 07:32:12 -06:00
|
|
|
#include <QScrollArea>
|
2017-03-21 09:32:07 -05:00
|
|
|
#include <QScrollBar>
|
2019-03-12 07:48:51 -05:00
|
|
|
#include <QTimer>
|
2017-03-21 09:32:07 -05:00
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2020-06-19 00:53:59 -05:00
|
|
|
///
|
2017-03-21 09:32:07 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2020-06-19 00:53:59 -05:00
|
|
|
QVerticalScrollArea::QVerticalScrollArea( QWidget* parent )
|
|
|
|
: QScrollArea( parent )
|
2017-03-21 09:32:07 -05:00
|
|
|
{
|
2020-06-19 00:53:59 -05:00
|
|
|
setWidgetResizable( true );
|
2022-05-26 14:17:21 -05:00
|
|
|
setHorizontalScrollBarPolicy( Qt::ScrollBarAsNeeded );
|
2020-06-19 00:53:59 -05:00
|
|
|
setVerticalScrollBarPolicy( Qt::ScrollBarAsNeeded );
|
2017-03-21 09:32:07 -05:00
|
|
|
}
|
|
|
|
|
2019-04-05 03:59:05 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
QSize QVerticalScrollArea::sizeHint() const
|
|
|
|
{
|
|
|
|
QSize widgetSize = widget()->sizeHint();
|
|
|
|
QSize scrollSize = QScrollArea::sizeHint();
|
2020-06-19 00:53:59 -05:00
|
|
|
scrollSize.setWidth( widgetSize.width() + verticalScrollBar()->width() );
|
2022-05-26 14:17:21 -05:00
|
|
|
|
2019-04-05 03:59:05 -05:00
|
|
|
return scrollSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
QSize QVerticalScrollArea::minimumSizeHint() const
|
|
|
|
{
|
|
|
|
QSize scrollSize = QScrollArea::minimumSizeHint();
|
2022-05-26 14:17:21 -05:00
|
|
|
scrollSize.setWidth( 10 );
|
|
|
|
|
2019-04-05 03:59:05 -05:00
|
|
|
return scrollSize;
|
|
|
|
}
|
|
|
|
|
2012-06-26 09:10:41 -05:00
|
|
|
namespace caf
|
|
|
|
{
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2020-06-19 00:53:59 -05:00
|
|
|
///
|
2012-06-26 09:10:41 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2020-06-19 00:53:59 -05:00
|
|
|
PdmUiPropertyView::PdmUiPropertyView( QWidget* parent, Qt::WindowFlags f )
|
|
|
|
: QWidget( parent, f )
|
2012-06-26 09:10:41 -05:00
|
|
|
{
|
2020-06-19 00:53:59 -05:00
|
|
|
m_scrollArea = new QVerticalScrollArea( this );
|
|
|
|
m_scrollArea->setFrameStyle( QFrame::NoFrame );
|
|
|
|
m_scrollArea->setWidgetResizable( true );
|
2012-06-26 09:10:41 -05:00
|
|
|
|
2017-02-20 07:32:12 -06:00
|
|
|
m_placeholder = new QWidget();
|
2020-06-19 00:53:59 -05:00
|
|
|
m_scrollArea->setWidget( m_placeholder );
|
2017-02-20 07:32:12 -06:00
|
|
|
|
|
|
|
m_placeHolderLayout = new QVBoxLayout();
|
2020-06-19 00:53:59 -05:00
|
|
|
m_placeHolderLayout->setContentsMargins( 5, 5, 5, 0 );
|
|
|
|
m_placeholder->setLayout( m_placeHolderLayout );
|
2017-02-20 07:32:12 -06:00
|
|
|
|
2020-06-19 00:53:59 -05:00
|
|
|
QVBoxLayout* dummy = new QVBoxLayout( this );
|
|
|
|
dummy->setContentsMargins( 0, 0, 0, 0 );
|
|
|
|
dummy->addWidget( m_scrollArea );
|
2012-06-26 09:10:41 -05:00
|
|
|
|
2019-02-22 03:05:03 -06:00
|
|
|
m_defaultObjectEditor = nullptr;
|
2012-06-26 09:10:41 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2020-06-19 00:53:59 -05:00
|
|
|
///
|
2012-06-26 09:10:41 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
PdmUiPropertyView::~PdmUiPropertyView()
|
|
|
|
{
|
2020-06-19 00:53:59 -05:00
|
|
|
if ( m_defaultObjectEditor ) delete m_defaultObjectEditor;
|
2012-06-26 09:10:41 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2020-06-19 00:53:59 -05:00
|
|
|
///
|
2012-06-26 09:10:41 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2020-06-19 00:53:59 -05:00
|
|
|
void PdmUiPropertyView::setUiConfigurationName( QString uiConfigName )
|
2012-06-26 09:10:41 -05:00
|
|
|
{
|
|
|
|
// Reset everything, and possibly create widgets etc afresh
|
2020-06-19 00:53:59 -05:00
|
|
|
if ( m_uiConfigName != uiConfigName )
|
|
|
|
{
|
2012-06-26 09:10:41 -05:00
|
|
|
m_uiConfigName = uiConfigName;
|
|
|
|
|
2020-06-19 00:53:59 -05:00
|
|
|
if ( m_defaultObjectEditor )
|
2012-06-26 09:10:41 -05:00
|
|
|
{
|
2019-02-22 03:05:03 -06:00
|
|
|
PdmObjectHandle* object = m_defaultObjectEditor->pdmObject();
|
|
|
|
delete m_defaultObjectEditor;
|
|
|
|
m_defaultObjectEditor = nullptr;
|
2020-06-19 00:53:59 -05:00
|
|
|
this->showProperties( object );
|
2012-06-26 09:10:41 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2020-06-19 00:53:59 -05:00
|
|
|
///
|
2012-06-26 09:10:41 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2020-06-19 00:53:59 -05:00
|
|
|
void PdmUiPropertyView::showProperties( PdmObjectHandle* object )
|
2012-06-26 09:10:41 -05:00
|
|
|
{
|
2020-06-19 00:53:59 -05:00
|
|
|
// Find specialized object view handle
|
2012-06-26 09:10:41 -05:00
|
|
|
|
|
|
|
// If the current ObjectView has the same type as the one to view, reuse, with Widget etc.
|
|
|
|
|
|
|
|
bool rebuildWidget = false;
|
|
|
|
|
2020-06-19 00:53:59 -05:00
|
|
|
if ( !m_defaultObjectEditor ) rebuildWidget = true;
|
|
|
|
|
|
|
|
if ( m_defaultObjectEditor && m_defaultObjectEditor->pdmObject() )
|
2012-06-26 09:10:41 -05:00
|
|
|
{
|
2020-06-19 00:53:59 -05:00
|
|
|
if ( object )
|
2012-06-26 09:10:41 -05:00
|
|
|
{
|
2020-06-19 00:53:59 -05:00
|
|
|
PdmUiObjectHandle* uiObject1 = uiObj( m_defaultObjectEditor->pdmObject() );
|
|
|
|
PdmUiObjectHandle* uiObject2 = uiObj( object );
|
2015-07-29 07:19:43 -05:00
|
|
|
|
2020-06-19 00:53:59 -05:00
|
|
|
if ( uiObject1 && uiObject2 &&
|
|
|
|
( uiObject1->uiEditorTypeName( m_uiConfigName ) != uiObject2->uiEditorTypeName( m_uiConfigName ) ) )
|
2012-06-26 09:10:41 -05:00
|
|
|
{
|
|
|
|
rebuildWidget = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-19 00:53:59 -05:00
|
|
|
if ( rebuildWidget )
|
2012-06-26 09:10:41 -05:00
|
|
|
{
|
|
|
|
// Remove Widget from layout
|
2020-06-19 00:53:59 -05:00
|
|
|
if ( m_defaultObjectEditor )
|
2012-06-26 09:10:41 -05:00
|
|
|
{
|
2020-06-19 00:53:59 -05:00
|
|
|
this->m_placeHolderLayout->removeWidget( m_defaultObjectEditor->widget() );
|
2019-02-22 03:05:03 -06:00
|
|
|
delete m_defaultObjectEditor;
|
|
|
|
m_defaultObjectEditor = nullptr;
|
2012-06-26 09:10:41 -05:00
|
|
|
}
|
|
|
|
|
2020-06-19 00:53:59 -05:00
|
|
|
if ( !m_defaultObjectEditor )
|
2012-06-26 09:10:41 -05:00
|
|
|
{
|
2019-02-22 03:05:03 -06:00
|
|
|
m_defaultObjectEditor = new PdmUiDefaultObjectEditor();
|
2012-06-26 09:10:41 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// Create widget to handle this
|
2020-06-19 00:53:59 -05:00
|
|
|
QWidget* propertyWidget = m_defaultObjectEditor->getOrCreateWidget( m_placeholder );
|
|
|
|
|
|
|
|
CAF_ASSERT( propertyWidget );
|
2012-06-26 09:10:41 -05:00
|
|
|
|
2020-06-19 00:53:59 -05:00
|
|
|
this->m_placeHolderLayout->insertWidget( 0, propertyWidget );
|
2012-06-26 09:10:41 -05:00
|
|
|
|
2017-02-20 07:32:12 -06:00
|
|
|
// Add stretch to make sure the property widget is not stretched
|
2020-06-19 00:53:59 -05:00
|
|
|
this->m_placeHolderLayout->insertStretch( -1, 1 );
|
2012-06-26 09:10:41 -05:00
|
|
|
}
|
|
|
|
|
2020-06-19 00:53:59 -05:00
|
|
|
m_defaultObjectEditor->setPdmObject( object );
|
2019-02-22 03:03:24 -06:00
|
|
|
|
2020-06-19 00:53:59 -05:00
|
|
|
m_defaultObjectEditor->updateUi( m_uiConfigName );
|
2019-04-05 03:59:05 -05:00
|
|
|
m_scrollArea->updateGeometry();
|
2019-02-22 03:03:24 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2020-06-19 00:53:59 -05:00
|
|
|
///
|
2012-09-18 08:21:04 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2015-08-18 09:40:32 -05:00
|
|
|
PdmObjectHandle* PdmUiPropertyView::currentObject()
|
2012-09-18 08:21:04 -05:00
|
|
|
{
|
2020-06-19 00:53:59 -05:00
|
|
|
if ( !m_defaultObjectEditor ) return nullptr;
|
2019-02-22 03:05:03 -06:00
|
|
|
return m_defaultObjectEditor->pdmObject();
|
2012-09-18 08:21:04 -05:00
|
|
|
}
|
|
|
|
|
2016-08-03 06:29:46 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2020-06-19 00:53:59 -05:00
|
|
|
///
|
2016-08-03 06:29:46 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
QSize PdmUiPropertyView::sizeHint() const
|
|
|
|
{
|
2019-04-08 07:29:47 -05:00
|
|
|
QSize scrollSize = m_scrollArea->sizeHint();
|
|
|
|
QSize contentSize = m_placeholder->sizeHint();
|
2020-06-19 00:53:59 -05:00
|
|
|
return QSize( scrollSize.width(), contentSize.height() );
|
2019-04-05 03:59:05 -05:00
|
|
|
}
|
2017-02-22 04:58:56 -06:00
|
|
|
|
2019-04-05 03:59:05 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
QSize PdmUiPropertyView::minimumSizeHint() const
|
|
|
|
{
|
|
|
|
return m_scrollArea->minimumSizeHint();
|
2016-08-03 06:29:46 -05:00
|
|
|
}
|
|
|
|
|
2020-06-19 00:53:59 -05:00
|
|
|
} // End of namespace caf
|