2017-09-05 13:29:38 +02:00
|
|
|
//##################################################################################################
|
|
|
|
|
//
|
|
|
|
|
// Custom Visualization Core library
|
|
|
|
|
//
|
|
|
|
|
// 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.
|
|
|
|
|
//
|
|
|
|
|
//##################################################################################################
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include "cafPdmUiTreeSelectionEditor.h"
|
|
|
|
|
|
|
|
|
|
#include "cafAssert.h"
|
|
|
|
|
#include "cafPdmObject.h"
|
|
|
|
|
#include "cafPdmUiTreeSelectionQModel.h"
|
|
|
|
|
|
2017-09-06 14:46:32 +02:00
|
|
|
#include "cafQTreeViewStateSerializer.h"
|
|
|
|
|
|
2017-09-05 13:29:38 +02:00
|
|
|
#include <QTreeView>
|
|
|
|
|
#include <QLabel>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace caf
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
CAF_PDM_UI_FIELD_EDITOR_SOURCE_INIT(PdmUiTreeSelectionEditor);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
PdmUiTreeSelectionEditor::PdmUiTreeSelectionEditor()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
PdmUiTreeSelectionEditor::~PdmUiTreeSelectionEditor()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
void PdmUiTreeSelectionEditor::configureAndUpdateUi(const QString& uiConfigName)
|
|
|
|
|
{
|
2017-09-07 08:03:58 +02:00
|
|
|
// Label
|
|
|
|
|
CAF_ASSERT(!m_label.isNull());
|
|
|
|
|
|
|
|
|
|
QIcon ic = field()->uiIcon(uiConfigName);
|
|
|
|
|
if (!ic.isNull())
|
|
|
|
|
{
|
|
|
|
|
m_label->setPixmap(ic.pixmap(ic.actualSize(QSize(64, 64))));
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
QString uiName = field()->uiName(uiConfigName);
|
|
|
|
|
m_label->setText(uiName);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
m_label->setEnabled(!field()->isUiReadOnly(uiConfigName));
|
|
|
|
|
m_label->setToolTip(field()->uiToolTip(uiConfigName));
|
|
|
|
|
|
|
|
|
|
// Tree view
|
|
|
|
|
|
2017-09-05 13:29:38 +02:00
|
|
|
bool optionsOnly = true;
|
|
|
|
|
QList<PdmOptionItemInfo> options = field()->valueOptions(&optionsOnly);
|
|
|
|
|
|
2017-09-06 14:46:32 +02:00
|
|
|
if (!m_treeView->model())
|
|
|
|
|
{
|
|
|
|
|
caf::PdmUiTreeSelectionQModel* model = new caf::PdmUiTreeSelectionQModel(m_treeView);
|
|
|
|
|
m_treeView->setModel(model);
|
|
|
|
|
connect(model, SIGNAL(signalSelectionStateForIndexHasChanged(int, bool)), this, SLOT(slotSetSelectionStateForIndex(int, bool)));
|
|
|
|
|
}
|
2017-09-05 13:29:38 +02:00
|
|
|
|
2017-09-06 14:46:32 +02:00
|
|
|
caf::PdmUiTreeSelectionQModel* treeSelectionQModel = dynamic_cast<caf::PdmUiTreeSelectionQModel*>(m_treeView->model());
|
|
|
|
|
if (treeSelectionQModel)
|
|
|
|
|
{
|
2017-09-07 07:32:42 +02:00
|
|
|
bool itemCountHasChaged = false;
|
|
|
|
|
if (treeSelectionQModel->optionItemCount() != options.size()) itemCountHasChaged = true;
|
|
|
|
|
|
2017-09-06 14:46:32 +02:00
|
|
|
// TODO: If the count is different between incoming and current list of items,
|
|
|
|
|
// use cafQTreeViewStateSerializer to restore collapsed state
|
|
|
|
|
treeSelectionQModel->setOptions(this, options);
|
2017-09-07 07:32:42 +02:00
|
|
|
|
|
|
|
|
if (itemCountHasChaged)
|
|
|
|
|
{
|
|
|
|
|
m_treeView->expandAll();
|
|
|
|
|
}
|
2017-09-06 14:46:32 +02:00
|
|
|
}
|
2017-09-06 07:37:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
void PdmUiTreeSelectionEditor::slotSetSelectionStateForIndex(int index, bool isSelected)
|
|
|
|
|
{
|
|
|
|
|
unsigned int unsignedValue = static_cast<unsigned int>(index);
|
|
|
|
|
|
|
|
|
|
QVariant fieldValue = field()->uiValue();
|
|
|
|
|
QList<QVariant> valuesSelectedInField = fieldValue.toList();
|
|
|
|
|
|
|
|
|
|
if (!isSelected)
|
|
|
|
|
{
|
|
|
|
|
valuesSelectedInField.removeAll(QVariant(unsignedValue));
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
bool isIndexPresent = false;
|
|
|
|
|
for (QVariant v : valuesSelectedInField)
|
|
|
|
|
{
|
|
|
|
|
unsigned int indexInField = v.toUInt();
|
|
|
|
|
if (indexInField == unsignedValue)
|
|
|
|
|
{
|
|
|
|
|
isIndexPresent = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!isIndexPresent)
|
|
|
|
|
{
|
|
|
|
|
valuesSelectedInField.push_back(QVariant(unsignedValue));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this->setValueToField(valuesSelectedInField);
|
2017-09-05 13:29:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
QWidget* PdmUiTreeSelectionEditor::createEditorWidget(QWidget * parent)
|
|
|
|
|
{
|
|
|
|
|
m_treeView = new QTreeView(parent);
|
|
|
|
|
|
2017-09-06 11:15:17 +02:00
|
|
|
m_treeView->setHeaderHidden(true);
|
|
|
|
|
|
2017-09-05 13:29:38 +02:00
|
|
|
return m_treeView;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
QWidget* PdmUiTreeSelectionEditor::createLabelWidget(QWidget * parent)
|
|
|
|
|
{
|
|
|
|
|
m_label = new QLabel(parent);
|
|
|
|
|
return m_label;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} // end namespace caf
|