Gui: property view related changes
* Display property from linked object, colored green, * Change DlgPropertyLink to support external linking and sub-object selection * Improve large selection performance by using a timer * Improve TAB key behavior in property editor * Add context menu to show hidden properties, change property status, set expression on any and property, and add/remove dynamic properties * Optimize expression completer model construction, as the original implementation gets prohibitively slow for moderate number of objects.
This commit is contained in:
@@ -38,18 +38,26 @@
|
||||
# include <QTextBlock>
|
||||
# include <QTimer>
|
||||
# include <QToolTip>
|
||||
# include <QDebug>
|
||||
#endif
|
||||
|
||||
#include <Base/Tools.h>
|
||||
#include <Base/Exception.h>
|
||||
#include <Base/Interpreter.h>
|
||||
#include <App/Expression.h>
|
||||
|
||||
#include "Command.h"
|
||||
#include "Widgets.h"
|
||||
#include "Application.h"
|
||||
#include "Action.h"
|
||||
#include "PrefWidgets.h"
|
||||
#include "BitmapFactory.h"
|
||||
#include "DlgExpressionInput.h"
|
||||
#include "QuantitySpinBox_p.h"
|
||||
|
||||
using namespace Gui;
|
||||
using namespace App;
|
||||
using namespace Base;
|
||||
|
||||
/**
|
||||
* Constructs an empty command view with parent \a parent.
|
||||
@@ -1403,4 +1411,173 @@ void LabelEditor::setInputType(InputType t)
|
||||
this->type = t;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------
|
||||
|
||||
ExpLineEdit::ExpLineEdit(QWidget* parent, bool expressionOnly)
|
||||
: QLineEdit(parent), autoClose(expressionOnly)
|
||||
{
|
||||
defaultPalette = palette();
|
||||
|
||||
/* Icon for f(x) */
|
||||
QFontMetrics fm(font());
|
||||
int frameWidth = style()->pixelMetric(QStyle::PM_SpinBoxFrameWidth);
|
||||
iconHeight = fm.height() - frameWidth;
|
||||
iconLabel = new ExpressionLabel(this);
|
||||
iconLabel->setCursor(Qt::ArrowCursor);
|
||||
QPixmap pixmap = getIcon(":/icons/bound-expression-unset.svg", QSize(iconHeight, iconHeight));
|
||||
iconLabel->setPixmap(pixmap);
|
||||
iconLabel->setStyleSheet(QString::fromLatin1("QLabel { border: none; padding: 0px; padding-top: %2px; width: %1px; height: %1px }").arg(iconHeight).arg(frameWidth/2));
|
||||
iconLabel->hide();
|
||||
setStyleSheet(QString::fromLatin1("QLineEdit { padding-right: %1px } ").arg(iconHeight+frameWidth));
|
||||
|
||||
QObject::connect(iconLabel, SIGNAL(clicked()), this, SLOT(openFormulaDialog()));
|
||||
if(expressionOnly)
|
||||
QMetaObject::invokeMethod(this, "openFormulaDialog", Qt::QueuedConnection, QGenericReturnArgument());
|
||||
}
|
||||
|
||||
bool ExpLineEdit::apply(const std::string& propName) {
|
||||
|
||||
if (!ExpressionBinding::apply(propName)) {
|
||||
QString val = QString::fromUtf8(Base::Interpreter().strToPython(text().toUtf8()).c_str());
|
||||
Gui::Command::doCommand(Gui::Command::Doc, "%s = \"%s\"", propName.c_str(), val.constData());
|
||||
return true;
|
||||
}
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
void ExpLineEdit::bind(const ObjectIdentifier& _path) {
|
||||
|
||||
ExpressionBinding::bind(_path);
|
||||
|
||||
int frameWidth = style()->pixelMetric(QStyle::PM_SpinBoxFrameWidth);
|
||||
setStyleSheet(QString::fromLatin1("QLineEdit { padding-right: %1px } ").arg(iconLabel->sizeHint().width() + frameWidth + 1));
|
||||
|
||||
iconLabel->show();
|
||||
}
|
||||
|
||||
void ExpLineEdit::setExpression(boost::shared_ptr<Expression> expr)
|
||||
{
|
||||
Q_ASSERT(isBound());
|
||||
|
||||
try {
|
||||
ExpressionBinding::setExpression(expr);
|
||||
}
|
||||
catch (const Base::Exception & e) {
|
||||
setReadOnly(true);
|
||||
QPalette p(palette());
|
||||
p.setColor(QPalette::Active, QPalette::Text, Qt::red);
|
||||
setPalette(p);
|
||||
iconLabel->setToolTip(QString::fromLatin1(e.what()));
|
||||
}
|
||||
}
|
||||
|
||||
void ExpLineEdit::onChange() {
|
||||
|
||||
if (getExpression()) {
|
||||
std::unique_ptr<Expression> result(getExpression()->eval());
|
||||
if(result->isDerivedFrom(App::StringExpression::getClassTypeId()))
|
||||
setText(QString::fromUtf8(static_cast<App::StringExpression*>(
|
||||
result.get())->getText().c_str()));
|
||||
else
|
||||
setText(QString::fromUtf8(result->toString().c_str()));
|
||||
setReadOnly(true);
|
||||
iconLabel->setPixmap(getIcon(":/icons/bound-expression.svg", QSize(iconHeight, iconHeight)));
|
||||
|
||||
QPalette p(palette());
|
||||
p.setColor(QPalette::Text, Qt::lightGray);
|
||||
setPalette(p);
|
||||
setToolTip(Base::Tools::fromStdString(getExpression()->toString()));
|
||||
}
|
||||
else {
|
||||
setReadOnly(false);
|
||||
iconLabel->setPixmap(getIcon(":/icons/bound-expression-unset.svg", QSize(iconHeight, iconHeight)));
|
||||
QPalette p(palette());
|
||||
p.setColor(QPalette::Active, QPalette::Text, defaultPalette.color(QPalette::Text));
|
||||
setPalette(p);
|
||||
|
||||
}
|
||||
iconLabel->setToolTip(QString());
|
||||
}
|
||||
|
||||
void ExpLineEdit::resizeEvent(QResizeEvent * event)
|
||||
{
|
||||
QLineEdit::resizeEvent(event);
|
||||
|
||||
int frameWidth = style()->pixelMetric(QStyle::PM_SpinBoxFrameWidth);
|
||||
|
||||
QSize sz = iconLabel->sizeHint();
|
||||
iconLabel->move(rect().right() - frameWidth - sz.width(), 0);
|
||||
|
||||
try {
|
||||
if (isBound() && getExpression()) {
|
||||
setReadOnly(true);
|
||||
QPixmap pixmap = getIcon(":/icons/bound-expression.svg", QSize(iconHeight, iconHeight));
|
||||
iconLabel->setPixmap(pixmap);
|
||||
|
||||
QPalette p(palette());
|
||||
p.setColor(QPalette::Text, Qt::lightGray);
|
||||
setPalette(p);
|
||||
setToolTip(Base::Tools::fromStdString(getExpression()->toString()));
|
||||
}
|
||||
else {
|
||||
setReadOnly(false);
|
||||
QPixmap pixmap = getIcon(":/icons/bound-expression-unset.svg", QSize(iconHeight, iconHeight));
|
||||
iconLabel->setPixmap(pixmap);
|
||||
|
||||
QPalette p(palette());
|
||||
p.setColor(QPalette::Active, QPalette::Text, defaultPalette.color(QPalette::Text));
|
||||
setPalette(p);
|
||||
|
||||
}
|
||||
iconLabel->setToolTip(QString());
|
||||
}
|
||||
catch (const Base::Exception & e) {
|
||||
setReadOnly(true);
|
||||
QPalette p(palette());
|
||||
p.setColor(QPalette::Active, QPalette::Text, Qt::red);
|
||||
setPalette(p);
|
||||
iconLabel->setToolTip(QString::fromLatin1(e.what()));
|
||||
}
|
||||
}
|
||||
|
||||
void ExpLineEdit::openFormulaDialog()
|
||||
{
|
||||
Q_ASSERT(isBound());
|
||||
|
||||
Gui::Dialog::DlgExpressionInput* box = new Gui::Dialog::DlgExpressionInput(
|
||||
getPath(), getExpression(),Unit(), this);
|
||||
connect(box, SIGNAL(finished(int)), this, SLOT(finishFormulaDialog()));
|
||||
box->show();
|
||||
|
||||
QPoint pos = mapToGlobal(QPoint(0,0));
|
||||
box->move(pos-box->expressionPosition());
|
||||
box->setExpressionInputSize(width(), height());
|
||||
}
|
||||
|
||||
void ExpLineEdit::finishFormulaDialog()
|
||||
{
|
||||
Gui::Dialog::DlgExpressionInput* box = qobject_cast<Gui::Dialog::DlgExpressionInput*>(sender());
|
||||
if (!box) {
|
||||
qWarning() << "Sender is not a Gui::Dialog::DlgExpressionInput";
|
||||
return;
|
||||
}
|
||||
|
||||
if (box->result() == QDialog::Accepted)
|
||||
setExpression(box->getExpression());
|
||||
else if (box->discardedFormula())
|
||||
setExpression(boost::shared_ptr<Expression>());
|
||||
|
||||
box->deleteLater();
|
||||
|
||||
if(autoClose)
|
||||
this->deleteLater();
|
||||
}
|
||||
|
||||
void ExpLineEdit::keyPressEvent(QKeyEvent *event)
|
||||
{
|
||||
if (!hasExpression())
|
||||
QLineEdit::keyPressEvent(event);
|
||||
}
|
||||
|
||||
#include "moc_Widgets.cpp"
|
||||
|
||||
Reference in New Issue
Block a user