2012-08-31 19:12:47 +02:00
|
|
|
//##################################################################################################
|
|
|
|
|
//
|
|
|
|
|
// Custom Visualization Core library
|
2013-09-20 15:22:29 +02: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-08-31 19:12:47 +02:00
|
|
|
//
|
|
|
|
|
//##################################################################################################
|
|
|
|
|
|
2013-09-20 15:22:29 +02:00
|
|
|
|
2012-08-31 19:12:47 +02:00
|
|
|
#include "cafPdmUiPushButtonEditor.h"
|
|
|
|
|
|
|
|
|
|
#include "cafPdmUiDefaultObjectEditor.h"
|
|
|
|
|
|
|
|
|
|
#include "cafPdmObject.h"
|
|
|
|
|
#include "cafPdmUiFieldEditorHandle.h"
|
|
|
|
|
#include "cafPdmUiOrdering.h"
|
|
|
|
|
#include "cafPdmField.h"
|
|
|
|
|
|
|
|
|
|
#include "cafFactory.h"
|
2017-11-23 07:43:41 +01:00
|
|
|
|
|
|
|
|
#include <QBoxLayout>
|
|
|
|
|
|
|
|
|
|
#include <cmath>
|
2012-08-31 19:12:47 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace caf
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
CAF_PDM_UI_FIELD_EDITOR_SOURCE_INIT(PdmUiPushButtonEditor);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
void PdmUiPushButtonEditor::configureAndUpdateUi(const QString& uiConfigName)
|
|
|
|
|
{
|
2017-03-08 08:19:51 +01:00
|
|
|
CAF_ASSERT(!m_pushButton.isNull());
|
|
|
|
|
CAF_ASSERT(!m_label.isNull());
|
2012-08-31 19:12:47 +02:00
|
|
|
|
2017-09-07 09:08:11 +02:00
|
|
|
PdmUiFieldEditorHandle::updateLabelFromField(m_label, uiConfigName);
|
2012-08-31 19:12:47 +02:00
|
|
|
|
2013-04-08 12:16:38 +02:00
|
|
|
m_pushButton->setCheckable(true);
|
2013-04-05 13:29:47 +02:00
|
|
|
m_pushButton->setEnabled(!field()->isUiReadOnly(uiConfigName));
|
2013-09-26 10:41:08 +02:00
|
|
|
m_pushButton->setToolTip(field()->uiToolTip(uiConfigName));
|
2012-08-31 19:12:47 +02:00
|
|
|
|
|
|
|
|
PdmUiPushButtonEditorAttribute attributes;
|
2015-07-29 14:19:43 +02:00
|
|
|
caf::PdmUiObjectHandle* uiObject = uiObj(field()->fieldHandle()->ownerObject());
|
|
|
|
|
if (uiObject)
|
|
|
|
|
{
|
|
|
|
|
uiObject->editorAttribute(field()->fieldHandle(), uiConfigName, &attributes);
|
|
|
|
|
}
|
2012-08-31 19:12:47 +02:00
|
|
|
|
2013-04-05 13:29:47 +02:00
|
|
|
QVariant variantFieldValue = field()->uiValue();
|
|
|
|
|
|
|
|
|
|
if (!attributes.m_buttonIcon.isNull())
|
|
|
|
|
{
|
|
|
|
|
m_pushButton->setIcon(attributes.m_buttonIcon);
|
|
|
|
|
}
|
2017-01-26 12:13:03 +01:00
|
|
|
|
|
|
|
|
if (!attributes.m_buttonText.isEmpty())
|
2013-04-08 12:16:38 +02:00
|
|
|
{
|
|
|
|
|
m_pushButton->setText(attributes.m_buttonText);
|
|
|
|
|
}
|
2013-04-05 13:29:47 +02:00
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (variantFieldValue.type() == QVariant::Bool)
|
|
|
|
|
{
|
|
|
|
|
m_pushButton->setText(variantFieldValue.toBool() ? "On" : "Off" );
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
m_pushButton->setText(variantFieldValue.toString());
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-11-22 14:52:08 +01:00
|
|
|
|
|
|
|
|
QSize defaultSize = m_pushButton->sizeHint();
|
|
|
|
|
m_pushButton->setMinimumWidth(10*std::round(0.1*(defaultSize.width() + 10)));
|
|
|
|
|
m_buttonLayout->setAlignment(m_pushButton, Qt::AlignRight);
|
2013-04-05 13:29:47 +02:00
|
|
|
|
|
|
|
|
if (variantFieldValue.type() == QVariant::Bool)
|
|
|
|
|
{
|
|
|
|
|
m_pushButton->setChecked(field()->uiValue().toBool());
|
|
|
|
|
}
|
2012-08-31 19:12:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2017-11-16 11:40:46 +01:00
|
|
|
void PdmUiPushButtonEditor::configureEditorForField(PdmFieldHandle* fieldHandle)
|
|
|
|
|
{
|
|
|
|
|
if (fieldHandle)
|
|
|
|
|
{
|
|
|
|
|
if (fieldHandle->xmlCapability())
|
|
|
|
|
{
|
|
|
|
|
fieldHandle->xmlCapability()->disableIO();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (fieldHandle->uiCapability())
|
|
|
|
|
{
|
|
|
|
|
fieldHandle->uiCapability()->setUiEditorTypeName(caf::PdmUiPushButtonEditor::uiEditorTypeName());
|
|
|
|
|
fieldHandle->uiCapability()->setUiLabelPosition(caf::PdmUiItemInfo::LEFT);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2012-08-31 19:12:47 +02:00
|
|
|
QWidget* PdmUiPushButtonEditor::createEditorWidget(QWidget * parent)
|
|
|
|
|
{
|
2017-11-22 14:52:08 +01:00
|
|
|
QWidget* containerWidget = new QWidget(parent);
|
|
|
|
|
|
|
|
|
|
m_pushButton = new QPushButton("", containerWidget);
|
2012-08-31 19:12:47 +02:00
|
|
|
connect(m_pushButton, SIGNAL(clicked(bool)), this, SLOT(slotClicked(bool)));
|
2017-11-22 14:52:08 +01:00
|
|
|
|
|
|
|
|
m_buttonLayout = new QHBoxLayout(containerWidget);
|
|
|
|
|
m_buttonLayout->addWidget(m_pushButton);
|
|
|
|
|
m_buttonLayout->setMargin(0);
|
|
|
|
|
m_buttonLayout->setSpacing(0);
|
|
|
|
|
|
|
|
|
|
containerWidget->setLayout(m_buttonLayout);
|
|
|
|
|
|
|
|
|
|
return containerWidget;
|
2012-08-31 19:12:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
QWidget* PdmUiPushButtonEditor::createLabelWidget(QWidget * parent)
|
|
|
|
|
{
|
|
|
|
|
m_label = new QLabel(parent);
|
|
|
|
|
return m_label;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
///
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
void PdmUiPushButtonEditor::slotClicked(bool checked)
|
|
|
|
|
{
|
2015-07-29 14:19:43 +02:00
|
|
|
if (field() && dynamic_cast<PdmField<bool> *> (field()->fieldHandle()))
|
2013-04-05 13:29:47 +02:00
|
|
|
{
|
|
|
|
|
QVariant v;
|
|
|
|
|
v = checked;
|
|
|
|
|
this->setValueToField(v);
|
|
|
|
|
}
|
2012-08-31 19:12:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} // end namespace caf
|