Gui: implement property editor for vector list
This commit is contained in:
@@ -224,6 +224,9 @@ public:
|
||||
virtual void Paste(const Property &from) override;
|
||||
|
||||
virtual unsigned int getMemSize (void) const override;
|
||||
const char* getEditorName(void) const override {
|
||||
return "Gui::PropertyEditor::PropertyVectorListItem";
|
||||
}
|
||||
|
||||
protected:
|
||||
Base::Vector3d getPyValue(PyObject *) const override;
|
||||
|
||||
@@ -370,6 +370,7 @@ set(Gui_MOC_HDRS
|
||||
TreeView.h
|
||||
ProjectView.h
|
||||
View3DInventor.h
|
||||
VectorListEditor.h
|
||||
WidgetFactory.h
|
||||
Widgets.h
|
||||
Language/Translator.h
|
||||
@@ -464,6 +465,7 @@ SET(Gui_UIC_SRCS
|
||||
TaskElementColors.ui
|
||||
DlgObjectSelection.ui
|
||||
DlgAddProperty.ui
|
||||
VectorListEditor.ui
|
||||
)
|
||||
|
||||
SET(Gui_RES_SRCS
|
||||
@@ -541,6 +543,7 @@ SET(Dialog_CPP_SRCS
|
||||
TaskElementColors.cpp
|
||||
DlgObjectSelection.cpp
|
||||
DlgAddProperty.cpp
|
||||
VectorListEditor.cpp
|
||||
)
|
||||
|
||||
SET(Dialog_HPP_SRCS
|
||||
@@ -577,6 +580,7 @@ SET(Dialog_HPP_SRCS
|
||||
TaskElementColors.h
|
||||
DlgObjectSelection.h
|
||||
DlgAddProperty.h
|
||||
VectorListEditor.h
|
||||
)
|
||||
|
||||
SET(Dialog_SRCS
|
||||
@@ -615,6 +619,7 @@ SET(Dialog_SRCS
|
||||
TextureMapping.ui
|
||||
TaskElementColors.ui
|
||||
DlgObjectSelection.ui
|
||||
VectorListEditor.ui
|
||||
)
|
||||
SOURCE_GROUP("Dialog" FILES ${Dialog_SRCS})
|
||||
|
||||
|
||||
@@ -31,6 +31,7 @@
|
||||
|
||||
Q_DECLARE_METATYPE(Base::Vector3f)
|
||||
Q_DECLARE_METATYPE(Base::Vector3d)
|
||||
Q_DECLARE_METATYPE(QList<Base::Vector3d>)
|
||||
Q_DECLARE_METATYPE(Base::Matrix4D)
|
||||
Q_DECLARE_METATYPE(Base::Placement)
|
||||
Q_DECLARE_METATYPE(Base::Quantity)
|
||||
|
||||
@@ -140,6 +140,7 @@ void Gui::SoFCDB::init()
|
||||
PropertyAngleItem ::init();
|
||||
PropertyBoolItem ::init();
|
||||
PropertyVectorItem ::init();
|
||||
PropertyVectorListItem ::init();
|
||||
PropertyVectorDistanceItem ::init();
|
||||
PropertyPositionItem ::init();
|
||||
PropertyDirectionItem ::init();
|
||||
|
||||
318
src/Gui/VectorListEditor.cpp
Normal file
318
src/Gui/VectorListEditor.cpp
Normal file
@@ -0,0 +1,318 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2020 Werner Mayer <wmayer[at]users.sourceforge.net> *
|
||||
* *
|
||||
* This file is part of the FreeCAD CAx development system. *
|
||||
* *
|
||||
* This library is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU Library General Public *
|
||||
* License as published by the Free Software Foundation; either *
|
||||
* version 2 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 Library General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU Library General Public *
|
||||
* License along with this library; see the file COPYING.LIB. If not, *
|
||||
* write to the Free Software Foundation, Inc., 59 Temple Place, *
|
||||
* Suite 330, Boston, MA 02111-1307, USA *
|
||||
* *
|
||||
***************************************************************************/
|
||||
|
||||
|
||||
#include "PreCompiled.h"
|
||||
#ifndef _PreComp_
|
||||
#endif
|
||||
|
||||
#include "VectorListEditor.h"
|
||||
#include "ui_VectorListEditor.h"
|
||||
#include <Gui/QuantitySpinBox.h>
|
||||
|
||||
using namespace Gui;
|
||||
|
||||
VectorTableModel::VectorTableModel(int decimals, QObject *parent)
|
||||
: QAbstractTableModel(parent)
|
||||
, decimals(decimals)
|
||||
{
|
||||
}
|
||||
|
||||
QVariant VectorTableModel::headerData(int section, Qt::Orientation orientation, int role) const
|
||||
{
|
||||
if (role == Qt::DisplayRole && orientation == Qt::Vertical)
|
||||
return section + 1;
|
||||
|
||||
if (role != Qt::DisplayRole || orientation != Qt::Horizontal)
|
||||
return QVariant();
|
||||
if (section == 0)
|
||||
return QVariant(QLatin1Char('x'));
|
||||
if (section == 1)
|
||||
return QVariant(QLatin1Char('y'));
|
||||
if (section == 2)
|
||||
return QVariant(QLatin1Char('z'));
|
||||
else
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
int VectorTableModel::columnCount(const QModelIndex&) const
|
||||
{
|
||||
return 3;
|
||||
}
|
||||
|
||||
int VectorTableModel::rowCount(const QModelIndex &) const
|
||||
{
|
||||
return vectors.size();
|
||||
}
|
||||
|
||||
Qt::ItemFlags VectorTableModel::flags (const QModelIndex & index) const
|
||||
{
|
||||
Qt::ItemFlags fl = QAbstractTableModel::flags(index);
|
||||
fl = fl | Qt::ItemIsEditable;
|
||||
return fl;
|
||||
}
|
||||
|
||||
bool VectorTableModel::setData(const QModelIndex &index, const QVariant &value, int role)
|
||||
{
|
||||
int r = index.row();
|
||||
int c = index.column();
|
||||
if (role == Qt::EditRole && r < vectors.size()) {
|
||||
if (value.canConvert<Base::Vector3d>()) {
|
||||
vectors[r] = value.value<Base::Vector3d>();
|
||||
dataChanged(index, index.sibling(index.row(), 2));
|
||||
return true;
|
||||
}
|
||||
else if (c < 3) {
|
||||
double d = value.toDouble();
|
||||
if (c == 0)
|
||||
vectors[r].x = d;
|
||||
else if (c == 1)
|
||||
vectors[r].y = d;
|
||||
else if (c == 2)
|
||||
vectors[r].z = d;
|
||||
dataChanged(index, index);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return QAbstractTableModel::setData(index, value, role);
|
||||
}
|
||||
|
||||
QVariant VectorTableModel::data(const QModelIndex &index, int role) const
|
||||
{
|
||||
if (role == Qt::DisplayRole || role == Qt::EditRole) {
|
||||
int r = index.row();
|
||||
int c = index.column();
|
||||
if (r < vectors.size() && c < 3) {
|
||||
double d = 0.0;
|
||||
if (c == 0)
|
||||
d = vectors[r].x;
|
||||
else if (c == 1)
|
||||
d = vectors[r].y;
|
||||
else if (c == 2)
|
||||
d = vectors[r].z;
|
||||
|
||||
if (role == Qt::DisplayRole) {
|
||||
QString str = QString::fromLatin1("%1").arg(d, 0, 'f', decimals);
|
||||
return str;
|
||||
}
|
||||
|
||||
return d;
|
||||
}
|
||||
}
|
||||
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
QModelIndex VectorTableModel::parent(const QModelIndex &) const
|
||||
{
|
||||
return QModelIndex();
|
||||
}
|
||||
|
||||
void VectorTableModel::setValues(const QList<Base::Vector3d>& d)
|
||||
{
|
||||
vectors = d;
|
||||
beginResetModel();
|
||||
endResetModel();
|
||||
}
|
||||
|
||||
const QList<Base::Vector3d>& VectorTableModel::values() const
|
||||
{
|
||||
return vectors;
|
||||
}
|
||||
|
||||
bool VectorTableModel::insertRows(int row, int count, const QModelIndex &parent)
|
||||
{
|
||||
if (vectors.size() >= row) {
|
||||
beginInsertRows(parent, row, row+count-1);
|
||||
Base::Vector3d v;
|
||||
for (int i=0; i<count; i++)
|
||||
vectors.insert(row, v);
|
||||
endInsertRows();
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool VectorTableModel::removeRows(int row, int count, const QModelIndex &parent)
|
||||
{
|
||||
if (vectors.size() > row) {
|
||||
beginRemoveRows(parent, row, row+count-1);
|
||||
for (int i=0; i<count; i++)
|
||||
vectors.removeAt(row);
|
||||
endRemoveRows();
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------
|
||||
|
||||
VectorTableDelegate::VectorTableDelegate(int decimals, QObject *parent)
|
||||
: QItemDelegate(parent)
|
||||
, decimals(decimals)
|
||||
{
|
||||
}
|
||||
|
||||
QWidget *VectorTableDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &/* option */,
|
||||
const QModelIndex & /*index*/) const
|
||||
{
|
||||
QDoubleSpinBox *editor = new QDoubleSpinBox(parent);
|
||||
editor->setDecimals(decimals);
|
||||
editor->setMinimum(INT_MIN);
|
||||
editor->setMaximum(INT_MAX);
|
||||
editor->setSingleStep(0.1);
|
||||
|
||||
return editor;
|
||||
}
|
||||
|
||||
void VectorTableDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const
|
||||
{
|
||||
double value = index.model()->data(index, Qt::EditRole).toDouble();
|
||||
|
||||
QDoubleSpinBox *spinBox = static_cast<QDoubleSpinBox*>(editor);
|
||||
spinBox->setValue(value);
|
||||
}
|
||||
|
||||
void VectorTableDelegate::setModelData(QWidget *editor, QAbstractItemModel *model,
|
||||
const QModelIndex &index) const
|
||||
{
|
||||
QDoubleSpinBox *spinBox = static_cast<QDoubleSpinBox*>(editor);
|
||||
spinBox->interpretText();
|
||||
double value = spinBox->value();
|
||||
model->setData(index, value, Qt::EditRole);
|
||||
}
|
||||
|
||||
void VectorTableDelegate::updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option,
|
||||
const QModelIndex &/* index */) const
|
||||
{
|
||||
editor->setGeometry(option.rect);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------
|
||||
|
||||
/* TRANSLATOR Gui::VectorListEditor */
|
||||
|
||||
VectorListEditor::VectorListEditor(int decimals, QWidget* parent)
|
||||
: QDialog(parent)
|
||||
, ui(new Ui_VectorListEditor)
|
||||
, model(new VectorTableModel(decimals))
|
||||
{
|
||||
ui->setupUi(this);
|
||||
ui->tableWidget->setItemDelegate(new VectorTableDelegate(decimals, this));
|
||||
ui->tableWidget->setModel(model);
|
||||
ui->widget->hide();
|
||||
|
||||
ui->coordX->setRange(INT_MIN, INT_MAX);
|
||||
ui->coordX->setDecimals(decimals);
|
||||
ui->coordY->setRange(INT_MIN, INT_MAX);
|
||||
ui->coordY->setDecimals(decimals);
|
||||
ui->coordZ->setRange(INT_MIN, INT_MAX);
|
||||
ui->coordZ->setDecimals(decimals);
|
||||
|
||||
ui->toolButtonMouse->setDisabled(true);
|
||||
|
||||
connect(ui->buttonBox, SIGNAL(accepted()), this, SLOT(accept()));
|
||||
connect(ui->buttonBox, SIGNAL(rejected()), this, SLOT(reject()));
|
||||
|
||||
connect(ui->spinBox, SIGNAL(valueChanged(int)), this, SLOT(setCurrentRow(int)));
|
||||
connect(ui->toolButtonAdd, SIGNAL(clicked(bool)), this, SLOT(addRow()));
|
||||
connect(ui->toolButtonRemove, SIGNAL(clicked(bool)), this, SLOT(removeRow()));
|
||||
connect(ui->toolButtonAccept, SIGNAL(clicked(bool)), this, SLOT(acceptCurrent()));
|
||||
}
|
||||
|
||||
VectorListEditor::~VectorListEditor()
|
||||
{
|
||||
}
|
||||
|
||||
void VectorListEditor::setValues(const QList<Base::Vector3d>& v)
|
||||
{
|
||||
data = v;
|
||||
model->setValues(v);
|
||||
if (v.isEmpty()) {
|
||||
ui->spinBox->setRange(1, 1);
|
||||
ui->spinBox->setEnabled(false);
|
||||
ui->toolButtonRemove->setEnabled(false);
|
||||
}
|
||||
else {
|
||||
ui->spinBox->setRange(1, v.size());
|
||||
}
|
||||
}
|
||||
|
||||
const QList<Base::Vector3d>& VectorListEditor::getValues() const
|
||||
{
|
||||
return data;
|
||||
}
|
||||
|
||||
void VectorListEditor::accept()
|
||||
{
|
||||
data = model->values();
|
||||
QDialog::accept();
|
||||
}
|
||||
|
||||
void VectorListEditor::reject()
|
||||
{
|
||||
QDialog::reject();
|
||||
}
|
||||
|
||||
void VectorListEditor::setCurrentRow(int row)
|
||||
{
|
||||
QModelIndex index = model->index(row - 1, 0);
|
||||
ui->tableWidget->setCurrentIndex(index);
|
||||
ui->coordX->setValue(model->data(model->index(row - 1, 0), Qt::EditRole).toDouble());
|
||||
ui->coordY->setValue(model->data(model->index(row - 1, 1), Qt::EditRole).toDouble());
|
||||
ui->coordZ->setValue(model->data(model->index(row - 1, 2), Qt::EditRole).toDouble());
|
||||
}
|
||||
|
||||
void VectorListEditor::acceptCurrent()
|
||||
{
|
||||
int row = ui->spinBox->value();
|
||||
double x = ui->coordX->value();
|
||||
double y = ui->coordY->value();
|
||||
double z = ui->coordZ->value();
|
||||
QVariant value = QVariant::fromValue<Base::Vector3d>(Base::Vector3d(x, y, z));
|
||||
model->setData(model->index(row - 1, 0), value);
|
||||
}
|
||||
|
||||
void VectorListEditor::addRow()
|
||||
{
|
||||
model->insertRow(ui->tableWidget->currentIndex().row() + 1);
|
||||
ui->spinBox->setMaximum(model->rowCount());
|
||||
ui->spinBox->setEnabled(true);
|
||||
ui->toolButtonRemove->setEnabled(true);
|
||||
}
|
||||
|
||||
void VectorListEditor::removeRow()
|
||||
{
|
||||
model->removeRow(ui->tableWidget->currentIndex().row());
|
||||
int rowCount = model->rowCount();
|
||||
if (rowCount > 0) {
|
||||
ui->spinBox->setRange(1, rowCount);
|
||||
}
|
||||
else {
|
||||
ui->spinBox->setEnabled(false);
|
||||
ui->toolButtonRemove->setEnabled(false);
|
||||
}
|
||||
}
|
||||
|
||||
#include "moc_VectorListEditor.cpp"
|
||||
109
src/Gui/VectorListEditor.h
Normal file
109
src/Gui/VectorListEditor.h
Normal file
@@ -0,0 +1,109 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2020 Werner Mayer <wmayer[at]users.sourceforge.net> *
|
||||
* *
|
||||
* This file is part of the FreeCAD CAx development system. *
|
||||
* *
|
||||
* This library is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU Library General Public *
|
||||
* License as published by the Free Software Foundation; either *
|
||||
* version 2 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 Library General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU Library General Public *
|
||||
* License along with this library; see the file COPYING.LIB. If not, *
|
||||
* write to the Free Software Foundation, Inc., 59 Temple Place, *
|
||||
* Suite 330, Boston, MA 02111-1307, USA *
|
||||
* *
|
||||
***************************************************************************/
|
||||
|
||||
#ifndef GUI_VECTORLISTEDITOR_H
|
||||
#define GUI_VECTORLISTEDITOR_H
|
||||
|
||||
#include <QDialog>
|
||||
#include <QList>
|
||||
#include <QAbstractTableModel>
|
||||
#include <QItemDelegate>
|
||||
#include <memory>
|
||||
#include <Base/Vector3D.h>
|
||||
|
||||
namespace Gui {
|
||||
|
||||
class VectorTableModel : public QAbstractTableModel
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
VectorTableModel(int decimals, QObject *parent = nullptr);
|
||||
|
||||
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const;
|
||||
virtual int columnCount(const QModelIndex &parent = QModelIndex()) const;
|
||||
virtual int rowCount(const QModelIndex &parent = QModelIndex()) const;
|
||||
Qt::ItemFlags flags (const QModelIndex & index) const;
|
||||
bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole);
|
||||
virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
|
||||
virtual QModelIndex parent(const QModelIndex &index) const;
|
||||
void setValues(const QList<Base::Vector3d>& d);
|
||||
const QList<Base::Vector3d>& values() const;
|
||||
virtual bool insertRows(int row, int count, const QModelIndex &parent = QModelIndex());
|
||||
virtual bool removeRows(int row, int count, const QModelIndex &parent = QModelIndex());
|
||||
|
||||
private:
|
||||
QList<Base::Vector3d> vectors;
|
||||
int decimals;
|
||||
};
|
||||
|
||||
class VectorTableDelegate : public QItemDelegate
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
VectorTableDelegate(int decimals, QObject *parent = 0);
|
||||
|
||||
QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option,
|
||||
const QModelIndex &index) const;
|
||||
|
||||
void setEditorData(QWidget *editor, const QModelIndex &index) const;
|
||||
void setModelData(QWidget *editor, QAbstractItemModel *model,
|
||||
const QModelIndex &index) const;
|
||||
|
||||
void updateEditorGeometry(QWidget *editor,
|
||||
const QStyleOptionViewItem &option, const QModelIndex &index) const;
|
||||
|
||||
private:
|
||||
int decimals;
|
||||
};
|
||||
|
||||
class Ui_VectorListEditor;
|
||||
class VectorListEditor : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
VectorListEditor(int decimals, QWidget* parent = nullptr);
|
||||
~VectorListEditor();
|
||||
|
||||
void setValues(const QList<Base::Vector3d>&);
|
||||
const QList<Base::Vector3d>& getValues() const;
|
||||
|
||||
void accept();
|
||||
void reject();
|
||||
|
||||
private Q_SLOTS:
|
||||
void addRow();
|
||||
void removeRow();
|
||||
void acceptCurrent();
|
||||
void setCurrentRow(int);
|
||||
|
||||
private:
|
||||
std::unique_ptr<Ui_VectorListEditor> ui;
|
||||
VectorTableModel* model;
|
||||
QList<Base::Vector3d> data;
|
||||
};
|
||||
|
||||
} // namespace Gui
|
||||
|
||||
#endif // GUI_VECTORLISTEDITOR_H
|
||||
232
src/Gui/VectorListEditor.ui
Normal file
232
src/Gui/VectorListEditor.ui
Normal file
@@ -0,0 +1,232 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>Gui::VectorListEditor</class>
|
||||
<widget class="QDialog" name="Gui::VectorListEditor">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>288</width>
|
||||
<height>476</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Vectors</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout_3">
|
||||
<property name="sizeConstraint">
|
||||
<enum>QLayout::SetFixedSize</enum>
|
||||
</property>
|
||||
<item row="0" column="0">
|
||||
<layout class="QGridLayout" name="gridLayout_2">
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string notr="true">Id:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QSpinBox" name="spinBox">
|
||||
<property name="minimum">
|
||||
<number>1</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="text">
|
||||
<string notr="true">x:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QDoubleSpinBox" name="coordX"/>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QLabel" name="label_3">
|
||||
<property name="text">
|
||||
<string notr="true">y:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<widget class="QDoubleSpinBox" name="coordY"/>
|
||||
</item>
|
||||
<item row="3" column="0">
|
||||
<widget class="QLabel" name="label_4">
|
||||
<property name="text">
|
||||
<string notr="true">z:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="1">
|
||||
<widget class="QDoubleSpinBox" name="coordZ"/>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<spacer name="horizontalSpacer_2">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>47</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item row="0" column="2" rowspan="2">
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="QDialogButtonBox" name="buttonBox">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>17</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="pushButton">
|
||||
<property name="text">
|
||||
<string>Table</string>
|
||||
</property>
|
||||
<property name="checkable">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<widget class="QToolButton" name="toolButtonMouse">
|
||||
<property name="text">
|
||||
<string>...</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="Icons/resource.qrc">
|
||||
<normaloff>:/icons/mouse_pointer.svg</normaloff>:/icons/mouse_pointer.svg</iconset>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QToolButton" name="toolButtonAdd">
|
||||
<property name="text">
|
||||
<string>...</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="Icons/resource.qrc">
|
||||
<normaloff>:/icons/list-add.svg</normaloff>:/icons/list-add.svg</iconset>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QToolButton" name="toolButtonRemove">
|
||||
<property name="text">
|
||||
<string>...</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="Icons/resource.qrc">
|
||||
<normaloff>:/icons/list-remove.svg</normaloff>:/icons/list-remove.svg</iconset>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QToolButton" name="toolButtonAccept">
|
||||
<property name="text">
|
||||
<string>...</string>
|
||||
</property>
|
||||
<property name="icon">
|
||||
<iconset resource="Icons/resource.qrc">
|
||||
<normaloff>:/icons/edit_OK.svg</normaloff>:/icons/edit_OK.svg</iconset>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="2" column="0" colspan="3">
|
||||
<widget class="QWidget" name="widget" native="true">
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>0</width>
|
||||
<height>300</height>
|
||||
</size>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item row="0" column="0">
|
||||
<widget class="QTableView" name="tableWidget">
|
||||
<attribute name="horizontalHeaderDefaultSectionSize">
|
||||
<number>80</number>
|
||||
</attribute>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<tabstops>
|
||||
<tabstop>spinBox</tabstop>
|
||||
<tabstop>coordX</tabstop>
|
||||
<tabstop>coordY</tabstop>
|
||||
<tabstop>coordZ</tabstop>
|
||||
<tabstop>toolButtonMouse</tabstop>
|
||||
<tabstop>toolButtonAdd</tabstop>
|
||||
<tabstop>toolButtonRemove</tabstop>
|
||||
<tabstop>toolButtonAccept</tabstop>
|
||||
<tabstop>tableWidget</tabstop>
|
||||
<tabstop>pushButton</tabstop>
|
||||
</tabstops>
|
||||
<resources>
|
||||
<include location="Icons/resource.qrc"/>
|
||||
</resources>
|
||||
<connections>
|
||||
<connection>
|
||||
<sender>pushButton</sender>
|
||||
<signal>toggled(bool)</signal>
|
||||
<receiver>widget</receiver>
|
||||
<slot>setVisible(bool)</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
<x>44</x>
|
||||
<y>159</y>
|
||||
</hint>
|
||||
<hint type="destinationlabel">
|
||||
<x>51</x>
|
||||
<y>249</y>
|
||||
</hint>
|
||||
</hints>
|
||||
</connection>
|
||||
</connections>
|
||||
</ui>
|
||||
@@ -60,6 +60,7 @@
|
||||
#include <Gui/FileDialog.h>
|
||||
#include <Gui/DlgPropertyLink.h>
|
||||
#include <Gui/QuantitySpinBox.h>
|
||||
#include <Gui/VectorListEditor.h>
|
||||
|
||||
#include "PropertyItem.h"
|
||||
#include "PropertyView.h"
|
||||
@@ -1425,6 +1426,119 @@ void PropertyVectorItem::propertyBound()
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
|
||||
VectorListButton::VectorListButton(int decimals, QWidget * parent)
|
||||
: LabelButton(parent)
|
||||
, decimals(decimals)
|
||||
{
|
||||
}
|
||||
|
||||
VectorListButton::~VectorListButton()
|
||||
{
|
||||
}
|
||||
|
||||
void VectorListButton::browse()
|
||||
{
|
||||
VectorListEditor dlg(decimals, Gui::getMainWindow());
|
||||
dlg.setValues(value().value<QList<Base::Vector3d>>());
|
||||
if (dlg.exec() == QDialog::Accepted) {
|
||||
QVariant data = QVariant::fromValue<QList<Base::Vector3d>>(dlg.getValues());
|
||||
setValue(data);
|
||||
}
|
||||
}
|
||||
|
||||
void VectorListButton::showValue(const QVariant& d)
|
||||
{
|
||||
QLocale loc;
|
||||
QString data;
|
||||
const QList<Base::Vector3d>& value = d.value<QList<Base::Vector3d>>();
|
||||
if (value.isEmpty()) {
|
||||
data = QString::fromLatin1("[]");
|
||||
}
|
||||
else {
|
||||
data = QString::fromLatin1("[%1 %2 %3], ...")
|
||||
.arg(loc.toString(value[0].x, 'f', 2),
|
||||
loc.toString(value[0].y, 'f', 2),
|
||||
loc.toString(value[0].z, 'f', 2));
|
||||
}
|
||||
getLabel()->setText(data);
|
||||
}
|
||||
|
||||
PROPERTYITEM_SOURCE(Gui::PropertyEditor::PropertyVectorListItem)
|
||||
|
||||
PropertyVectorListItem::PropertyVectorListItem()
|
||||
{
|
||||
}
|
||||
|
||||
QVariant PropertyVectorListItem::toString(const QVariant& prop) const
|
||||
{
|
||||
QLocale loc;
|
||||
QString data;
|
||||
const QList<Base::Vector3d>& value = prop.value<QList<Base::Vector3d>>();
|
||||
if (value.isEmpty()) {
|
||||
data = QString::fromLatin1("[]");
|
||||
}
|
||||
else {
|
||||
data = QString::fromLatin1("[%1 %2 %3], ...")
|
||||
.arg(loc.toString(value[0].x, 'f', 2),
|
||||
loc.toString(value[0].y, 'f', 2),
|
||||
loc.toString(value[0].z, 'f', 2));
|
||||
}
|
||||
|
||||
if (hasExpression())
|
||||
data += QString::fromLatin1(" ( %1 )").arg(QString::fromStdString(getExpressionString()));
|
||||
return QVariant(data);
|
||||
}
|
||||
|
||||
QVariant PropertyVectorListItem::value(const App::Property* prop) const
|
||||
{
|
||||
assert(prop && prop->getTypeId().isDerivedFrom(App::PropertyVectorList::getClassTypeId()));
|
||||
|
||||
const std::vector<Base::Vector3d>& value = static_cast<const App::PropertyVectorList*>(prop)->getValue();
|
||||
QList<Base::Vector3d> list;
|
||||
std::copy(value.begin(), value.end(), std::back_inserter(list));
|
||||
return QVariant::fromValue<QList<Base::Vector3d>>(list);
|
||||
}
|
||||
|
||||
void PropertyVectorListItem::setValue(const QVariant& value)
|
||||
{
|
||||
if (!value.canConvert<QList<Base::Vector3d>>())
|
||||
return;
|
||||
const QList<Base::Vector3d>& val = value.value<QList<Base::Vector3d>>();
|
||||
QString data;
|
||||
QTextStream str(&data);
|
||||
str << "[";
|
||||
for (const auto it : val) {
|
||||
str << QString::fromLatin1("(%1, %2, %3), ")
|
||||
.arg(it.x,0,'f',decimals())
|
||||
.arg(it.y,0,'f',decimals())
|
||||
.arg(it.z,0,'f',decimals());
|
||||
}
|
||||
str << "]";
|
||||
setPropertyValue(data);
|
||||
}
|
||||
|
||||
QWidget* PropertyVectorListItem::createEditor(QWidget* parent, const QObject* receiver, const char* method) const
|
||||
{
|
||||
VectorListButton *pe = new VectorListButton(decimals(), parent);
|
||||
QObject::connect(pe, SIGNAL(valueChanged(const QVariant &)), receiver, method);
|
||||
pe->setDisabled(isReadOnly());
|
||||
return pe;
|
||||
}
|
||||
|
||||
void PropertyVectorListItem::setEditorData(QWidget *editor, const QVariant& data) const
|
||||
{
|
||||
VectorListButton *pe = qobject_cast<VectorListButton*>(editor);
|
||||
pe->setValue(data);
|
||||
}
|
||||
|
||||
QVariant PropertyVectorListItem::editorData(QWidget *editor) const
|
||||
{
|
||||
VectorListButton *pe = qobject_cast<VectorListButton*>(editor);
|
||||
return pe->value();
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------
|
||||
|
||||
PROPERTYITEM_SOURCE(Gui::PropertyEditor::PropertyVectorDistanceItem)
|
||||
|
||||
PropertyVectorDistanceItem::PropertyVectorDistanceItem()
|
||||
|
||||
@@ -44,6 +44,7 @@
|
||||
#ifdef Q_MOC_RUN
|
||||
Q_DECLARE_METATYPE(Base::Vector3f)
|
||||
Q_DECLARE_METATYPE(Base::Vector3d)
|
||||
Q_DECLARE_METATYPE(QList<Base::Vector3d>)
|
||||
Q_DECLARE_METATYPE(Base::Matrix4D)
|
||||
Q_DECLARE_METATYPE(Base::Placement)
|
||||
Q_DECLARE_METATYPE(Base::Quantity)
|
||||
@@ -465,6 +466,44 @@ private:
|
||||
PropertyFloatItem* m_z;
|
||||
};
|
||||
|
||||
class VectorListButton : public Gui::LabelButton
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
VectorListButton(int decimals, QWidget * parent = 0);
|
||||
~VectorListButton();
|
||||
|
||||
private:
|
||||
void browse();
|
||||
void showValue(const QVariant& d);
|
||||
|
||||
private:
|
||||
int decimals;
|
||||
};
|
||||
|
||||
/**
|
||||
* Edit properties of vector list type.
|
||||
* \author Werner Mayer
|
||||
*/
|
||||
class GuiExport PropertyVectorListItem : public PropertyItem
|
||||
{
|
||||
Q_OBJECT
|
||||
PROPERTYITEM_HEADER
|
||||
|
||||
virtual QWidget* createEditor(QWidget* parent, const QObject* receiver, const char* method) const;
|
||||
virtual void setEditorData(QWidget *editor, const QVariant& data) const;
|
||||
virtual QVariant editorData(QWidget *editor) const;
|
||||
|
||||
protected:
|
||||
virtual QVariant toString(const QVariant&) const;
|
||||
virtual QVariant value(const App::Property*) const;
|
||||
virtual void setValue(const QVariant&);
|
||||
|
||||
protected:
|
||||
PropertyVectorListItem();
|
||||
};
|
||||
|
||||
/**
|
||||
* Edit properties of vector type which hold distances.
|
||||
* \author Stefan Troeger
|
||||
|
||||
Reference in New Issue
Block a user