2014-09-10 17:27:45 +02:00
|
|
|
/************************************************************************
|
|
|
|
**
|
|
|
|
** @file vpropertyformview.cpp
|
|
|
|
** @author hedgeware <internal(at)hedgeware.net>
|
|
|
|
** @date
|
|
|
|
**
|
|
|
|
** @brief
|
|
|
|
** @copyright
|
|
|
|
** All rights reserved. This program and the accompanying materials
|
|
|
|
** are made available under the terms of the GNU Lesser General Public License
|
|
|
|
** (LGPL) version 2.1 which accompanies this distribution, and is available at
|
|
|
|
** http://www.gnu.org/licenses/lgpl-2.1.html
|
|
|
|
**
|
|
|
|
** 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 for more details.
|
|
|
|
**
|
|
|
|
*************************************************************************/
|
|
|
|
|
|
|
|
#include "vpropertyformview.h"
|
2016-08-08 13:44:49 +02:00
|
|
|
|
|
|
|
#include <QList>
|
|
|
|
|
|
|
|
#include "vpropertyformview_p.h"
|
|
|
|
#include "vpropertyformwidget_p.h"
|
2014-09-10 17:27:45 +02:00
|
|
|
#include "vpropertymodel.h"
|
|
|
|
#include "vpropertyset.h"
|
|
|
|
|
2023-08-05 16:51:23 +02:00
|
|
|
VPE::VPropertyFormView::VPropertyFormView(QWidget *parent)
|
|
|
|
: VPropertyFormWidget(new VPropertyFormViewPrivate(), parent)
|
2014-09-10 17:27:45 +02:00
|
|
|
{
|
|
|
|
//
|
|
|
|
}
|
|
|
|
|
2023-08-05 16:51:23 +02:00
|
|
|
VPE::VPropertyFormView::VPropertyFormView(VPropertyModel *model, QWidget *parent)
|
|
|
|
: VPropertyFormWidget(new VPropertyFormViewPrivate(), parent)
|
2014-09-10 17:27:45 +02:00
|
|
|
{
|
|
|
|
setModel(model);
|
|
|
|
}
|
|
|
|
|
2023-08-05 16:51:23 +02:00
|
|
|
VPE::VPropertyFormView::VPropertyFormView(VPropertySet *property_set, QWidget *parent)
|
|
|
|
: VPropertyFormWidget(new VPropertyFormViewPrivate(), parent)
|
2014-09-10 17:27:45 +02:00
|
|
|
{
|
|
|
|
setPropertySet(property_set);
|
|
|
|
}
|
|
|
|
|
2016-12-21 13:02:55 +01:00
|
|
|
VPE::VPropertyFormView::~VPropertyFormView()
|
2014-09-10 17:27:45 +02:00
|
|
|
{
|
|
|
|
// Nothing to do
|
|
|
|
}
|
|
|
|
|
2016-12-21 13:02:55 +01:00
|
|
|
void VPE::VPropertyFormView::build()
|
2014-09-10 17:27:45 +02:00
|
|
|
{
|
|
|
|
VPropertyFormWidget::build();
|
|
|
|
|
|
|
|
// Go through all sub widgets and connect
|
|
|
|
connectPropertyFormWidget(this);
|
|
|
|
}
|
|
|
|
|
2016-12-21 13:02:55 +01:00
|
|
|
void VPE::VPropertyFormView::setModel(VPropertyModel *model)
|
2014-09-10 17:27:45 +02:00
|
|
|
{
|
|
|
|
// Remove old model or set
|
|
|
|
removeModelAndSet();
|
|
|
|
|
|
|
|
// Set model
|
2023-08-05 16:51:23 +02:00
|
|
|
static_cast<VPropertyFormViewPrivate *>(d_ptr)->Model = model;
|
2014-09-10 19:57:08 +02:00
|
|
|
if (model)
|
|
|
|
{
|
2014-09-10 17:27:45 +02:00
|
|
|
// Set the property list
|
2014-09-10 19:57:08 +02:00
|
|
|
if (model->getPropertySet())
|
|
|
|
{
|
2014-09-10 17:27:45 +02:00
|
|
|
d_ptr->Properties = model->getPropertySet()->getRootProperties();
|
2014-09-10 19:57:08 +02:00
|
|
|
}
|
2014-09-10 17:27:45 +02:00
|
|
|
|
|
|
|
// Connect signals // todo: more signals neccesary!!!
|
2016-03-13 14:02:11 +01:00
|
|
|
connect(model, &VPropertyModel::destroyed, this, &VPropertyFormView::modelDestroyed);
|
|
|
|
connect(model, &VPropertyModel::rowsInserted, this, &VPropertyFormView::rowsInserted);
|
|
|
|
connect(model, &VPropertyModel::modelReset, this, &VPropertyFormView::modelReset);
|
|
|
|
connect(model, &VPropertyModel::rowsRemoved, this, &VPropertyFormView::rowsRemoved);
|
2014-09-10 17:27:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Build the widget
|
|
|
|
updatePropertyList();
|
|
|
|
}
|
|
|
|
|
2023-08-05 16:51:23 +02:00
|
|
|
void VPE::VPropertyFormView::setPropertySet(VPropertySet *property_set)
|
2014-09-10 17:27:45 +02:00
|
|
|
{
|
|
|
|
// Remove old model or set
|
|
|
|
removeModelAndSet();
|
|
|
|
|
|
|
|
// Set property set
|
2023-08-05 16:51:23 +02:00
|
|
|
static_cast<VPropertyFormViewPrivate *>(d_ptr)->PropertySet = property_set;
|
2014-09-10 19:57:08 +02:00
|
|
|
if (property_set)
|
|
|
|
{
|
2014-09-10 17:27:45 +02:00
|
|
|
// Set the property list
|
|
|
|
d_ptr->Properties = property_set->getRootProperties();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Build the widget
|
|
|
|
updatePropertyList();
|
|
|
|
}
|
|
|
|
|
2016-12-21 13:02:55 +01:00
|
|
|
void VPE::VPropertyFormView::rowsRemoved(const QModelIndex &parent, int start, int end)
|
2014-09-10 17:27:45 +02:00
|
|
|
{
|
|
|
|
// todo: Only rebuild the neccessary parts
|
|
|
|
Q_UNUSED(parent)
|
|
|
|
Q_UNUSED(start)
|
|
|
|
Q_UNUSED(end)
|
|
|
|
updatePropertyList();
|
|
|
|
}
|
|
|
|
|
2016-12-21 13:02:55 +01:00
|
|
|
void VPE::VPropertyFormView::rowsInserted(const QModelIndex &parent, int start, int end) //-V524
|
2014-09-10 17:27:45 +02:00
|
|
|
{
|
|
|
|
// todo: Only rebuild the neccessary parts
|
|
|
|
Q_UNUSED(parent)
|
|
|
|
Q_UNUSED(start)
|
|
|
|
Q_UNUSED(end)
|
|
|
|
updatePropertyList();
|
|
|
|
}
|
|
|
|
|
2016-12-21 13:02:55 +01:00
|
|
|
void VPE::VPropertyFormView::modelReset()
|
2014-09-10 17:27:45 +02:00
|
|
|
{
|
|
|
|
updatePropertyList();
|
|
|
|
}
|
|
|
|
|
2016-12-21 13:02:55 +01:00
|
|
|
void VPE::VPropertyFormView::modelDestroyed()
|
2014-09-10 17:27:45 +02:00
|
|
|
{
|
|
|
|
removeModelAndSet();
|
|
|
|
updatePropertyList();
|
|
|
|
}
|
|
|
|
|
2016-12-21 13:02:55 +01:00
|
|
|
void VPE::VPropertyFormView::dataChanged(const QModelIndex &top_left, const QModelIndex &bottom_right)
|
2014-09-10 17:27:45 +02:00
|
|
|
{
|
2014-09-11 16:15:49 +02:00
|
|
|
Q_UNUSED(top_left)
|
|
|
|
Q_UNUSED(bottom_right)
|
2017-09-13 10:52:41 +02:00
|
|
|
|
|
|
|
// Ucomment when handle data changes
|
2023-08-05 16:51:23 +02:00
|
|
|
// if (static_cast<VPropertyFormViewPrivate*>(d_ptr)->IgnoreDataChangedSignal)
|
|
|
|
// {
|
|
|
|
// return;
|
|
|
|
// }
|
2017-09-13 10:52:41 +02:00
|
|
|
|
2014-09-10 17:27:45 +02:00
|
|
|
// todo: handle data changes
|
|
|
|
}
|
|
|
|
|
2016-12-21 13:02:55 +01:00
|
|
|
void VPE::VPropertyFormView::dataSubmitted(VProperty *property)
|
2014-09-10 17:27:45 +02:00
|
|
|
{
|
2023-08-05 16:51:23 +02:00
|
|
|
VPropertyModel *tmpModel = static_cast<VPropertyFormViewPrivate *>(d_ptr)->Model;
|
2014-09-10 17:27:45 +02:00
|
|
|
|
2014-09-10 19:57:08 +02:00
|
|
|
if (tmpModel && d_ptr->UpdateEditors)
|
|
|
|
{
|
2023-08-05 16:51:23 +02:00
|
|
|
static_cast<VPropertyFormViewPrivate *>(d_ptr)->IgnoreDataChangedSignal = true;
|
2014-09-10 17:27:45 +02:00
|
|
|
tmpModel->onDataChangedByModel(property);
|
2023-08-05 16:51:23 +02:00
|
|
|
static_cast<VPropertyFormViewPrivate *>(d_ptr)->IgnoreDataChangedSignal = false;
|
2014-09-10 17:27:45 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-21 13:02:55 +01:00
|
|
|
void VPE::VPropertyFormView::showEvent(QShowEvent *event)
|
2014-09-10 17:27:45 +02:00
|
|
|
{
|
|
|
|
Q_UNUSED(event)
|
2023-08-05 16:51:23 +02:00
|
|
|
if (static_cast<VPropertyFormViewPrivate *>(d_ptr)->NeedsRebuild)
|
2014-09-10 19:57:08 +02:00
|
|
|
{
|
2014-09-10 17:27:45 +02:00
|
|
|
build();
|
2014-09-10 19:57:08 +02:00
|
|
|
}
|
2023-08-05 16:51:23 +02:00
|
|
|
static_cast<VPropertyFormViewPrivate *>(d_ptr)->NeedsRebuild = false;
|
2014-09-10 17:27:45 +02:00
|
|
|
}
|
|
|
|
|
2016-12-21 13:02:55 +01:00
|
|
|
void VPE::VPropertyFormView::updatePropertyList()
|
2014-09-10 17:27:45 +02:00
|
|
|
{
|
2023-08-05 16:51:23 +02:00
|
|
|
VPropertyModel *tmpModel = static_cast<VPropertyFormViewPrivate *>(d_ptr)->Model;
|
|
|
|
VPropertySet *tmpSet = static_cast<VPropertyFormViewPrivate *>(d_ptr)->PropertySet;
|
2014-09-10 17:27:45 +02:00
|
|
|
|
2014-09-10 19:57:08 +02:00
|
|
|
if (tmpModel && tmpModel->getPropertySet())
|
|
|
|
{
|
2014-09-10 17:27:45 +02:00
|
|
|
d_ptr->Properties = tmpModel->getPropertySet()->getRootProperties();
|
2014-09-10 19:57:08 +02:00
|
|
|
}
|
|
|
|
else if (tmpSet)
|
|
|
|
{
|
2014-09-10 17:27:45 +02:00
|
|
|
d_ptr->Properties = tmpSet->getRootProperties();
|
2014-09-10 19:57:08 +02:00
|
|
|
}
|
2014-09-10 17:27:45 +02:00
|
|
|
else
|
|
|
|
d_ptr->Properties.clear();
|
|
|
|
|
2014-09-10 19:57:08 +02:00
|
|
|
if (isVisible())
|
|
|
|
{
|
2014-09-10 17:27:45 +02:00
|
|
|
build();
|
2014-09-10 19:57:08 +02:00
|
|
|
}
|
2014-09-10 17:27:45 +02:00
|
|
|
else
|
2023-08-05 16:51:23 +02:00
|
|
|
static_cast<VPropertyFormViewPrivate *>(d_ptr)->NeedsRebuild = true;
|
2014-09-10 17:27:45 +02:00
|
|
|
}
|
|
|
|
|
2016-12-21 13:02:55 +01:00
|
|
|
void VPE::VPropertyFormView::removeModelAndSet()
|
2014-09-10 17:27:45 +02:00
|
|
|
{
|
2023-08-05 16:51:23 +02:00
|
|
|
if (static_cast<VPropertyFormViewPrivate *>(d_ptr)->Model)
|
2014-09-10 19:57:08 +02:00
|
|
|
{
|
2023-08-05 16:51:23 +02:00
|
|
|
disconnect(static_cast<VPropertyFormViewPrivate *>(d_ptr)->Model, nullptr, this, nullptr);
|
|
|
|
static_cast<VPropertyFormViewPrivate *>(d_ptr)->Model = nullptr;
|
2014-09-10 17:27:45 +02:00
|
|
|
}
|
|
|
|
|
2023-08-05 16:51:23 +02:00
|
|
|
static_cast<VPropertyFormViewPrivate *>(d_ptr)->NeedsRebuild = true;
|
2014-09-10 17:27:45 +02:00
|
|
|
d_ptr->Properties.clear();
|
2023-08-05 16:51:23 +02:00
|
|
|
static_cast<VPropertyFormViewPrivate *>(d_ptr)->PropertySet = nullptr;
|
2014-09-10 17:27:45 +02:00
|
|
|
}
|
|
|
|
|
2016-12-21 13:02:55 +01:00
|
|
|
void VPE::VPropertyFormView::connectPropertyFormWidget(VPropertyFormWidget *widget)
|
2014-09-10 17:27:45 +02:00
|
|
|
{
|
2014-09-10 19:57:08 +02:00
|
|
|
if (!widget)
|
|
|
|
{
|
2014-09-10 17:27:45 +02:00
|
|
|
return;
|
2014-09-10 19:57:08 +02:00
|
|
|
}
|
2014-09-10 17:27:45 +02:00
|
|
|
|
|
|
|
connect(widget, &VPropertyFormWidget::propertyDataSubmitted, this, &VPropertyFormView::dataSubmitted,
|
|
|
|
Qt::UniqueConnection);
|
2023-08-05 16:51:23 +02:00
|
|
|
const QList<VPropertyFormWidget *> tmpList = widget->getChildPropertyFormWidgets();
|
2014-09-10 17:27:45 +02:00
|
|
|
|
2023-05-03 13:07:02 +02:00
|
|
|
for (auto *tmpEditorWidget : tmpList)
|
2014-09-10 19:57:08 +02:00
|
|
|
{
|
2014-09-10 17:27:45 +02:00
|
|
|
connectPropertyFormWidget(tmpEditorWidget);
|
|
|
|
}
|
|
|
|
}
|