diff --git a/.hgignore b/.hgignore index d4f666f85..305d6889b 100644 --- a/.hgignore +++ b/.hgignore @@ -26,17 +26,61 @@ uic/ rcc/ man/ -#Ignore Coverity Scan Build Tool +# Ignore Coverity Scan Build Tool cov-int/ -# Ignore file used QtCreator for user profile. -*.pro.user +# Compiled Object files +*.slo +*.lo +*.o +*.obj -# Ignore file Qt translation. +# Precompiled Headers +*.gch +*.pch + +# Compiled Dynamic libraries +*.so +*.dylib +*.dll + +# Fortran module files +*.mod + +# Compiled Static libraries +*.lai +*.la +*.a +*.lib + +# Executables +*.exe +*.out +*.app + +# Qt-es +/.qmake.cache +/.qmake.stash +*.pro.user +*.pro.user.* +*.moc +moc_*.cpp +qrc_*.cpp +ui_*.h +Makefile* +*-build-* + +# Ignore Qt translation file . *.qm +# QtCreator +*.autosave + # Ignore Mercurial .orig files *.orig -# Ignore Makefile -Makefile +*.rej + +# QtCtreator Qml +*.qmlproject.user +*.qmlproject.user.* diff --git a/src/app/app.pro b/src/app/app.pro index e9ad262be..1b389589b 100644 --- a/src/app/app.pro +++ b/src/app/app.pro @@ -620,29 +620,36 @@ INSTALLS += \ for(_translation_name, TRANSLATIONS) { _translation_name_qm = $$section(_translation_name,".", 0, 0).qm - system($$shell_path($$[QT_INSTALL_BINS]/lrelease) $$shell_path($$PWD/$$_translation_name) -qm $$shell_path($$PWD/$$_translation_name_qm)) + system($$shell_path($$[QT_INSTALL_BINS]/lrelease) $$shell_path($${PWD}/$$_translation_name) -qm $$shell_path($${PWD}/$$_translation_name_qm)) } } for(DIR, INSTALL_TRANSLATIONS) { #add these absolute paths to a variable which #ends up as 'mkcommands = path1 path2 path3 ...' - tr_path += $$PWD/$$DIR + tr_path += $${PWD}/$$DIR } -copyToDestdir($$tr_path, $$shell_path($$OUT_PWD/$$DESTDIR/translations)) +copyToDestdir($$tr_path, $$shell_path($${OUT_PWD}/$$DESTDIR/translations)) for(DIR, INSTALL_STANDARD_MEASHUREMENTS) { #add these absolute paths to a variable which #ends up as 'mkcommands = path1 path2 path3 ...' - st_path += $$PWD/$$DIR + st_path += $${PWD}/$$DIR } -copyToDestdir($$st_path, $$shell_path($$OUT_PWD/$$DESTDIR/tables/standard)) +copyToDestdir($$st_path, $$shell_path($${OUT_PWD}/$$DESTDIR/tables/standard)) -win32:CONFIG(release, debug|release): LIBS += -L$$OUT_PWD/../libs/qmuparser/bin -lqmuparser2 -else:win32:CONFIG(debug, debug|release): LIBS += -L$$OUT_PWD/../libs/qmuparser/bin -lqmuparser2 -else:unix: LIBS += -L$$OUT_PWD/../libs/qmuparser/bin -lqmuparser +win32:CONFIG(release, debug|release): LIBS += -L$${OUT_PWD}/../libs/qmuparser/$${DESTDIR} -lqmuparser2 +else:win32:CONFIG(debug, debug|release): LIBS += -L$${OUT_PWD}/../libs/qmuparser/$${DESTDIR} -lqmuparser2 +else:unix: LIBS += -L$${OUT_PWD}/../libs/qmuparser/$${DESTDIR} -lqmuparser -INCLUDEPATH += $$PWD/../libs/qmuparser -DEPENDPATH += $$PWD/../libs/qmuparser +INCLUDEPATH += $${PWD}/../libs/qmuparser +DEPENDPATH += $${PWD}/../libs/qmuparser + +win32:CONFIG(release, debug|release): LIBS += -L$${OUT_PWD}/../libs/vpropertyexplorer/$${DESTDIR} -lvpropertyexplorer +else:win32:CONFIG(debug, debug|release): LIBS += -L$${OUT_PWD}/../libs/vpropertyexplorer/$${DESTDIR} -lvpropertyexplorer +else:unix: LIBS += -L$${OUT_PWD}/../libs/vpropertyexplorer/$${DESTDIR} -lvpropertyexplorer + +INCLUDEPATH += $${PWD}/../libs/vpropertyexplorer +DEPENDPATH += $${PWD}/../libs/vpropertyexplorer diff --git a/src/app/container/calculator.cpp b/src/app/container/calculator.cpp index 3ea4cb7f1..adcafbdc0 100644 --- a/src/app/container/calculator.cpp +++ b/src/app/container/calculator.cpp @@ -55,14 +55,7 @@ Calculator::Calculator(const VContainer *data) :QmuParser(), vVarVal(nullptr), data(data) { InitCharacterSets(); - - // Add unary operators - DefinePostfixOprt(cm_Oprt, CmUnit); - DefinePostfixOprt(mm_Oprt, MmUnit); - DefinePostfixOprt(in_Oprt, InchUnit); - - SetArgSep(','); - SetDecSep('.'); + setAllowSubexpressions(false);//Only one expression per time } //--------------------------------------------------------------------------------------------------------------------- @@ -85,15 +78,12 @@ Calculator::Calculator(const QString &formula, bool fromUser) :QmuParser(), vVarVal(nullptr), data(nullptr) { InitCharacterSets(); + setAllowSubexpressions(false);//Only one expression per time SetVarFactory(AddVariable, this); // Add unary operators if (fromUser) { - DefinePostfixOprt(qApp->PostfixOperator(cm_Oprt), CmUnit); - DefinePostfixOprt(qApp->PostfixOperator(mm_Oprt), MmUnit); - DefinePostfixOprt(qApp->PostfixOperator(in_Oprt), InchUnit); - bool osSeparatorValue = qApp->getSettings()->value("configuration/osSeparator", 1).toBool(); if (osSeparatorValue) @@ -111,16 +101,13 @@ Calculator::Calculator(const QString &formula, bool fromUser) } else { - DefinePostfixOprt(cm_Oprt, CmUnit); - DefinePostfixOprt(mm_Oprt, MmUnit); - DefinePostfixOprt(in_Oprt, InchUnit); SetArgSep(','); SetDecSep('.'); } SetExpr(formula); - //Need run for making tokens. Don't catch exception here, because because we want know if formula has error. + //Need run for making tokens. Don't catch exception here, because we want know if formula has error. Eval(); } @@ -152,15 +139,12 @@ qreal Calculator::EvalFormula(const QString &formula) } // Add variables - InitVariables(data, tokens); - - result = Eval(); - - return result; + InitVariables(data, tokens, formula); + return Eval(); } //--------------------------------------------------------------------------------------------------------------------- -void Calculator::InitVariables(const VContainer *data, const QMap &tokens) +void Calculator::InitVariables(const VContainer *data, const QMap &tokens, const QString &formula) { if (qApp->patternType() == MeasurementsType::Standard) { @@ -169,9 +153,11 @@ void Calculator::InitVariables(const VContainer *data, const QMap const QHash > *vars = data->DataVariables(); + bool found = false; QMap::const_iterator i = tokens.constBegin(); while (i != tokens.constEnd()) { + found = false; if (vars->contains(i.value())) { QSharedPointer var = vars->value(i.value()); @@ -182,6 +168,7 @@ void Calculator::InitVariables(const VContainer *data, const QMap m->SetValue(data->size(), data->height()); } DefineVar(i.value(), var->GetValue()); + found = true; } if (qApp->patternType() == MeasurementsType::Standard) @@ -190,14 +177,21 @@ void Calculator::InitVariables(const VContainer *data, const QMap { vVarVal[0] = data->size(); DefineVar(data->SizeName(), &vVarVal[0]); + found = true; } if (i.value() == data->HeightName()) { vVarVal[1] = data->height(); DefineVar(data->HeightName(), &vVarVal[1]); + found = true; } } + + if (found == false) + { + throw qmu::QmuParserError (ecUNASSIGNABLE_TOKEN , i.value(), formula, i.key()); + } ++i; } } @@ -221,69 +215,6 @@ void Calculator::InitCharacterSets() DefineOprtChars(symbols + QStringLiteral("+-*^/?<>=#!$%&|~'_")); } -//--------------------------------------------------------------------------------------------------------------------- -qreal Calculator::CmUnit(qreal val) -{ - qreal unit = val; - switch (qApp->patternUnit()) - { - case Unit::Mm: - unit = val * 10.0; - break; - case Unit::Cm: - break; - case Unit::Inch: - unit = val / 2.54; - break; - default: - break; - } - - return unit; -} - -//--------------------------------------------------------------------------------------------------------------------- -qreal Calculator::MmUnit(qreal val) -{ - qreal unit = val; - switch (qApp->patternUnit()) - { - case Unit::Mm: - break; - case Unit::Cm: - unit = val / 10.0; - break; - case Unit::Inch: - unit = val / 25.4; - break; - default: - break; - } - - return unit; -} - -//--------------------------------------------------------------------------------------------------------------------- -qreal Calculator::InchUnit(qreal val) -{ - qreal unit = val; - switch (qApp->patternUnit()) - { - case Unit::Mm: - unit = val * 25.4; - break; - case Unit::Cm: - unit = val * 2.54; - break; - case Unit::Inch: - break; - default: - break; - } - - return unit; -} - //--------------------------------------------------------------------------- // Factory function for creating new parser variables // This could as well be a function performing database queries. diff --git a/src/app/container/calculator.h b/src/app/container/calculator.h index 9ec6c303d..c0c11b090 100644 --- a/src/app/container/calculator.h +++ b/src/app/container/calculator.h @@ -64,11 +64,8 @@ private: qreal *vVarVal; static int iVal; const VContainer *data; - void InitVariables(const VContainer *data, const QMap &tokens); + void InitVariables(const VContainer *data, const QMap &tokens, const QString &formula); void InitCharacterSets(); - static qreal CmUnit(qreal val); - static qreal MmUnit(qreal val); - static qreal InchUnit(qreal val); static qreal* AddVariable(const QString &a_szName, void *a_pUserData); }; diff --git a/src/app/container/container.pri b/src/app/container/container.pri index 758aaf921..2c1e50367 100644 --- a/src/app/container/container.pri +++ b/src/app/container/container.pri @@ -9,7 +9,8 @@ SOURCES += \ container/varclength.cpp \ container/vcurvelength.cpp \ container/vlinelength.cpp \ - container/vsplinelength.cpp + container/vsplinelength.cpp \ + container/vformula.cpp HEADERS += \ container/vcontainer.h \ @@ -30,4 +31,5 @@ HEADERS += \ container/vcurvelength_p.h \ container/vlineangle_p.h \ container/vlinelength_p.h \ - container/vmeasurement_p.h + container/vmeasurement_p.h \ + container/vformula.h diff --git a/src/app/container/vcontainer.cpp b/src/app/container/vcontainer.cpp index 0e9960bd4..865c79c56 100644 --- a/src/app/container/vcontainer.cpp +++ b/src/app/container/vcontainer.cpp @@ -37,6 +37,7 @@ quint32 VContainer::_id = NULL_ID; qreal VContainer::_size = 50; qreal VContainer::_height = 176; +QSet VContainer::uniqueNames = QSet(); //--------------------------------------------------------------------------------------------------------------------- /** @@ -138,6 +139,7 @@ quint32 VContainer::AddGObject(VGObject *obj) { SCASSERT(obj != nullptr); QSharedPointer pointer(obj); + uniqueNames.insert(obj->name()); return AddObject(d->gObjects, pointer); } @@ -210,6 +212,7 @@ void VContainer::Clear() d->details.clear(); ClearVariables(); ClearGObjects(); + ClearUniqueNames(); } //--------------------------------------------------------------------------------------------------------------------- @@ -334,6 +337,7 @@ void VContainer::UpdateGObject(quint32 id, VGObject* obj) SCASSERT(obj != nullptr); QSharedPointer pointer(obj); UpdateObject(d->gObjects, id, pointer); + uniqueNames.insert(obj->name()); } //--------------------------------------------------------------------------------------------------------------------- @@ -407,6 +411,12 @@ const QMap > VContainer::DataAngleLines() co return DataVar(VarType::LineAngle); } +//--------------------------------------------------------------------------------------------------------------------- +bool VContainer::IsUnique(const QString &name) +{ + return !uniqueNames.contains(name); +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief VariableExist check if exist variable this same name. @@ -442,6 +452,12 @@ void VContainer::ClearDetails() d->details.clear(); } +//--------------------------------------------------------------------------------------------------------------------- +void VContainer::ClearUniqueNames() +{ + uniqueNames.clear(); +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief SetSize set value of size diff --git a/src/app/container/vcontainer.h b/src/app/container/vcontainer.h index 08cc0fa86..18eff2599 100644 --- a/src/app/container/vcontainer.h +++ b/src/app/container/vcontainer.h @@ -37,6 +37,7 @@ #include #include +#include #ifdef Q_CC_GNU #pragma GCC diagnostic push @@ -186,6 +187,7 @@ public: } } d->variables[name] = QSharedPointer(var); + uniqueNames.insert(name); } void UpdateGObject(quint32 id, VGObject* obj); @@ -196,6 +198,7 @@ public: void ClearCalculationGObjects(); void ClearVariables(const VarType &type = VarType::Unknown); void ClearDetails(); + static void ClearUniqueNames(); void SetSize(qreal size); void SetSizeName(const QString &name); @@ -221,6 +224,7 @@ public: const QMap > DataLengthArcs() const; const QMap > DataAngleLines() const; + static bool IsUnique(const QString &name); private: /** @@ -229,6 +233,7 @@ private: static quint32 _id; static qreal _size; static qreal _height; + static QSet uniqueNames; QSharedDataPointer d; diff --git a/src/app/container/vformula.cpp b/src/app/container/vformula.cpp new file mode 100644 index 000000000..b9a9719ea --- /dev/null +++ b/src/app/container/vformula.cpp @@ -0,0 +1,266 @@ +/************************************************************************ + ** + ** @file vformula.cpp + ** @author Roman Telezhynskyi + ** @date 28 8, 2014 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2014 Valentina project + ** All Rights Reserved. + ** + ** Valentina 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. + ** + ** Valentina 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 for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with Valentina. If not, see . + ** + *************************************************************************/ + +#include "vformula.h" +#include "../container/calculator.h" +#include "../container/vcontainer.h" +#include "../widgets/vapplication.h" + +//VFormula +//--------------------------------------------------------------------------------------------------------------------- +VFormula::VFormula() + :formula(QString()), value(QString(tr("Error"))), checkZero(true), data(nullptr), toolId(NULL_ID), + postfix(QStringLiteral("")), _error(true), dValue(0) +{} + +//--------------------------------------------------------------------------------------------------------------------- +VFormula::VFormula(const QString &formula, const VContainer *container) + :formula(qApp->FormulaToUser(formula)), value(QString(tr("Error"))), checkZero(true), data(container), toolId(NULL_ID), + postfix(QStringLiteral("")), _error(true), dValue(0) +{ + this->formula.replace("\n", " ");// Replace line return with spaces for calc if exist + Eval(); +} + +//--------------------------------------------------------------------------------------------------------------------- +VFormula &VFormula::operator=(const VFormula &formula) +{ + if ( &formula == this ) + { + return *this; + } + this->formula = formula.getFormula(); + this->value = formula.getStringValue(); + this->checkZero = formula.getCheckZero(); + this->data = formula.getData(); + this->toolId = formula.getToolId(); + this->postfix = formula.getPostfix(); + this->_error = formula.error(); + this->dValue = formula.getDoubleValue(); + return *this; +} + +//--------------------------------------------------------------------------------------------------------------------- +VFormula::VFormula(const VFormula &formula) + :formula(formula.getFormula()), value(formula.getStringValue()), checkZero(formula.getCheckZero()), + data(formula.getData()), toolId(formula.getToolId()), postfix(formula.getPostfix()), _error(formula.error()), + dValue(formula.getDoubleValue()) +{} + +//--------------------------------------------------------------------------------------------------------------------- +bool VFormula::operator==(const VFormula &formula) const +{ + bool isEqual = false; + if (this->formula == formula.getFormula() && this->value == formula.getStringValue() && + this->checkZero == formula.getCheckZero() && this->data == formula.getData() && + this->toolId == formula.getToolId() && this->postfix == formula.getPostfix() && + this->_error == formula.error() && this->dValue == formula.getDoubleValue()) + { + isEqual = true; + } + return isEqual; +} + +bool VFormula::operator!=(const VFormula &formula) const +{ + return !VFormula::operator==(formula); +} + +//--------------------------------------------------------------------------------------------------------------------- +QString VFormula::getFormula(FormulaType type) const +{ + if (type == FormulaType::ToUser) + { + return formula; + } + else + { + return qApp->FormulaFromUser(formula); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VFormula::setFormula(const QString &value, FormulaType type) +{ + if (formula != value) + { + if (type == FormulaType::ToUser) + { + formula = value; + } + else + { + formula = qApp->FormulaToUser(value); + } + formula.replace("\n", " ");// Replace line return with spaces for calc if exist + Eval(); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +QString VFormula::getStringValue() const +{ + return value; +} + +//--------------------------------------------------------------------------------------------------------------------- +qreal VFormula::getDoubleValue() const +{ + return dValue; +} + +//--------------------------------------------------------------------------------------------------------------------- +bool VFormula::getCheckZero() const +{ + return checkZero; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VFormula::setCheckZero(bool value) +{ + if (checkZero != value) + { + checkZero = value; + Eval(); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +const VContainer *VFormula::getData() const +{ + return data; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VFormula::setData(const VContainer *value) +{ + if (data != value && value != nullptr) + { + data = value; + Eval(); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +quint32 VFormula::getToolId() const +{ + return toolId; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VFormula::setToolId(const quint32 &value) +{ + toolId = value; +} + +//--------------------------------------------------------------------------------------------------------------------- +QString VFormula::getPostfix() const +{ + return postfix; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VFormula::setPostfix(const QString &value) +{ + if (postfix != value) + { + postfix = value; + Eval(); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +bool VFormula::error() const +{ + return _error; +} + +//--------------------------------------------------------------------------------------------------------------------- +int VFormula::FormulaTypeId() +{ + return qMetaTypeId(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VFormula::Eval() +{ + if (data == nullptr) + { + return; + } + if (formula.isEmpty()) + { + value = QString(tr("Error")); + _error = true; + dValue = 0; + } + else + { + try + { + Calculator *cal = new Calculator(data); + QString expression = qApp->FormulaFromUser(formula); + const qreal result = cal->EvalFormula(expression); + delete cal; + + //if result equal 0 + if (checkZero && qFuzzyCompare(1 + result, 1 + 0)) + { + value = QString("0"); + _error = true; + dValue = 0; + } + else + { + QLocale loc; + if (qApp->getSettings()->value("configuration/osSeparator", 1).toBool()) + { + loc = QLocale::system(); + } + else + { + loc = QLocale(QLocale::C); + } + dValue = result; + value = QString(loc.toString(result) + " " + postfix); + _error = false; + } + } + catch (qmu::QmuParserError &e) + { + value = QString(tr("Error")); + _error = true; + dValue = 0; + qDebug() << "\nMath parser error:\n" + << "--------------------------------------\n" + << "Message: " << e.GetMsg() << "\n" + << "Expression: " << e.GetExpr() << "\n" + << "--------------------------------------"; + } + } +} diff --git a/src/app/container/vformula.h b/src/app/container/vformula.h new file mode 100644 index 000000000..222845442 --- /dev/null +++ b/src/app/container/vformula.h @@ -0,0 +1,84 @@ +/************************************************************************ + ** + ** @file vformula.h + ** @author Roman Telezhynskyi + ** @date 28 8, 2014 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2014 Valentina project + ** All Rights Reserved. + ** + ** Valentina 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. + ** + ** Valentina 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 for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with Valentina. If not, see . + ** + *************************************************************************/ + +#ifndef VFORMULA_H +#define VFORMULA_H + +#include + +enum class FormulaType : char{ToUser, FromUser}; + +class VContainer; + +class VFormula +{ + Q_DECLARE_TR_FUNCTIONS(VFormula) +public: + VFormula(); + VFormula(const QString &formula, const VContainer *container); + VFormula &operator=(const VFormula &formula); + VFormula(const VFormula &formula); + bool operator==(const VFormula &formula) const; + bool operator!=(const VFormula &formula) const; + + QString getFormula(FormulaType type = FormulaType::ToUser) const; + void setFormula(const QString &value, FormulaType type = FormulaType::ToUser); + + QString getStringValue() const; + qreal getDoubleValue() const; + + bool getCheckZero() const; + void setCheckZero(bool value); + + const VContainer *getData() const; + void setData(const VContainer *value); + + quint32 getToolId() const; + void setToolId(const quint32 &value); + + QString getPostfix() const; + void setPostfix(const QString &value); + + bool error() const; + + static int FormulaTypeId(); +private: + QString formula; + QString value; + bool checkZero; + const VContainer *data; + quint32 toolId; + QString postfix; + bool _error; + qreal dValue; + + void Eval(); +}; +Q_DECLARE_METATYPE(VFormula) + +#endif // VFORMULA_H diff --git a/src/app/dialogs/app/configpages/configurationpage.cpp b/src/app/dialogs/app/configpages/configurationpage.cpp index 6c91267d1..46bddce59 100644 --- a/src/app/dialogs/app/configpages/configurationpage.cpp +++ b/src/app/dialogs/app/configpages/configurationpage.cpp @@ -43,8 +43,8 @@ //--------------------------------------------------------------------------------------------------------------------- ConfigurationPage::ConfigurationPage(QWidget *parent) - : QWidget(parent), autoSaveCheck(nullptr), autoTime(nullptr), langCombo(nullptr), unitCombo(nullptr), - osOptionCheck(nullptr), langChanged(false), unitChanged(false) + : QWidget(parent), autoSaveCheck(nullptr), autoTime(nullptr), langCombo(nullptr), labelCombo(nullptr), + unitCombo(nullptr), osOptionCheck(nullptr), langChanged(false), unitChanged(false), labelLangChanged(false) { QGroupBox *saveGroup = SaveGroup(); QGroupBox *langGroup = LangGroup(); @@ -93,6 +93,12 @@ void ConfigurationPage::Apply() QString text = QString(tr("Default unit updated and will be used the next pattern creation")); QMessageBox::information(this, QApplication::applicationName(), text); } + if (labelLangChanged) + { + QString locale = qvariant_cast(labelCombo->itemData(labelCombo->currentIndex())); + qApp->getSettings()->setValue("configuration/label_language", locale); + labelLangChanged = false; + } } //--------------------------------------------------------------------------------------------------------------------- @@ -107,6 +113,12 @@ void ConfigurationPage::UnitChanged() this->unitChanged = true; } +//--------------------------------------------------------------------------------------------------------------------- +void ConfigurationPage::LabelLangChanged() +{ + labelLangChanged = true; +} + //--------------------------------------------------------------------------------------------------------------------- QGroupBox *ConfigurationPage::SaveGroup() { @@ -227,13 +239,47 @@ QGroupBox *ConfigurationPage::LangGroup() UnitLayout->addWidget(unitLabel); UnitLayout->addWidget(this->unitCombo); - //----------------------- Unit setup + //----------------------- Label language + + QLabel *labelName = new QLabel(tr("Label language")); + labelCombo = new QComboBox; + + QString checkedLabelLocale = settings->value("configuration/label_language", defaultLocale).toString(); + + QStringList list{"de", "en" , "fr" , "ru" , "uk"}; + SetLabelComboBox(list); + + index = labelCombo->findData(checkedLabelLocale); + if (index != -1) + { + labelCombo->setCurrentIndex(index); + } + connect(labelCombo, static_cast(&QComboBox::currentIndexChanged), this, + &ConfigurationPage::LabelLangChanged); + + QHBoxLayout *labelLangLayout = new QHBoxLayout; + labelLangLayout->addWidget(labelName); + labelLangLayout->addWidget(labelCombo); + + //----------------------- QVBoxLayout *langLayout = new QVBoxLayout; langLayout->addLayout(guiLangLayout); langLayout->addLayout(separatorLayout); langLayout->addLayout(UnitLayout); + langLayout->addLayout(labelLangLayout); langGroup->setLayout(langLayout); return langGroup; } + +//--------------------------------------------------------------------------------------------------------------------- +void ConfigurationPage::SetLabelComboBox(const QStringList &list) +{ + for (int i = 0; i < list.size(); ++i) + { + QString lang = QLocale(list.at(i)).nativeLanguageName(); + QIcon ico(QString("%1/%2.png").arg("://icon/flags").arg(list.at(i))); + labelCombo->addItem(ico, lang, list.at(i)); + } +} diff --git a/src/app/dialogs/app/configpages/configurationpage.h b/src/app/dialogs/app/configpages/configurationpage.h index 9e32fee0e..0bad4043c 100644 --- a/src/app/dialogs/app/configpages/configurationpage.h +++ b/src/app/dialogs/app/configpages/configurationpage.h @@ -46,17 +46,22 @@ public: public slots: void LangChanged(); void UnitChanged(); + void LabelLangChanged(); private: Q_DISABLE_COPY(ConfigurationPage) QCheckBox *autoSaveCheck; QSpinBox *autoTime; QComboBox *langCombo; + QComboBox *labelCombo; QComboBox *unitCombo; QCheckBox *osOptionCheck; bool langChanged; bool unitChanged; + bool labelLangChanged; + QGroupBox *SaveGroup(); QGroupBox *LangGroup(); + void SetLabelComboBox(const QStringList &list); }; #endif // CONFIGURATIONPAGE_H diff --git a/src/app/dialogs/app/dialoghistory.cpp b/src/app/dialogs/app/dialoghistory.cpp index 188efdb7a..d0950ed16 100644 --- a/src/app/dialogs/app/dialoghistory.cpp +++ b/src/app/dialogs/app/dialoghistory.cpp @@ -213,44 +213,44 @@ QString DialogHistory::Record(const VToolRecord &tool) { switch ( tool.getTypeTool() ) { - case Tool::ArrowTool: + case Tool::Arrow: Q_UNREACHABLE(); break; - case Tool::SinglePointTool: + case Tool::SinglePoint: { return QString(tr("%1 - Base point")).arg(PointName(tool.getId())); } - case Tool::EndLineTool: + case Tool::EndLine: { return QString(tr("%1_%2 - Line from point %1 to point %2")) .arg(PointName(AttrUInt(domElem, VAbstractTool::AttrBasePoint))) .arg(PointName(tool.getId())); } - case Tool::LineTool: + case Tool::Line: { return QString(tr("%1_%2 - Line from point %1 to point %2")) .arg(PointName(AttrUInt(domElem, VAbstractTool::AttrFirstPoint))) .arg(PointName(AttrUInt(domElem, VAbstractTool::AttrSecondPoint))); } - case Tool::AlongLineTool: + case Tool::AlongLine: { return QString(tr("%3 - Point along line %1_%2")) .arg(PointName(AttrUInt(domElem, VAbstractTool::AttrFirstPoint))) .arg(PointName(AttrUInt(domElem, VAbstractTool::AttrSecondPoint))) .arg(PointName(tool.getId())); } - case Tool::ShoulderPointTool: + case Tool::ShoulderPoint: { return QString(tr("%1 - Point of shoulder")).arg(PointName(tool.getId())); } - case Tool::NormalTool: + case Tool::Normal: { return QString(tr("%3 - normal to line %1_%2")) .arg(PointName(AttrUInt(domElem, VAbstractTool::AttrFirstPoint))) .arg(PointName(AttrUInt(domElem, VAbstractTool::AttrSecondPoint))) .arg(PointName(tool.getId())); } - case Tool::BisectorTool: + case Tool::Bisector: { return QString(tr("%4 - bisector of angle %1_%2_%3")) .arg(PointName(AttrUInt(domElem, VAbstractTool::AttrFirstPoint))) @@ -258,7 +258,7 @@ QString DialogHistory::Record(const VToolRecord &tool) .arg(PointName(AttrUInt(domElem, VAbstractTool::AttrThirdPoint))) .arg(PointName(tool.getId())); } - case Tool::LineIntersectTool: + case Tool::LineIntersect: { return QString(tr("%5 - intersection of lines %1_%2 and %3_%4")) .arg(PointName(AttrUInt(domElem, VAbstractTool::AttrP1Line1))) @@ -267,19 +267,19 @@ QString DialogHistory::Record(const VToolRecord &tool) .arg(PointName(AttrUInt(domElem, VAbstractTool::AttrP2Line2))) .arg(PointName(tool.getId())); } - case Tool::SplineTool: + case Tool::Spline: { const QSharedPointer spl = data->GeometricObject(tool.getId()); SCASSERT(spl != nullptr); return QString(tr("Curve %1_%2")).arg(PointName(spl->GetP1().id())).arg(PointName(spl->GetP4().id())); } - case Tool::ArcTool: + case Tool::Arc: { const QSharedPointer arc = data->GeometricObject(tool.getId()); SCASSERT(arc != nullptr); return QString(tr("Arc with center in point %1")).arg(PointName(arc->GetCenter().id())); } - case Tool::SplinePathTool: + case Tool::SplinePath: { const QSharedPointer splPath = data->GeometricObject(tool.getId()); SCASSERT(splPath != nullptr); @@ -331,7 +331,7 @@ QString DialogHistory::Record(const VToolRecord &tool) .arg(PointName(AttrUInt(domElem, VAbstractTool::AttrFirstPoint))) .arg(PointName(AttrUInt(domElem, VAbstractTool::AttrSecondPoint))); } - case Tool::CutArcTool: + case Tool::CutArc: { const QSharedPointer arc = data->GeometricObject(AttrUInt(domElem, VToolCutArc::AttrArc)); SCASSERT(arc != nullptr); @@ -339,7 +339,7 @@ QString DialogHistory::Record(const VToolRecord &tool) .arg(PointName(tool.getId())) .arg(PointName(arc->GetCenter().id())); } - case Tool::CutSplineTool: + case Tool::CutSpline: { const quint32 splineId = AttrUInt(domElem, VToolCutSpline::AttrSpline); const QSharedPointer spl = data->GeometricObject(splineId); @@ -349,7 +349,7 @@ QString DialogHistory::Record(const VToolRecord &tool) .arg(PointName(spl->GetP1().id())) .arg(PointName(spl->GetP4().id())); } - case Tool::CutSplinePathTool: + case Tool::CutSplinePath: { const quint32 splinePathId = AttrUInt(domElem, VToolCutSplinePath::AttrSplinePath); const QSharedPointer splPath = data->GeometricObject(splinePathId); @@ -375,7 +375,7 @@ QString DialogHistory::Record(const VToolRecord &tool) } //Because "history" not only show history of pattern, but help restore current data for each pattern's //piece, we need add record about details and nodes, but don't show them. - case Tool::DetailTool: + case Tool::Detail: break; case Tool::UnionDetails: break; diff --git a/src/app/dialogs/app/dialogincrements.cpp b/src/app/dialogs/app/dialogincrements.cpp index d2fd0853f..e40893726 100644 --- a/src/app/dialogs/app/dialogincrements.cpp +++ b/src/app/dialogs/app/dialogincrements.cpp @@ -69,9 +69,7 @@ DialogIncrements::DialogIncrements(VContainer *data, VPattern *doc, QWidget *par } } - //Same regex in pattern.xsd shema file. Don't forget synchronize. - TextDelegate *textDelegate = new TextDelegate("^([^0-9-*/^+=\\s\\(\\)%:;!.,]){1,1}([^-*/^+=\\s\\(\\)%:;!.,]){0,}$", - data, ui->tableWidgetIncrement); + TextDelegate *textDelegate = new TextDelegate(nameRegExp, data, ui->tableWidgetIncrement); ui->tableWidgetIncrement->setItemDelegateForColumn(0, textDelegate);// name DoubleSpinBoxDelegate *doubleDelegate = new DoubleSpinBoxDelegate(ui->tableWidgetIncrement); ui->tableWidgetIncrement->setItemDelegateForColumn(2, doubleDelegate);// base value diff --git a/src/app/dialogs/tools/dialogalongline.cpp b/src/app/dialogs/tools/dialogalongline.cpp index c2b67d9bb..3ccc55d5a 100644 --- a/src/app/dialogs/tools/dialogalongline.cpp +++ b/src/app/dialogs/tools/dialogalongline.cpp @@ -41,19 +41,20 @@ * @param parent parent widget */ DialogAlongLine::DialogAlongLine(const VContainer *data, const quint32 &toolId, QWidget *parent) - :DialogTool(data, toolId, parent), ui(new Ui::DialogAlongLine), number(0), pointName(QString()), + :DialogTool(data, toolId, parent), ui(new Ui::DialogAlongLine), number(0), typeLine(QString()), formula(QString()), firstPointId(NULL_ID), secondPointId(NULL_ID), formulaBaseHeight(0), line(nullptr) { ui->setupUi(this); InitVariables(ui); InitFormulaUI(ui); + ui->lineEditNamePoint->setText(qApp->getCurrentDocument()->GenerateLabel(LabelType::NewLabel)); labelEditNamePoint = ui->labelEditNamePoint; + this->formulaBaseHeight = ui->plainTextEditFormula->height(); InitOkCancelApply(ui); flagFormula = false; - flagName = false; CheckState(); FillComboBoxPoints(ui->comboBoxFirstPoint); diff --git a/src/app/dialogs/tools/dialogalongline.h b/src/app/dialogs/tools/dialogalongline.h index 4eeb9265a..335ffd22a 100644 --- a/src/app/dialogs/tools/dialogalongline.h +++ b/src/app/dialogs/tools/dialogalongline.h @@ -87,9 +87,6 @@ private: /** @brief number number of handled objects */ qint32 number; - /** @brief pointName name of point */ - QString pointName; - /** @brief typeLine type of line */ QString typeLine; diff --git a/src/app/dialogs/tools/dialogalongline.ui b/src/app/dialogs/tools/dialogalongline.ui index 37da60097..7fea4abba 100644 --- a/src/app/dialogs/tools/dialogalongline.ui +++ b/src/app/dialogs/tools/dialogalongline.ui @@ -220,43 +220,6 @@ - - - - - - - 255 - 0 - 0 - - - - - - - - - 255 - 0 - 0 - - - - - - - - - 159 - 158 - 158 - - - - - - Point label diff --git a/src/app/dialogs/tools/dialogarc.ui b/src/app/dialogs/tools/dialogarc.ui index 8689df614..9e751d4ee 100644 --- a/src/app/dialogs/tools/dialogarc.ui +++ b/src/app/dialogs/tools/dialogarc.ui @@ -522,6 +522,9 @@ + + 9 + diff --git a/src/app/dialogs/tools/dialogbisector.cpp b/src/app/dialogs/tools/dialogbisector.cpp index 2526aa7d4..8b8c5ec0f 100644 --- a/src/app/dialogs/tools/dialogbisector.cpp +++ b/src/app/dialogs/tools/dialogbisector.cpp @@ -42,19 +42,19 @@ * @param parent parent widget */ DialogBisector::DialogBisector(const VContainer *data, const quint32 &toolId, QWidget *parent) - :DialogTool(data, toolId, parent), ui(new Ui::DialogBisector), number(0), pointName(QString()), typeLine(QString()), + :DialogTool(data, toolId, parent), ui(new Ui::DialogBisector), number(0), typeLine(QString()), formula(QString()), firstPointId(NULL_ID), secondPointId(NULL_ID), thirdPointId(NULL_ID), formulaBaseHeight(0), line(nullptr), prepare(false) { ui->setupUi(this); InitVariables(ui); InitFormulaUI(ui); + ui->lineEditNamePoint->setText(qApp->getCurrentDocument()->GenerateLabel(LabelType::NewLabel)); labelEditNamePoint = ui->labelEditNamePoint; this->formulaBaseHeight = ui->plainTextEditFormula->height(); InitOkCancelApply(ui); flagFormula = false; - flagName = false; CheckState(); FillComboBoxPoints(ui->comboBoxFirstPoint); diff --git a/src/app/dialogs/tools/dialogbisector.h b/src/app/dialogs/tools/dialogbisector.h index 12fbdfacf..6a0816a45 100644 --- a/src/app/dialogs/tools/dialogbisector.h +++ b/src/app/dialogs/tools/dialogbisector.h @@ -92,9 +92,6 @@ private: /** @brief number number of handled objects */ qint32 number; - /** @brief pointName name of point */ - QString pointName; - /** @brief typeLine type of line */ QString typeLine; diff --git a/src/app/dialogs/tools/dialogbisector.ui b/src/app/dialogs/tools/dialogbisector.ui index 0172c1140..e004708ac 100644 --- a/src/app/dialogs/tools/dialogbisector.ui +++ b/src/app/dialogs/tools/dialogbisector.ui @@ -217,43 +217,6 @@ 0 - - - - - - - 255 - 0 - 0 - - - - - - - - - 255 - 0 - 0 - - - - - - - - - 159 - 158 - 158 - - - - - - Point label diff --git a/src/app/dialogs/tools/dialogcutarc.cpp b/src/app/dialogs/tools/dialogcutarc.cpp index 599960f14..312354b2c 100644 --- a/src/app/dialogs/tools/dialogcutarc.cpp +++ b/src/app/dialogs/tools/dialogcutarc.cpp @@ -33,6 +33,7 @@ #include "../../container/vcontainer.h" #include "../../visualization/vistoolcutarc.h" #include "../../widgets/vmaingraphicsscene.h" +#include "../../xml/vpattern.h" //--------------------------------------------------------------------------------------------------------------------- /** @@ -41,18 +42,18 @@ * @param parent parent widget */ DialogCutArc::DialogCutArc(const VContainer *data, const quint32 &toolId, QWidget *parent) - : DialogTool(data, toolId, parent), ui(new Ui::DialogCutArc), pointName(QString()), formula(QString()), + : DialogTool(data, toolId, parent), ui(new Ui::DialogCutArc), formula(QString()), arcId(NULL_ID), formulaBaseHeight(0), path(nullptr) { ui->setupUi(this); InitVariables(ui); InitFormulaUI(ui); + ui->lineEditNamePoint->setText(qApp->getCurrentDocument()->GenerateLabel(LabelType::NewLabel)); labelEditNamePoint = ui->labelEditNamePoint; this->formulaBaseHeight = ui->plainTextEditFormula->height(); InitOkCancelApply(ui); flagFormula = false; - flagName = false; CheckState(); FillComboBoxArcs(ui->comboBoxArc); diff --git a/src/app/dialogs/tools/dialogcutarc.h b/src/app/dialogs/tools/dialogcutarc.h index a01f5c1e5..a320b7e37 100644 --- a/src/app/dialogs/tools/dialogcutarc.h +++ b/src/app/dialogs/tools/dialogcutarc.h @@ -78,9 +78,6 @@ private: /** @brief ui keeps information about user interface */ Ui::DialogCutArc *ui; - /** @brief pointName name of created point */ - QString pointName; - /** @brief formula string with formula */ QString formula; diff --git a/src/app/dialogs/tools/dialogcutarc.ui b/src/app/dialogs/tools/dialogcutarc.ui index 7efe094bc..f13d05840 100644 --- a/src/app/dialogs/tools/dialogcutarc.ui +++ b/src/app/dialogs/tools/dialogcutarc.ui @@ -238,43 +238,6 @@ 0 - - - - - - - 255 - 0 - 0 - - - - - - - - - 255 - 0 - 0 - - - - - - - - - 159 - 158 - 158 - - - - - - Point label diff --git a/src/app/dialogs/tools/dialogcutspline.cpp b/src/app/dialogs/tools/dialogcutspline.cpp index 985c1d512..c99c3338c 100644 --- a/src/app/dialogs/tools/dialogcutspline.cpp +++ b/src/app/dialogs/tools/dialogcutspline.cpp @@ -31,6 +31,8 @@ #include "../../geometry/vspline.h" #include "../../container/vcontainer.h" +#include "../../xml/vpattern.h" +#include "../../visualization/vistoolcutspline.h" //--------------------------------------------------------------------------------------------------------------------- /** @@ -39,18 +41,18 @@ * @param parent parent widget */ DialogCutSpline::DialogCutSpline(const VContainer *data, const quint32 &toolId, QWidget *parent) - :DialogTool(data, toolId, parent), ui(new Ui::DialogCutSpline), pointName(QString()), formula(QString()), - splineId(NULL_ID), formulaBaseHeight(0) + :DialogTool(data, toolId, parent), ui(new Ui::DialogCutSpline), formula(QString()), + splineId(NULL_ID), formulaBaseHeight(0), path(nullptr) { ui->setupUi(this); InitVariables(ui); InitFormulaUI(ui); + ui->lineEditNamePoint->setText(qApp->getCurrentDocument()->GenerateLabel(LabelType::NewLabel)); labelEditNamePoint = ui->labelEditNamePoint; this->formulaBaseHeight = ui->plainTextEditFormula->height(); - InitOkCancel(ui); + InitOkCancelApply(ui); flagFormula = false; - flagName = false; CheckState(); FillComboBoxSplines(ui->comboBoxSpline); @@ -61,11 +63,14 @@ DialogCutSpline::DialogCutSpline(const VContainer *data, const quint32 &toolId, connect(ui->lineEditNamePoint, &QLineEdit::textChanged, this, &DialogCutSpline::NamePointChanged); connect(ui->plainTextEditFormula, &QPlainTextEdit::textChanged, this, &DialogCutSpline::FormulaChanged); connect(ui->pushButtonGrowLength, &QPushButton::clicked, this, &DialogCutSpline::DeployFormulaTextEdit); + + path = new VisToolCutSpline(data); } //--------------------------------------------------------------------------------------------------------------------- DialogCutSpline::~DialogCutSpline() { + delete path; delete ui; } @@ -95,6 +100,7 @@ void DialogCutSpline::setFormula(const QString &value) this->DeployFormulaTextEdit(); } ui->plainTextEditFormula->setPlainText(formula); + path->setLength(formula); } //--------------------------------------------------------------------------------------------------------------------- @@ -105,6 +111,7 @@ void DialogCutSpline::setFormula(const QString &value) void DialogCutSpline::setSplineId(const quint32 &value) { setCurrentSplineId(ui->comboBoxSpline, splineId, value, ComboBoxCutSpline::CutSpline); + path->setPoint1Id(splineId); } //--------------------------------------------------------------------------------------------------------------------- @@ -121,6 +128,8 @@ void DialogCutSpline::ChosenObject(quint32 id, const SceneObject &type) { if (SetObject(id, ui->comboBoxSpline, "")) { + path->VisualMode(id); + prepare = true; this->setModal(true); this->show(); } @@ -135,6 +144,10 @@ void DialogCutSpline::SaveData() formula = ui->plainTextEditFormula->toPlainText(); formula.replace("\n", " "); splineId = getCurrentObjectId(ui->comboBoxSpline); + + path->setPoint1Id(splineId); + path->setLength(formula); + path->RefreshGeometry(); } //--------------------------------------------------------------------------------------------------------------------- @@ -142,3 +155,15 @@ void DialogCutSpline::DeployFormulaTextEdit() { DeployFormula(ui->plainTextEditFormula, ui->pushButtonGrowLength, formulaBaseHeight); } + +//--------------------------------------------------------------------------------------------------------------------- +void DialogCutSpline::ShowVisualization() +{ + if (prepare == false) + { + VMainGraphicsScene *scene = qApp->getCurrentScene(); + connect(scene, &VMainGraphicsScene::NewFactor, path, &Visualization::SetFactor); + scene->addItem(path); + path->RefreshGeometry(); + } +} diff --git a/src/app/dialogs/tools/dialogcutspline.h b/src/app/dialogs/tools/dialogcutspline.h index 11833bd25..257324c54 100644 --- a/src/app/dialogs/tools/dialogcutspline.h +++ b/src/app/dialogs/tools/dialogcutspline.h @@ -36,6 +36,8 @@ namespace Ui class DialogCutSpline; } +class VisToolCutSpline; + /** * @brief The DialogCutSpline class dialog for ToolCutSpline. */ @@ -61,6 +63,7 @@ public slots: */ void DeployFormulaTextEdit(); protected: + virtual void ShowVisualization(); /** * @brief SaveData Put dialog data in local variables */ @@ -71,9 +74,6 @@ private: /** @brief ui keeps information about user interface */ Ui::DialogCutSpline *ui; - /** @brief pointName name of created point */ - QString pointName; - /** @brief formula string with formula */ QString formula; @@ -82,6 +82,8 @@ private: /** @brief formulaBaseHeight base height defined by dialogui */ int formulaBaseHeight; + + VisToolCutSpline *path; }; //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/dialogs/tools/dialogcutspline.ui b/src/app/dialogs/tools/dialogcutspline.ui index ea8f6e9b9..c17f5f0c5 100644 --- a/src/app/dialogs/tools/dialogcutspline.ui +++ b/src/app/dialogs/tools/dialogcutspline.ui @@ -238,43 +238,6 @@ 0 - - - - - - - 255 - 0 - 0 - - - - - - - - - 255 - 0 - 0 - - - - - - - - - 159 - 158 - 158 - - - - - - Point label @@ -429,7 +392,7 @@ Qt::Horizontal - QDialogButtonBox::Cancel|QDialogButtonBox::Ok + QDialogButtonBox::Apply|QDialogButtonBox::Cancel|QDialogButtonBox::Ok diff --git a/src/app/dialogs/tools/dialogcutsplinepath.cpp b/src/app/dialogs/tools/dialogcutsplinepath.cpp index 7448318a9..6c01dd21d 100644 --- a/src/app/dialogs/tools/dialogcutsplinepath.cpp +++ b/src/app/dialogs/tools/dialogcutsplinepath.cpp @@ -31,6 +31,8 @@ #include "../../geometry/vsplinepath.h" #include "../../container/vcontainer.h" +#include "../../xml/vpattern.h" +#include "../../visualization/vistoolcutsplinepath.h" //--------------------------------------------------------------------------------------------------------------------- /** @@ -39,18 +41,18 @@ * @param parent parent widget */ DialogCutSplinePath::DialogCutSplinePath(const VContainer *data, const quint32 &toolId, QWidget *parent) - :DialogTool(data, toolId, parent), ui(new Ui::DialogCutSplinePath), pointName(QString()), formula(QString()), - splinePathId(NULL_ID), formulaBaseHeight(0) + :DialogTool(data, toolId, parent), ui(new Ui::DialogCutSplinePath), formula(QString()), + splinePathId(NULL_ID), formulaBaseHeight(0), path(nullptr) { ui->setupUi(this); InitVariables(ui); InitFormulaUI(ui); + ui->lineEditNamePoint->setText(qApp->getCurrentDocument()->GenerateLabel(LabelType::NewLabel)); labelEditNamePoint = ui->labelEditNamePoint; this->formulaBaseHeight = ui->plainTextEditFormula->height(); - InitOkCancel(ui); + InitOkCancelApply(ui); flagFormula = false; - flagName = false; CheckState(); FillComboBoxSplinesPath(ui->comboBoxSplinePath); @@ -61,11 +63,14 @@ DialogCutSplinePath::DialogCutSplinePath(const VContainer *data, const quint32 & connect(ui->lineEditNamePoint, &QLineEdit::textChanged, this, &DialogCutSplinePath::NamePointChanged); connect(ui->plainTextEditFormula, &QPlainTextEdit::textChanged, this, &DialogCutSplinePath::FormulaChanged); connect(ui->pushButtonGrowLength, &QPushButton::clicked, this, &DialogCutSplinePath::DeployFormulaTextEdit); + + path = new VisToolCutSplinePath(data); } //--------------------------------------------------------------------------------------------------------------------- DialogCutSplinePath::~DialogCutSplinePath() { + delete path; delete ui; } @@ -95,6 +100,7 @@ void DialogCutSplinePath::setFormula(const QString &value) this->DeployFormulaTextEdit(); } ui->plainTextEditFormula->setPlainText(formula); + path->setLength(formula); } //--------------------------------------------------------------------------------------------------------------------- @@ -105,6 +111,7 @@ void DialogCutSplinePath::setFormula(const QString &value) void DialogCutSplinePath::setSplinePathId(const quint32 &value) { setCurrentSplinePathId(ui->comboBoxSplinePath, splinePathId, value, ComboBoxCutSpline::CutSpline); + path->setPoint1Id(splinePathId); } //--------------------------------------------------------------------------------------------------------------------- @@ -121,6 +128,8 @@ void DialogCutSplinePath::ChosenObject(quint32 id, const SceneObject &type) { if (SetObject(id, ui->comboBoxSplinePath, "")) { + path->VisualMode(id); + prepare = true; this->setModal(true); this->show(); } @@ -135,6 +144,10 @@ void DialogCutSplinePath::SaveData() formula = ui->plainTextEditFormula->toPlainText(); formula.replace("\n", " "); splinePathId = getCurrentObjectId(ui->comboBoxSplinePath); + + path->setPoint1Id(splinePathId); + path->setLength(formula); + path->RefreshGeometry(); } //--------------------------------------------------------------------------------------------------------------------- @@ -142,3 +155,15 @@ void DialogCutSplinePath::DeployFormulaTextEdit() { DeployFormula(ui->plainTextEditFormula, ui->pushButtonGrowLength, formulaBaseHeight); } + +//--------------------------------------------------------------------------------------------------------------------- +void DialogCutSplinePath::ShowVisualization() +{ + if (prepare == false) + { + VMainGraphicsScene *scene = qApp->getCurrentScene(); + connect(scene, &VMainGraphicsScene::NewFactor, path, &Visualization::SetFactor); + scene->addItem(path); + path->RefreshGeometry(); + } +} diff --git a/src/app/dialogs/tools/dialogcutsplinepath.h b/src/app/dialogs/tools/dialogcutsplinepath.h index a6676629a..ff06576c1 100644 --- a/src/app/dialogs/tools/dialogcutsplinepath.h +++ b/src/app/dialogs/tools/dialogcutsplinepath.h @@ -36,6 +36,8 @@ namespace Ui class DialogCutSplinePath; } +class VisToolCutSplinePath; + /** * @brief The DialogCutSplinePath class dialog for ToolCutSplinePath. */ @@ -61,6 +63,7 @@ public slots: */ void DeployFormulaTextEdit(); protected: + virtual void ShowVisualization(); /** * @brief SaveData Put dialog data in local variables */ @@ -71,9 +74,6 @@ private: /** @brief ui keeps information about user interface */ Ui::DialogCutSplinePath *ui; - /** @brief pointName name of created point */ - QString pointName; - /** @brief formula string with formula */ QString formula; @@ -82,6 +82,8 @@ private: /** @brief formulaBaseHeight base height defined by dialogui */ int formulaBaseHeight; + + VisToolCutSplinePath *path; }; //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/dialogs/tools/dialogcutsplinepath.ui b/src/app/dialogs/tools/dialogcutsplinepath.ui index 881de2939..788de6c27 100644 --- a/src/app/dialogs/tools/dialogcutsplinepath.ui +++ b/src/app/dialogs/tools/dialogcutsplinepath.ui @@ -238,43 +238,6 @@ 0 - - - - - - - 255 - 0 - 0 - - - - - - - - - 255 - 0 - 0 - - - - - - - - - 159 - 158 - 158 - - - - - - Point label @@ -429,7 +392,7 @@ Qt::Horizontal - QDialogButtonBox::Cancel|QDialogButtonBox::Ok + QDialogButtonBox::Apply|QDialogButtonBox::Cancel|QDialogButtonBox::Ok diff --git a/src/app/dialogs/tools/dialogeditwrongformula.cpp b/src/app/dialogs/tools/dialogeditwrongformula.cpp index 34b7e8c6a..6c81c10bb 100644 --- a/src/app/dialogs/tools/dialogeditwrongformula.cpp +++ b/src/app/dialogs/tools/dialogeditwrongformula.cpp @@ -31,7 +31,8 @@ //--------------------------------------------------------------------------------------------------------------------- DialogEditWrongFormula::DialogEditWrongFormula(const VContainer *data, const quint32 &toolId, QWidget *parent) - :DialogTool(data, toolId, parent), ui(new Ui::DialogEditWrongFormula), formula(QString()), formulaBaseHeight(0) + :DialogTool(data, toolId, parent), ui(new Ui::DialogEditWrongFormula), formula(QString()), formulaBaseHeight(0), + checkZero(false), postfix(QStringLiteral("")), restoreCursor(false) { ui->setupUi(this); InitVariables(ui); @@ -51,7 +52,14 @@ DialogEditWrongFormula::DialogEditWrongFormula(const VContainer *data, const qui //Disable Qt::WaitCursor #ifndef QT_NO_CURSOR - QApplication::restoreOverrideCursor(); + if (QApplication::overrideCursor() != nullptr) + { + if (QApplication::overrideCursor()->shape() == Qt::WaitCursor) + { + restoreCursor = true; + QApplication::restoreOverrideCursor(); + } + } #endif } @@ -59,7 +67,10 @@ DialogEditWrongFormula::DialogEditWrongFormula(const VContainer *data, const qui DialogEditWrongFormula::~DialogEditWrongFormula() { #ifndef QT_NO_CURSOR - QApplication::setOverrideCursor(Qt::WaitCursor); + if (restoreCursor) + { + QApplication::setOverrideCursor(Qt::WaitCursor); + } #endif delete ui; } @@ -91,8 +102,7 @@ void DialogEditWrongFormula::EvalFormula() { SCASSERT(plainTextEditFormula != nullptr); SCASSERT(labelResultCalculation != nullptr); - const QString postfix = QStringLiteral(""); - Eval(plainTextEditFormula->toPlainText(), flagFormula, timerFormula, labelResultCalculation, postfix); + Eval(plainTextEditFormula->toPlainText(), flagFormula, timerFormula, labelResultCalculation, postfix, checkZero); } //--------------------------------------------------------------------------------------------------------------------- @@ -115,6 +125,18 @@ void DialogEditWrongFormula::setFormula(const QString &value) ui->plainTextEditFormula->setPlainText(formula); } +//--------------------------------------------------------------------------------------------------------------------- +void DialogEditWrongFormula::setCheckZero(bool value) +{ + checkZero = value; +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogEditWrongFormula::setPostfix(const QString &value) +{ + postfix = value; +} + //--------------------------------------------------------------------------------------------------------------------- QString DialogEditWrongFormula::getFormula() const { diff --git a/src/app/dialogs/tools/dialogeditwrongformula.h b/src/app/dialogs/tools/dialogeditwrongformula.h index 5e070c2b0..8a6de06e9 100644 --- a/src/app/dialogs/tools/dialogeditwrongformula.h +++ b/src/app/dialogs/tools/dialogeditwrongformula.h @@ -53,6 +53,8 @@ public: QString getFormula() const; void setFormula(const QString &value); + void setCheckZero(bool value); + void setPostfix(const QString &value); public slots: virtual void DialogAccepted(); virtual void DialogRejected(); @@ -72,6 +74,10 @@ private: /** @brief formulaBaseHeight base height defined by dialogui */ int formulaBaseHeight; + + bool checkZero; + QString postfix; + bool restoreCursor; }; diff --git a/src/app/dialogs/tools/dialogeditwrongformula.ui b/src/app/dialogs/tools/dialogeditwrongformula.ui index 1c240dfa3..c24142095 100644 --- a/src/app/dialogs/tools/dialogeditwrongformula.ui +++ b/src/app/dialogs/tools/dialogeditwrongformula.ui @@ -14,7 +14,7 @@ - Edit wrong formula + Edit formula diff --git a/src/app/dialogs/tools/dialogendline.cpp b/src/app/dialogs/tools/dialogendline.cpp index f1bc2253e..e1009d46a 100644 --- a/src/app/dialogs/tools/dialogendline.cpp +++ b/src/app/dialogs/tools/dialogendline.cpp @@ -42,20 +42,20 @@ * @param parent parent widget */ DialogEndLine::DialogEndLine(const VContainer *data, const quint32 &toolId, QWidget *parent) - :DialogTool(data, toolId, parent), ui(new Ui::DialogEndLine), pointName(QString()), typeLine(QString()), + :DialogTool(data, toolId, parent), ui(new Ui::DialogEndLine), typeLine(QString()), formulaLength(QString()), formulaAngle(QString()), basePointId(NULL_ID), formulaBaseHeight(0), formulaBaseHeightAngle(0), line(nullptr) { ui->setupUi(this); InitVariables(ui); InitFormulaUI(ui); + ui->lineEditNamePoint->setText(qApp->getCurrentDocument()->GenerateLabel(LabelType::NewLabel)); labelEditNamePoint = ui->labelEditNamePoint; this->formulaBaseHeight = ui->plainTextEditFormula->height(); this->formulaBaseHeightAngle = ui->plainTextEditAngle->height(); InitOkCancelApply(ui); flagFormula = false; - flagName = false; CheckState(); FillComboBoxPoints(ui->comboBoxBasePoint); diff --git a/src/app/dialogs/tools/dialogendline.h b/src/app/dialogs/tools/dialogendline.h index b0a9eed1c..6fa3ebfc4 100644 --- a/src/app/dialogs/tools/dialogendline.h +++ b/src/app/dialogs/tools/dialogendline.h @@ -89,9 +89,6 @@ private: /** @brief ui keeps information about user interface */ Ui::DialogEndLine *ui; - /** @brief pointName name of point */ - QString pointName; - /** @brief typeLine type of line */ QString typeLine; diff --git a/src/app/dialogs/tools/dialogendline.ui b/src/app/dialogs/tools/dialogendline.ui index 49b0313da..e541832af 100644 --- a/src/app/dialogs/tools/dialogendline.ui +++ b/src/app/dialogs/tools/dialogendline.ui @@ -323,7 +323,7 @@ - Value of length + Value of angle _ @@ -423,43 +423,6 @@ 0 - - - - - - - 255 - 0 - 0 - - - - - - - - - 255 - 0 - 0 - - - - - - - - - 159 - 158 - 158 - - - - - - Point label diff --git a/src/app/dialogs/tools/dialogheight.cpp b/src/app/dialogs/tools/dialogheight.cpp index 5fb40d6b1..020c12a7b 100644 --- a/src/app/dialogs/tools/dialogheight.cpp +++ b/src/app/dialogs/tools/dialogheight.cpp @@ -42,13 +42,13 @@ * @param parent parent widget */ DialogHeight::DialogHeight(const VContainer *data, const quint32 &toolId, QWidget *parent) - :DialogTool(data, toolId, parent), ui(new Ui::DialogHeight), number(0), pointName(QString()), + :DialogTool(data, toolId, parent), ui(new Ui::DialogHeight), number(0), typeLine(QString()), basePointId(NULL_ID), p1LineId(NULL_ID), p2LineId(NULL_ID), line(nullptr) { ui->setupUi(this); + ui->lineEditNamePoint->setText(qApp->getCurrentDocument()->GenerateLabel(LabelType::NewLabel)); labelEditNamePoint = ui->labelEditNamePoint; InitOkCancelApply(ui); - flagName = false; CheckState(); FillComboBoxPoints(ui->comboBoxBasePoint); diff --git a/src/app/dialogs/tools/dialogheight.h b/src/app/dialogs/tools/dialogheight.h index 8d4c33f01..8c384b145 100644 --- a/src/app/dialogs/tools/dialogheight.h +++ b/src/app/dialogs/tools/dialogheight.h @@ -81,9 +81,6 @@ private: /** @brief number number of handled objects */ qint32 number; - /** @brief pointName name of point */ - QString pointName; - /** @brief typeLine type of line */ QString typeLine; diff --git a/src/app/dialogs/tools/dialogheight.ui b/src/app/dialogs/tools/dialogheight.ui index 006e1817b..5acad9cd7 100644 --- a/src/app/dialogs/tools/dialogheight.ui +++ b/src/app/dialogs/tools/dialogheight.ui @@ -31,43 +31,6 @@ 0 - - - - - - - 255 - 0 - 0 - - - - - - - - - 255 - 0 - 0 - - - - - - - - - 159 - 158 - 158 - - - - - - Point label diff --git a/src/app/dialogs/tools/dialoglineintersect.cpp b/src/app/dialogs/tools/dialoglineintersect.cpp index 674eb5ac9..4de620302 100644 --- a/src/app/dialogs/tools/dialoglineintersect.cpp +++ b/src/app/dialogs/tools/dialoglineintersect.cpp @@ -33,6 +33,7 @@ #include "../../container/vcontainer.h" #include "../../visualization/vistoollineintersect.h" #include "../../widgets/vmaingraphicsscene.h" +#include "../../xml/vpattern.h" //--------------------------------------------------------------------------------------------------------------------- /** @@ -41,14 +42,14 @@ * @param parent parent widget */ DialogLineIntersect::DialogLineIntersect(const VContainer *data, const quint32 &toolId, QWidget *parent) - :DialogTool(data, toolId, parent), ui(new Ui::DialogLineIntersect), number(0), pointName(QString()), + :DialogTool(data, toolId, parent), ui(new Ui::DialogLineIntersect), number(0), p1Line1(NULL_ID), p2Line1(NULL_ID), p1Line2(NULL_ID), p2Line2(NULL_ID), flagPoint(true), line(nullptr) { ui->setupUi(this); number = 0; InitOkCancelApply(ui); + ui->lineEditNamePoint->setText(qApp->getCurrentDocument()->GenerateLabel(LabelType::NewLabel)); labelEditNamePoint = ui->labelEditNamePoint; - flagName = false; FillComboBoxPoints(ui->comboBoxP1Line1); FillComboBoxPoints(ui->comboBoxP2Line1); diff --git a/src/app/dialogs/tools/dialoglineintersect.h b/src/app/dialogs/tools/dialoglineintersect.h index 474261208..93f686f73 100644 --- a/src/app/dialogs/tools/dialoglineintersect.h +++ b/src/app/dialogs/tools/dialoglineintersect.h @@ -85,9 +85,6 @@ private: /** @brief number number of handled objects */ qint32 number; - /** @brief pointName name of point */ - QString pointName; - /** @brief p1Line1 id first point of first line */ quint32 p1Line1; diff --git a/src/app/dialogs/tools/dialoglineintersect.ui b/src/app/dialogs/tools/dialoglineintersect.ui index 96d2bc764..53e5d3f89 100644 --- a/src/app/dialogs/tools/dialoglineintersect.ui +++ b/src/app/dialogs/tools/dialoglineintersect.ui @@ -31,43 +31,6 @@ 0 - - - - - - - 255 - 0 - 0 - - - - - - - - - 255 - 0 - 0 - - - - - - - - - 159 - 158 - 158 - - - - - - Point label diff --git a/src/app/dialogs/tools/dialognormal.cpp b/src/app/dialogs/tools/dialognormal.cpp index 72122f60f..01dd8bdde 100644 --- a/src/app/dialogs/tools/dialognormal.cpp +++ b/src/app/dialogs/tools/dialognormal.cpp @@ -39,18 +39,18 @@ * @param parent parent widget */ DialogNormal::DialogNormal(const VContainer *data, const quint32 &toolId, QWidget *parent) - :DialogTool(data, toolId, parent), ui(new Ui::DialogNormal), number(0), pointName(QString()), typeLine(QString()), + :DialogTool(data, toolId, parent), ui(new Ui::DialogNormal), number(0), typeLine(QString()), formula(QString()), angle(0), firstPointId(NULL_ID), secondPointId(NULL_ID), formulaBaseHeight(0), line(nullptr) { ui->setupUi(this); InitVariables(ui); InitFormulaUI(ui); + ui->lineEditNamePoint->setText(qApp->getCurrentDocument()->GenerateLabel(LabelType::NewLabel)); labelEditNamePoint = ui->labelEditNamePoint; this->formulaBaseHeight = ui->plainTextEditFormula->height(); InitOkCancelApply(ui); flagFormula = false; - flagName = false; CheckState(); FillComboBoxPoints(ui->comboBoxFirstPoint); diff --git a/src/app/dialogs/tools/dialognormal.h b/src/app/dialogs/tools/dialognormal.h index 4c52ad887..222ced37b 100644 --- a/src/app/dialogs/tools/dialognormal.h +++ b/src/app/dialogs/tools/dialognormal.h @@ -91,9 +91,6 @@ private: /** @brief number number of handled objects */ qint32 number; - /** @brief pointName name of point */ - QString pointName; - /** @brief typeLine type of line */ QString typeLine; diff --git a/src/app/dialogs/tools/dialognormal.ui b/src/app/dialogs/tools/dialognormal.ui index 4ec34e02b..6ea7bf7f6 100644 --- a/src/app/dialogs/tools/dialognormal.ui +++ b/src/app/dialogs/tools/dialognormal.ui @@ -220,43 +220,6 @@ 0 - - - - - - - 255 - 0 - 0 - - - - - - - - - 255 - 0 - 0 - - - - - - - - - 159 - 158 - 158 - - - - - - Point label diff --git a/src/app/dialogs/tools/dialogpointofcontact.cpp b/src/app/dialogs/tools/dialogpointofcontact.cpp index 207306b3c..a4f6331c8 100644 --- a/src/app/dialogs/tools/dialogpointofcontact.cpp +++ b/src/app/dialogs/tools/dialogpointofcontact.cpp @@ -32,6 +32,7 @@ #include "../../container/vcontainer.h" #include "../../visualization/vistoolpointofcontact.h" #include "../../widgets/vmaingraphicsscene.h" +#include "../../xml/vpattern.h" //--------------------------------------------------------------------------------------------------------------------- /** @@ -40,18 +41,18 @@ * @param parent parent widget */ DialogPointOfContact::DialogPointOfContact(const VContainer *data, const quint32 &toolId, QWidget *parent) - :DialogTool(data, toolId, parent), ui(new Ui::DialogPointOfContact), number(0), pointName(QString()), + :DialogTool(data, toolId, parent), ui(new Ui::DialogPointOfContact), number(0), radius(QString()), center(NULL_ID), firstPoint(NULL_ID), secondPoint(NULL_ID), formulaBaseHeight(0), line(nullptr) { ui->setupUi(this); InitVariables(ui); InitFormulaUI(ui); + ui->lineEditNamePoint->setText(qApp->getCurrentDocument()->GenerateLabel(LabelType::NewLabel)); labelEditNamePoint = ui->labelEditNamePoint; this->formulaBaseHeight = ui->plainTextEditFormula->height(); InitOkCancelApply(ui); flagFormula = false; - flagName = false; CheckState(); FillComboBoxPoints(ui->comboBoxFirstPoint); diff --git a/src/app/dialogs/tools/dialogpointofcontact.h b/src/app/dialogs/tools/dialogpointofcontact.h index 5887ec95a..11fd4ed7a 100644 --- a/src/app/dialogs/tools/dialogpointofcontact.h +++ b/src/app/dialogs/tools/dialogpointofcontact.h @@ -89,9 +89,6 @@ private: /** @brief number number of handled objects */ qint32 number; - /** @brief pointName name of point */ - QString pointName; - /** @brief radius radius of arc */ QString radius; diff --git a/src/app/dialogs/tools/dialogpointofcontact.ui b/src/app/dialogs/tools/dialogpointofcontact.ui index 30ed3122d..8098355be 100644 --- a/src/app/dialogs/tools/dialogpointofcontact.ui +++ b/src/app/dialogs/tools/dialogpointofcontact.ui @@ -220,43 +220,6 @@ 0 - - - - - - - 255 - 0 - 0 - - - - - - - - - 255 - 0 - 0 - - - - - - - - - 159 - 158 - 158 - - - - - - Point label diff --git a/src/app/dialogs/tools/dialogpointofintersection.cpp b/src/app/dialogs/tools/dialogpointofintersection.cpp index 4dd2c5bd9..0788a791c 100644 --- a/src/app/dialogs/tools/dialogpointofintersection.cpp +++ b/src/app/dialogs/tools/dialogpointofintersection.cpp @@ -33,6 +33,7 @@ #include "../../container/vcontainer.h" #include "../../visualization/vistoolpointofintersection.h" #include "../../widgets/vmaingraphicsscene.h" +#include "../../xml/vpattern.h" //--------------------------------------------------------------------------------------------------------------------- /** @@ -41,14 +42,14 @@ * @param parent parent widget */ DialogPointOfIntersection::DialogPointOfIntersection(const VContainer *data, const quint32 &toolId, QWidget *parent) - :DialogTool(data, toolId, parent), ui(new Ui::DialogPointOfIntersection), number(0), pointName(QString()), + :DialogTool(data, toolId, parent), ui(new Ui::DialogPointOfIntersection), number(0), firstPointId(NULL_ID), secondPointId(NULL_ID), line(nullptr) { ui->setupUi(this); + ui->lineEditNamePoint->setText(qApp->getCurrentDocument()->GenerateLabel(LabelType::NewLabel)); labelEditNamePoint = ui->labelEditNamePoint; InitOkCancelApply(ui); - flagName = false; CheckState(); FillComboBoxPoints(ui->comboBoxFirstPoint); diff --git a/src/app/dialogs/tools/dialogpointofintersection.h b/src/app/dialogs/tools/dialogpointofintersection.h index ef1074baf..00fb7648b 100644 --- a/src/app/dialogs/tools/dialogpointofintersection.h +++ b/src/app/dialogs/tools/dialogpointofintersection.h @@ -75,9 +75,6 @@ private: /** @brief number number of handled objects */ qint32 number; - /** @brief pointName name of point */ - QString pointName; - /** @brief firstPointId id first point of line */ quint32 firstPointId; diff --git a/src/app/dialogs/tools/dialogpointofintersection.ui b/src/app/dialogs/tools/dialogpointofintersection.ui index db3a4c052..f31727a7c 100644 --- a/src/app/dialogs/tools/dialogpointofintersection.ui +++ b/src/app/dialogs/tools/dialogpointofintersection.ui @@ -28,43 +28,6 @@ 0 - - - - - - - 255 - 0 - 0 - - - - - - - - - 255 - 0 - 0 - - - - - - - - - 159 - 158 - 158 - - - - - - Point label diff --git a/src/app/dialogs/tools/dialogshoulderpoint.cpp b/src/app/dialogs/tools/dialogshoulderpoint.cpp index 2fbaf4b69..eed3962de 100644 --- a/src/app/dialogs/tools/dialogshoulderpoint.cpp +++ b/src/app/dialogs/tools/dialogshoulderpoint.cpp @@ -42,19 +42,19 @@ * @param parent parent widget */ DialogShoulderPoint::DialogShoulderPoint(const VContainer *data, const quint32 &toolId, QWidget *parent) - :DialogTool(data, toolId, parent), ui(new Ui::DialogShoulderPoint), number(0), pointName(QString()), + :DialogTool(data, toolId, parent), ui(new Ui::DialogShoulderPoint), number(0), typeLine(QString()), formula(QString()), p1Line(NULL_ID), p2Line(NULL_ID), pShoulder(NULL_ID), formulaBaseHeight(0), line (nullptr) { ui->setupUi(this); InitVariables(ui); InitFormulaUI(ui); + ui->lineEditNamePoint->setText(qApp->getCurrentDocument()->GenerateLabel(LabelType::NewLabel)); labelEditNamePoint = ui->labelEditNamePoint; this->formulaBaseHeight = ui->plainTextEditFormula->height(); InitOkCancelApply(ui); flagFormula = false; - flagName = false; CheckState(); FillComboBoxTypeLine(ui->comboBoxLineType); diff --git a/src/app/dialogs/tools/dialogshoulderpoint.h b/src/app/dialogs/tools/dialogshoulderpoint.h index 192cd7387..f4e09d955 100644 --- a/src/app/dialogs/tools/dialogshoulderpoint.h +++ b/src/app/dialogs/tools/dialogshoulderpoint.h @@ -91,9 +91,6 @@ private: /** @brief number number of handled objects */ qint32 number; - /** @brief pointName name of point */ - QString pointName; - /** @brief typeLine type of line */ QString typeLine; diff --git a/src/app/dialogs/tools/dialogshoulderpoint.ui b/src/app/dialogs/tools/dialogshoulderpoint.ui index 2696419e7..1325d9919 100644 --- a/src/app/dialogs/tools/dialogshoulderpoint.ui +++ b/src/app/dialogs/tools/dialogshoulderpoint.ui @@ -220,43 +220,6 @@ 0 - - - - - - - 255 - 0 - 0 - - - - - - - - - 255 - 0 - 0 - - - - - - - - - 159 - 158 - 158 - - - - - - Point label diff --git a/src/app/dialogs/tools/dialogsinglepoint.ui b/src/app/dialogs/tools/dialogsinglepoint.ui index 24aa830f2..aa0bcbc91 100644 --- a/src/app/dialogs/tools/dialogsinglepoint.ui +++ b/src/app/dialogs/tools/dialogsinglepoint.ui @@ -73,43 +73,6 @@ 17 - - - - - - - 255 - 0 - 0 - - - - - - - - - 255 - 0 - 0 - - - - - - - - - 159 - 158 - 158 - - - - - - Point label diff --git a/src/app/dialogs/tools/dialogsplinepath.cpp b/src/app/dialogs/tools/dialogsplinepath.cpp index 833737387..7a05b4c45 100644 --- a/src/app/dialogs/tools/dialogsplinepath.cpp +++ b/src/app/dialogs/tools/dialogsplinepath.cpp @@ -30,6 +30,7 @@ #include "ui_dialogsplinepath.h" #include "../../geometry/vsplinepoint.h" #include "../../container/vcontainer.h" +#include "../../visualization/vistoolsplinepath.h" //--------------------------------------------------------------------------------------------------------------------- /** @@ -38,10 +39,10 @@ * @param parent parent widget */ DialogSplinePath::DialogSplinePath(const VContainer *data, const quint32 &toolId, QWidget *parent) - :DialogTool(data, toolId, parent), ui(new Ui::DialogSplinePath), path(VSplinePath()) + :DialogTool(data, toolId, parent), ui(new Ui::DialogSplinePath), path(VSplinePath()), visPath(nullptr) { ui->setupUi(this); - InitOkCancel(ui); + InitOkCancelApply(ui); bOk->setEnabled(false); FillComboBoxPoints(ui->comboBoxPoint); @@ -57,11 +58,14 @@ DialogSplinePath::DialogSplinePath(const VContainer *data, const quint32 &toolId this, &DialogSplinePath::KAsm1Changed); connect(ui->doubleSpinBoxKasm2, static_cast(&QDoubleSpinBox::valueChanged), this, &DialogSplinePath::KAsm2Changed); + + visPath = new VisToolSplinePath(data); } //--------------------------------------------------------------------------------------------------------------------- DialogSplinePath::~DialogSplinePath() { + delete visPath; delete ui; } @@ -73,6 +77,7 @@ DialogSplinePath::~DialogSplinePath() void DialogSplinePath::SetPath(const VSplinePath &value) { this->path = value; + ui->listWidget->blockSignals(true); ui->listWidget->clear(); for (qint32 i = 0; i < path.CountPoint(); ++i) { @@ -80,6 +85,9 @@ void DialogSplinePath::SetPath(const VSplinePath &value) } ui->listWidget->setFocus(Qt::OtherFocusReason); ui->doubleSpinBoxKcurve->setValue(path.getKCurve()); + + visPath->setPath(path); + ui->listWidget->blockSignals(false); } //--------------------------------------------------------------------------------------------------------------------- @@ -94,20 +102,29 @@ void DialogSplinePath::ChosenObject(quint32 id, const SceneObject &type) { NewItem(id, 1, 0, 1, 180); emit ToolTip(tr("Select point of curve path")); - this->show(); + + SavePath(); + visPath->setPath(path); + if (path.CountPoint() == 1) + { + visPath->VisualMode(NULL_ID); + connect(visPath, &VisToolSplinePath::ToolTip, this, &DialogTool::ShowVisToolTip); + connect(visPath, &VisToolSplinePath::PathChanged, this, &DialogSplinePath::PathUpdated); + } + else + { + visPath->RefreshGeometry(); + } } } //--------------------------------------------------------------------------------------------------------------------- void DialogSplinePath::SaveData() { - path.Clear(); - for (qint32 i = 0; i < ui->listWidget->count(); ++i) - { - QListWidgetItem *item = ui->listWidget->item(i); - path.append( qvariant_cast(item->data(Qt::UserRole))); - } - path.setKCurve(ui->doubleSpinBoxKcurve->value()); + SavePath(); + + visPath->setPath(path); + visPath->RefreshGeometry(); } //--------------------------------------------------------------------------------------------------------------------- @@ -214,6 +231,35 @@ void DialogSplinePath::UpdateList() */ } +//--------------------------------------------------------------------------------------------------------------------- +void DialogSplinePath::ShowDialog(bool click) +{ + if (click == false) + { + emit ToolTip(""); + DialogAccepted(); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogSplinePath::PathUpdated(const VSplinePath &path) +{ + SetPath(path); +} + +//--------------------------------------------------------------------------------------------------------------------- +void DialogSplinePath::ShowVisualization() +{ + if (prepare == false) + { + VMainGraphicsScene *scene = qApp->getCurrentScene(); + connect(scene, &VMainGraphicsScene::NewFactor, visPath, &Visualization::SetFactor); + scene->addItem(visPath); + visPath->setMode(Mode::Show); + visPath->RefreshGeometry(); + } +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief NewItem add point to list @@ -228,7 +274,7 @@ void DialogSplinePath::NewItem(quint32 id, qreal kAsm1, qreal angle1, qreal kAsm const QSharedPointer point = data->GeometricObject(id); QListWidgetItem *item = new QListWidgetItem(point->name()); item->setFont(QFont("Times", 12, QFont::Bold)); - VSplinePoint p(*point, kAsm1, angle1, kAsm2, angle2); + VSplinePoint p(*point.data(), kAsm1, angle1, kAsm2, angle2); DataPoint(point->id(), kAsm1, angle1, kAsm2, angle2); item->setData(Qt::UserRole, QVariant::fromValue(p)); ui->listWidget->addItem(item); @@ -295,3 +341,15 @@ void DialogSplinePath::EnableFields() return; } } + +//--------------------------------------------------------------------------------------------------------------------- +void DialogSplinePath::SavePath() +{ + path.Clear(); + for (qint32 i = 0; i < ui->listWidget->count(); ++i) + { + QListWidgetItem *item = ui->listWidget->item(i); + path.append( qvariant_cast(item->data(Qt::UserRole))); + } + path.setKCurve(ui->doubleSpinBoxKcurve->value()); +} diff --git a/src/app/dialogs/tools/dialogsplinepath.h b/src/app/dialogs/tools/dialogsplinepath.h index 52c5356f8..4316ddefd 100644 --- a/src/app/dialogs/tools/dialogsplinepath.h +++ b/src/app/dialogs/tools/dialogsplinepath.h @@ -37,6 +37,8 @@ namespace Ui class DialogSplinePath; } +class VisToolSplinePath; + /** * @brief The DialogSplinePath class dialog for ToolSplinePath. Help create spline path and edit option. */ @@ -58,7 +60,10 @@ public slots: void KAsm1Changed(qreal d); void KAsm2Changed(qreal d); virtual void UpdateList(); + virtual void ShowDialog(bool click); + void PathUpdated(const VSplinePath &path); protected: + virtual void ShowVisualization(); /** * @brief SaveData Put dialog data in local variables */ @@ -72,9 +77,12 @@ private: /** @brief path spline path */ VSplinePath path; + VisToolSplinePath *visPath; + void NewItem(quint32 id, qreal kAsm1, qreal angle1, qreal kAsm2, qreal angle2); void DataPoint(quint32 id, qreal kAsm1, qreal angle1, qreal kAsm2, qreal angle2); void EnableFields(); + void SavePath(); }; //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/dialogs/tools/dialogsplinepath.ui b/src/app/dialogs/tools/dialogsplinepath.ui index 22ce120d6..e620b6de0 100644 --- a/src/app/dialogs/tools/dialogsplinepath.ui +++ b/src/app/dialogs/tools/dialogsplinepath.ui @@ -191,7 +191,7 @@ Qt::Horizontal - QDialogButtonBox::Cancel|QDialogButtonBox::Ok + QDialogButtonBox::Apply|QDialogButtonBox::Cancel|QDialogButtonBox::Ok diff --git a/src/app/dialogs/tools/dialogtool.cpp b/src/app/dialogs/tools/dialogtool.cpp index 515ab0109..f3c2e443f 100644 --- a/src/app/dialogs/tools/dialogtool.cpp +++ b/src/app/dialogs/tools/dialogtool.cpp @@ -63,7 +63,8 @@ DialogTool::DialogTool(const VContainer *data, const quint32 &toolId, QWidget *p labelEditFormula(nullptr), radioButtonSizeGrowth(nullptr), radioButtonStandardTable(nullptr), radioButtonIncrements(nullptr), radioButtonLengthLine(nullptr), radioButtonLengthArc(nullptr), radioButtonLengthCurve(nullptr), radioButtonAngleLine(nullptr), lineStyles(VAbstractTool::Styles()), - okColor(QColor(76, 76, 76)), errorColor(Qt::red), associatedTool(nullptr), toolId(toolId), prepare(false) + okColor(QColor(76, 76, 76)), errorColor(Qt::red), associatedTool(nullptr), toolId(toolId), prepare(false), + pointName(QString()) { SCASSERT(data != nullptr); timerFormula = new QTimer(this); @@ -377,11 +378,13 @@ void DialogTool::ValFormulaChanged(bool &flag, QLineEdit *edit, QTimer *timer) SCASSERT(edit != nullptr); SCASSERT(timer != nullptr); SCASSERT(labelEditFormula != nullptr); + SCASSERT(labelResultCalculation != nullptr); if (edit->text().isEmpty()) { flag = false; CheckState(); ChangeColor(labelEditFormula, Qt::red); + labelResultCalculation->setText(tr("Error")); return; } timer->start(1000); @@ -392,11 +395,13 @@ void DialogTool::ValFormulaChanged(bool &flag, QPlainTextEdit *edit, QTimer *tim SCASSERT(edit != nullptr); SCASSERT(timer != nullptr); SCASSERT(labelEditFormula != nullptr); + SCASSERT(labelResultCalculation != nullptr); if (edit->toPlainText().isEmpty()) { flag = false; CheckState(); ChangeColor(labelEditFormula, Qt::red); + labelResultCalculation->setText(tr("Error")); return; } timer->setSingleShot(true); @@ -423,6 +428,8 @@ void DialogTool::Eval(const QString &text, bool &flag, QTimer *timer, QLabel *la { flag = false; ChangeColor(labelEditFormula, Qt::red); + label->setText(tr("Error")); + label->setToolTip(tr("Empty field")); } else { @@ -441,6 +448,8 @@ void DialogTool::Eval(const QString &text, bool &flag, QTimer *timer, QLabel *la { flag = false; ChangeColor(labelEditFormula, Qt::red); + label->setText(tr("Error")); + label->setToolTip(tr("Value can't be 0")); } else { @@ -456,6 +465,7 @@ void DialogTool::Eval(const QString &text, bool &flag, QTimer *timer, QLabel *la label->setText(loc.toString(result) + postfix); flag = true; ChangeColor(labelEditFormula, okColor); + label->setToolTip(tr("Value")); emit ToolTip(""); } } @@ -465,6 +475,7 @@ void DialogTool::Eval(const QString &text, bool &flag, QTimer *timer, QLabel *la flag = false; ChangeColor(labelEditFormula, Qt::red); emit ToolTip("Parser error: "+e.GetMsg()); + label->setToolTip("Parser error: "+e.GetMsg()); qDebug() << "\nMath parser error:\n" << "--------------------------------------\n" << "Message: " << e.GetMsg() << "\n" @@ -653,7 +664,8 @@ void DialogTool::NamePointChanged() if (edit) { QString name = edit->text(); - if (name.isEmpty() || name.contains(" ")) + name.replace(" ", ""); + if (name.isEmpty() || (pointName != name && data->IsUnique(name) == false)) { flagName = false; ChangeColor(labelEditNamePoint, Qt::red); diff --git a/src/app/dialogs/tools/dialogtool.h b/src/app/dialogs/tools/dialogtool.h index 5d2ab7950..659cc7069 100644 --- a/src/app/dialogs/tools/dialogtool.h +++ b/src/app/dialogs/tools/dialogtool.h @@ -200,6 +200,9 @@ protected: /** @brief prepare show if we prepare. Show dialog after finish working with visual part of tool*/ bool prepare; + /** @brief pointName name of point */ + QString pointName; + virtual void closeEvent ( QCloseEvent * event ); virtual void showEvent( QShowEvent *event ); void FillComboBoxPoints(QComboBox *box)const; diff --git a/src/app/dialogs/tools/dialogtriangle.cpp b/src/app/dialogs/tools/dialogtriangle.cpp index a4e4f0112..065b03093 100644 --- a/src/app/dialogs/tools/dialogtriangle.cpp +++ b/src/app/dialogs/tools/dialogtriangle.cpp @@ -32,6 +32,7 @@ #include "../../container/vcontainer.h" #include "../../visualization/vistooltriangle.h" #include "../../widgets/vmaingraphicsscene.h" +#include "../../xml/vpattern.h" //--------------------------------------------------------------------------------------------------------------------- /** @@ -40,14 +41,14 @@ * @param parent parent widget */ DialogTriangle::DialogTriangle(const VContainer *data, const quint32 &toolId, QWidget *parent) - :DialogTool(data, toolId, parent), ui(new Ui::DialogTriangle), number(0), pointName(QString()), axisP1Id(NULL_ID), + :DialogTool(data, toolId, parent), ui(new Ui::DialogTriangle), number(0), axisP1Id(NULL_ID), axisP2Id(NULL_ID), firstPointId(NULL_ID), secondPointId(NULL_ID), line (nullptr) { ui->setupUi(this); + ui->lineEditNamePoint->setText(qApp->getCurrentDocument()->GenerateLabel(LabelType::NewLabel)); labelEditNamePoint = ui->labelEditNamePoint; InitOkCancelApply(ui); - flagName = false; CheckState(); FillComboBoxPoints(ui->comboBoxAxisP1); diff --git a/src/app/dialogs/tools/dialogtriangle.h b/src/app/dialogs/tools/dialogtriangle.h index 5c0828e1e..51c2e52b7 100644 --- a/src/app/dialogs/tools/dialogtriangle.h +++ b/src/app/dialogs/tools/dialogtriangle.h @@ -80,9 +80,6 @@ private: /** @brief number number of handled objects */ qint32 number; - /** @brief pointName name of point */ - QString pointName; - /** @brief axisP1Id id first point of axis */ quint32 axisP1Id; diff --git a/src/app/dialogs/tools/dialogtriangle.ui b/src/app/dialogs/tools/dialogtriangle.ui index 4ac997de3..b743f48f3 100644 --- a/src/app/dialogs/tools/dialogtriangle.ui +++ b/src/app/dialogs/tools/dialogtriangle.ui @@ -31,43 +31,6 @@ 0 - - - - - - - 255 - 0 - 0 - - - - - - - - - 255 - 0 - 0 - - - - - - - - - 159 - 158 - 158 - - - - - - Point label diff --git a/src/app/geometry/varc.cpp b/src/app/geometry/varc.cpp index b2773455e..6d97b2c3d 100644 --- a/src/app/geometry/varc.cpp +++ b/src/app/geometry/varc.cpp @@ -37,6 +37,8 @@ # include // for M_PI on Windows #endif /*Q_OS_WIN32*/ +#include "../container/vformula.h" + //--------------------------------------------------------------------------------------------------------------------- /** @@ -247,6 +249,13 @@ QString VArc::GetFormulaF1() const return d->formulaF1; } +//--------------------------------------------------------------------------------------------------------------------- +void VArc::SetFormulaF1(const VFormula &value) +{ + d->formulaF1 = value.getFormula(FormulaType::FromUser); + d->f1 = value.getDoubleValue(); +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief GetF1 return formula for start angle. @@ -267,6 +276,13 @@ QString VArc::GetFormulaF2() const return d->formulaF2; } +//--------------------------------------------------------------------------------------------------------------------- +void VArc::SetFormulaF2(const VFormula &value) +{ + d->formulaF2 = value.getFormula(FormulaType::FromUser); + d->f2 = value.getDoubleValue(); +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief GetF2 return formula for end angle. @@ -287,6 +303,13 @@ QString VArc::GetFormulaRadius() const return d->formulaRadius; } +//--------------------------------------------------------------------------------------------------------------------- +void VArc::SetFormulaRadius(const VFormula &value) +{ + d->formulaRadius = value.getFormula(FormulaType::FromUser); + d->radius = value.getDoubleValue(); +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief GetRadius return formula for radius. @@ -306,3 +329,9 @@ VPointF VArc::GetCenter() const { return d->center; } + +//--------------------------------------------------------------------------------------------------------------------- +void VArc::SetCenter(const VPointF &value) +{ + d->center = value; +} diff --git a/src/app/geometry/varc.h b/src/app/geometry/varc.h index bd48b8568..53003724f 100644 --- a/src/app/geometry/varc.h +++ b/src/app/geometry/varc.h @@ -35,6 +35,7 @@ class QPainterPath; class VArcData; +class VFormula; /** * @brief VArc class for anticlockwise arc. @@ -52,13 +53,21 @@ public: virtual ~VArc(); QString GetFormulaF1 () const; + void SetFormulaF1 (const VFormula &value); qreal GetF1 () const; + QString GetFormulaF2 () const; + void SetFormulaF2 (const VFormula &value); qreal GetF2 () const; - qreal GetLength () const; + QString GetFormulaRadius () const; + void SetFormulaRadius (const VFormula &value); qreal GetRadius () const; + VPointF GetCenter () const; + void SetCenter (const VPointF &value); + + qreal GetLength () const; QPointF GetP1() const; QPointF GetP2 () const; qreal AngleArc() const; diff --git a/src/app/geometry/vspline.cpp b/src/app/geometry/vspline.cpp index 09f9bc161..ec695751a 100644 --- a/src/app/geometry/vspline.cpp +++ b/src/app/geometry/vspline.cpp @@ -241,6 +241,20 @@ QPointF VSpline::CutSpline ( qreal length, QPointF &spl1p2, QPointF &spl1p3, QPo return p1234; } +//--------------------------------------------------------------------------------------------------------------------- +QPointF VSpline::CutSpline(qreal length, VSpline &spl1, VSpline &spl2) const +{ + QPointF spl1p2; + QPointF spl1p3; + QPointF spl2p2; + QPointF spl2p3; + QPointF cutPoint = CutSpline (length, spl1p2, spl1p3, spl2p2, spl2p3 ); + + spl1 = VSpline(GetP1(), spl1p2, spl1p3, cutPoint, GetKcurve()); + spl2 = VSpline(cutPoint, spl2p2, spl2p3, GetP4(), GetKcurve()); + return cutPoint; +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief GetPoints return list with spline points. @@ -750,3 +764,12 @@ qreal VSpline::GetKcurve() const { return d->kCurve; } + +//--------------------------------------------------------------------------------------------------------------------- +void VSpline::SetKcurve(qreal factor) +{ + if (factor > 0) + { + d->kCurve = factor; + } +} diff --git a/src/app/geometry/vspline.h b/src/app/geometry/vspline.h index 48f724613..cf57a0fe1 100644 --- a/src/app/geometry/vspline.h +++ b/src/app/geometry/vspline.h @@ -63,10 +63,12 @@ public: qreal GetKasm1() const; qreal GetKasm2() const; qreal GetKcurve() const; + void SetKcurve(qreal factor); // cppcheck-suppress unusedFunction QLineF::IntersectType CrossingSplLine(const QLineF &line, QPointF *intersectionPoint ) const; qreal LengthT(qreal t) const; QPointF CutSpline ( qreal length, QPointF &spl1p2, QPointF &spl1p3, QPointF &spl2p2, QPointF &spl2p3) const; + QPointF CutSpline ( qreal length, VSpline &spl1, VSpline &spl2) const; QVector GetPoints () const; // cppcheck-suppress unusedFunction static QVector SplinePoints(const QPointF &p1, const QPointF &p4, qreal angle1, qreal angle2, qreal kAsm1, diff --git a/src/app/geometry/vspline_p.h b/src/app/geometry/vspline_p.h index d91951474..49863caaa 100644 --- a/src/app/geometry/vspline_p.h +++ b/src/app/geometry/vspline_p.h @@ -48,7 +48,7 @@ public: VSplineData ( const VSplineData &spline ) :QSharedData(spline), p1(spline.p1), p2(spline.p2), p3(spline.p3), p4(spline.p4), angle1(spline.angle1), - angle2(spline.angle2), kAsm1(spline.angle2), kAsm2(spline.kAsm1), kCurve(spline.kCurve) + angle2(spline.angle2), kAsm1(spline.kAsm1), kAsm2(spline.kAsm2), kCurve(spline.kCurve) {} VSplineData (VPointF p1, VPointF p4, qreal angle1, qreal angle2, qreal kAsm1, qreal kAsm2, qreal kCurve) diff --git a/src/app/geometry/vsplinepath.cpp b/src/app/geometry/vsplinepath.cpp index 98d99ffd1..4fa7736d9 100644 --- a/src/app/geometry/vsplinepath.cpp +++ b/src/app/geometry/vsplinepath.cpp @@ -258,7 +258,10 @@ qreal VSplinePath::getKCurve() const //--------------------------------------------------------------------------------------------------------------------- void VSplinePath::setKCurve(const qreal &value) { - d->kCurve = value; + if (value > 0) + { + d->kCurve = value; + } } //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/main.cpp b/src/app/main.cpp index ccb002022..0f628032c 100644 --- a/src/app/main.cpp +++ b/src/app/main.cpp @@ -80,21 +80,21 @@ inline void noisyFailureMsgHandler(QtMsgType type, const QMessageLogContext &con case QtWarningMsg: messageBox.setIcon(QMessageBox::Warning); messageBox.setInformativeText(msg); - messageBox.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel); + messageBox.setStandardButtons(QMessageBox::Ok); fprintf(stderr, "Warning: %s (%s:%u, %s)\n", localMsg.constData(), context.file, context.line, context.function); break; case QtCriticalMsg: messageBox.setIcon(QMessageBox::Critical); messageBox.setInformativeText(msg); - messageBox.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel); + messageBox.setStandardButtons(QMessageBox::Ok); fprintf(stderr, "Critical: %s (%s:%u, %s)\n", localMsg.constData(), context.file, context.line, context.function); break; case QtFatalMsg: messageBox.setIcon(QMessageBox::Critical); messageBox.setInformativeText(msg); - messageBox.setStandardButtons(QMessageBox::Cancel); + messageBox.setStandardButtons(QMessageBox::Ok); fprintf(stderr, "Fatal: %s (%s:%u, %s)\n", localMsg.constData(), context.file, context.line, context.function); break; diff --git a/src/app/mainwindow.cpp b/src/app/mainwindow.cpp index f547d6610..9ec7f6495 100644 --- a/src/app/mainwindow.cpp +++ b/src/app/mainwindow.cpp @@ -41,6 +41,7 @@ #include "widgets/vapplication.h" #include "widgets/undoevent.h" #include "undocommands/renamepp.h" +#include "vtooloptionspropertybrowser.h" #include #include @@ -60,7 +61,7 @@ * @param parent parent widget. */ MainWindow::MainWindow(QWidget *parent) - :QMainWindow(parent), ui(new Ui::MainWindow), pattern(nullptr), doc(nullptr), tool(Tool::ArrowTool), + :QMainWindow(parent), ui(new Ui::MainWindow), pattern(nullptr), doc(nullptr), tool(Tool::Arrow), currentScene(nullptr), sceneDraw(nullptr), sceneDetails(nullptr), mouseCoordinate(nullptr), helpLabel(nullptr), isInitialized(false), dialogTable(nullptr), dialogTool(nullptr), dialogHistory(nullptr), comboBoxDraws(nullptr), curFile(QString()), mode(Draw::Calculation), currentDrawIndex(0), @@ -104,6 +105,7 @@ MainWindow::MainWindow(QWidget *parent) connect(doc, &VPattern::UndoCommand, this, &MainWindow::FullParseFile); connect(doc, &VPattern::SetEnabledGUI, this, &MainWindow::SetEnabledGUI); connect(doc, &VPattern::CheckLayout, this, &MainWindow::Layout); + qApp->setCurrentDocument(doc); connect(qApp->getUndoStack(), &QUndoStack::cleanChanged, this, &MainWindow::PatternWasModified); @@ -112,6 +114,7 @@ MainWindow::MainWindow(QWidget *parent) ui->toolBox->setCurrentIndex(0); ReadSettings(); + PropertyBrowser(); setCurrentFile(""); } @@ -192,15 +195,18 @@ void MainWindow::ActionNewPP() pattern->ClearGObjects(); //Create single point - const quint32 id = pattern->AddGObject(new VPointF(20+comboBoxDraws->count()*5, 20, "А", 5, 10)); + ui->view->itemClicked(nullptr);//hide options previous tool + QString label = doc->GenerateLabel(LabelType::NewPatternPiece); + const quint32 id = pattern->AddGObject(new VPointF(30+comboBoxDraws->count()*5, 40, label, 5, 10)); VToolSinglePoint *spoint = new VToolSinglePoint(doc, pattern, id, Source::FromGui, patternPieceName, path); sceneDraw->addItem(spoint); + ui->view->itemClicked(spoint); connect(spoint, &VToolPoint::ChoosedTool, sceneDraw, &VMainGraphicsScene::ChoosedItem); connect(sceneDraw, &VMainGraphicsScene::NewFactor, spoint, &VToolSinglePoint::SetFactor); QHash* tools = doc->getTools(); SCASSERT(tools != nullptr); tools->insert(id, spoint); - VDrawTool::AddRecord(id, Tool::SinglePointTool, doc); + VDrawTool::AddRecord(id, Tool::SinglePoint, doc); SetEnableTool(true); SetEnableWidgets(true); @@ -253,6 +259,7 @@ void MainWindow::SetToolButton(bool checked, Tool t, const QString &cursor, cons QCursor cur(pixmap, 2, 3); ui->view->setCursor(cur); helpLabel->setText(toolTip); + ui->view->setShowToolOptions(false); dialogTool = new Dialog(pattern, 0, this); connect(currentScene, &VMainGraphicsScene::ChoosedObject, dialogTool, &DialogTool::ChosenObject); connect(dialogTool, &DialogTool::DialogClosed, this, closeDialogSlot); @@ -290,6 +297,7 @@ void MainWindow::SetToolButtonWithApply(bool checked, Tool t, const QString &cur QPixmap pixmap(cursor); QCursor cur(pixmap, 2, 3); ui->view->setCursor(cur); + ui->view->setShowToolOptions(false); helpLabel->setText(toolTip); dialogTool = new Dialog(pattern, 0, this); connect(currentScene, &VMainGraphicsScene::ChoosedObject, dialogTool, &DialogTool::ChosenObject); @@ -319,7 +327,8 @@ void MainWindow::ClosedDialog(int result) SCASSERT(dialogTool != nullptr); if (result == QDialog::Accepted) { - DrawTool::Create(dialogTool, currentScene, doc, pattern); + QGraphicsItem *tool = dynamic_cast(DrawTool::Create(dialogTool, currentScene, doc, pattern)); + ui->view->itemClicked(tool); } ArrowTool(); } @@ -347,9 +356,11 @@ void MainWindow::ClosedDialogWithApply(int result) vtool->FullUpdateFromGuiApply(); } } + QGraphicsItem *tool = dynamic_cast(dialogTool->GetAssociatedTool()); + ui->view->itemClicked(tool); if (dialogTool->GetAssociatedTool() != nullptr) { - VDrawTool * vtool= static_cast(dialogTool->GetAssociatedTool()); + VDrawTool *vtool= static_cast(dialogTool->GetAssociatedTool()); vtool->DialogLinkDestroy(); } ArrowTool(); @@ -385,7 +396,7 @@ void MainWindow::ApplyDialog() */ void MainWindow::ToolEndLine(bool checked) { - SetToolButtonWithApply(checked, Tool::EndLineTool, ":/cursor/endline_cursor.png", tr("Select point"), + SetToolButtonWithApply(checked, Tool::EndLine, ":/cursor/endline_cursor.png", tr("Select point"), &MainWindow::ClosedDialogWithApply, &MainWindow::ApplyDialog); } @@ -397,7 +408,7 @@ void MainWindow::ToolEndLine(bool checked) */ void MainWindow::ToolLine(bool checked) { - SetToolButtonWithApply(checked, Tool::LineTool, ":/cursor/line_cursor.png", tr("Select first point"), + SetToolButtonWithApply(checked, Tool::Line, ":/cursor/line_cursor.png", tr("Select first point"), &MainWindow::ClosedDialogWithApply, &MainWindow::ApplyDialog); } @@ -409,7 +420,7 @@ void MainWindow::ToolLine(bool checked) */ void MainWindow::ToolAlongLine(bool checked) { - SetToolButtonWithApply(checked, Tool::AlongLineTool, ":/cursor/alongline_cursor.png", + SetToolButtonWithApply(checked, Tool::AlongLine, ":/cursor/alongline_cursor.png", tr("Select point"), &MainWindow::ClosedDialogWithApply, &MainWindow::ApplyDialog); } @@ -421,7 +432,7 @@ void MainWindow::ToolAlongLine(bool checked) */ void MainWindow::ToolShoulderPoint(bool checked) { - SetToolButtonWithApply(checked, Tool::ShoulderPointTool, ":/cursor/shoulder_cursor.png", + SetToolButtonWithApply(checked, Tool::ShoulderPoint, ":/cursor/shoulder_cursor.png", tr("Select point of shoulder"), &MainWindow::ClosedDialogWithApply, &MainWindow::ApplyDialog); @@ -434,7 +445,7 @@ void MainWindow::ToolShoulderPoint(bool checked) */ void MainWindow::ToolNormal(bool checked) { - SetToolButtonWithApply(checked, Tool::NormalTool, ":/cursor/normal_cursor.png", + SetToolButtonWithApply(checked, Tool::Normal, ":/cursor/normal_cursor.png", tr("Select first point of line"), &MainWindow::ClosedDialogWithApply, &MainWindow::ApplyDialog); @@ -447,7 +458,7 @@ void MainWindow::ToolNormal(bool checked) */ void MainWindow::ToolBisector(bool checked) { - SetToolButtonWithApply(checked, Tool::BisectorTool, ":/cursor/bisector_cursor.png", + SetToolButtonWithApply(checked, Tool::Bisector, ":/cursor/bisector_cursor.png", tr("Select first point of angle"), &MainWindow::ClosedDialogWithApply, &MainWindow::ApplyDialog); @@ -460,7 +471,7 @@ void MainWindow::ToolBisector(bool checked) */ void MainWindow::ToolLineIntersect(bool checked) { - SetToolButtonWithApply(checked, Tool::LineIntersectTool, ":/cursor/intersect_cursor.png", + SetToolButtonWithApply(checked, Tool::LineIntersect, ":/cursor/intersect_cursor.png", tr("Select first point of first line"), &MainWindow::ClosedDialogWithApply, &MainWindow::ApplyDialog); @@ -473,7 +484,7 @@ void MainWindow::ToolLineIntersect(bool checked) */ void MainWindow::ToolSpline(bool checked) { - SetToolButtonWithApply(checked, Tool::SplineTool, ":/cursor/spline_cursor.png", + SetToolButtonWithApply(checked, Tool::Spline, ":/cursor/spline_cursor.png", tr("Select first point curve"), &MainWindow::ClosedDialogWithApply, &MainWindow::ApplyDialog); @@ -486,8 +497,10 @@ void MainWindow::ToolSpline(bool checked) */ void MainWindow::ToolCutSpline(bool checked) { - SetToolButton(checked, Tool::CutSplineTool, ":/cursor/spline_cut_point_cursor.png", - tr("Select simple curve"), &MainWindow::ClosedDialog); + SetToolButtonWithApply(checked, Tool::CutSpline, ":/cursor/spline_cut_point_cursor.png", + tr("Select simple curve"), + &MainWindow::ClosedDialogWithApply, + &MainWindow::ApplyDialog); } //--------------------------------------------------------------------------------------------------------------------- @@ -497,7 +510,7 @@ void MainWindow::ToolCutSpline(bool checked) */ void MainWindow::ToolArc(bool checked) { - SetToolButtonWithApply(checked, Tool::ArcTool, ":/cursor/arc_cursor.png", + SetToolButtonWithApply(checked, Tool::Arc, ":/cursor/arc_cursor.png", tr("Select point of center of arc"), &MainWindow::ClosedDialogWithApply, &MainWindow::ApplyDialog); } @@ -509,8 +522,10 @@ void MainWindow::ToolArc(bool checked) */ void MainWindow::ToolSplinePath(bool checked) { - SetToolButton(checked, Tool::SplinePathTool, ":/cursor/splinepath_cursor.png", - tr("Select point of curve path"), &MainWindow::ClosedDialog); + SetToolButtonWithApply(checked, Tool::SplinePath, ":/cursor/splinepath_cursor.png", + tr("Select point of curve path"), + &MainWindow::ClosedDialogWithApply, + &MainWindow::ApplyDialog); } //--------------------------------------------------------------------------------------------------------------------- @@ -520,9 +535,10 @@ void MainWindow::ToolSplinePath(bool checked) */ void MainWindow::ToolCutSplinePath(bool checked) { - SetToolButton(checked, Tool::CutSplinePathTool, - ":/cursor/splinepath_cut_point_cursor.png", tr("Select curve path"), - &MainWindow::ClosedDialog); + SetToolButtonWithApply(checked, Tool::CutSplinePath, + ":/cursor/splinepath_cut_point_cursor.png", tr("Select curve path"), + &MainWindow::ClosedDialogWithApply, + &MainWindow::ApplyDialog); } //--------------------------------------------------------------------------------------------------------------------- @@ -545,7 +561,7 @@ void MainWindow::ToolPointOfContact(bool checked) */ void MainWindow::ToolDetail(bool checked) { - SetToolButton(checked, Tool::DetailTool, "://cursor/new_detail_cursor.png", + SetToolButton(checked, Tool::Detail, "://cursor/new_detail_cursor.png", tr("Select points, arcs, curves clockwise."), &MainWindow::ClosedDialogDetail); } @@ -634,7 +650,7 @@ void MainWindow::ClosedDialogUnionDetails(int result) */ void MainWindow::ToolCutArc(bool checked) { - SetToolButtonWithApply(checked, Tool::CutArcTool, ":/cursor/arc_cut_cursor.png", + SetToolButtonWithApply(checked, Tool::CutArc, ":/cursor/arc_cut_cursor.png", tr("Select arc"), &MainWindow::ClosedDialogWithApply, &MainWindow::ApplyDialog); } @@ -942,60 +958,60 @@ void MainWindow::CancelTool() dialogTool = nullptr; switch ( tool ) { - case Tool::ArrowTool: + case Tool::Arrow: ui->actionArrowTool->setChecked(false); helpLabel->setText(""); break; - case Tool::SinglePointTool: + case Tool::SinglePoint: Q_UNREACHABLE(); //Nothing to do here because we can't create this tool from main window. break; - case Tool::EndLineTool: + case Tool::EndLine: ui->toolButtonEndLine->setChecked(false); currentScene->setFocus(Qt::OtherFocusReason); currentScene->clearSelection(); break; - case Tool::LineTool: + case Tool::Line: ui->toolButtonLine->setChecked(false); currentScene->setFocus(Qt::OtherFocusReason); currentScene->clearFocus(); break; - case Tool::AlongLineTool: + case Tool::AlongLine: ui->toolButtonAlongLine->setChecked(false); currentScene->setFocus(Qt::OtherFocusReason); currentScene->clearSelection(); break; - case Tool::ShoulderPointTool: + case Tool::ShoulderPoint: ui->toolButtonShoulderPoint->setChecked(false); currentScene->setFocus(Qt::OtherFocusReason); currentScene->clearSelection(); break; - case Tool::NormalTool: + case Tool::Normal: ui->toolButtonNormal->setChecked(false); currentScene->setFocus(Qt::OtherFocusReason); currentScene->clearSelection(); break; - case Tool::BisectorTool: + case Tool::Bisector: ui->toolButtonBisector->setChecked(false); currentScene->setFocus(Qt::OtherFocusReason); currentScene->clearSelection(); break; - case Tool::LineIntersectTool: + case Tool::LineIntersect: ui->toolButtonLineIntersect->setChecked(false); currentScene->setFocus(Qt::OtherFocusReason); currentScene->clearSelection(); break; - case Tool::SplineTool: + case Tool::Spline: ui->toolButtonSpline->setChecked(false); currentScene->setFocus(Qt::OtherFocusReason); currentScene->clearSelection(); break; - case Tool::ArcTool: + case Tool::Arc: ui->toolButtonArc->setChecked(false); currentScene->setFocus(Qt::OtherFocusReason); currentScene->clearSelection(); break; - case Tool::SplinePathTool: + case Tool::SplinePath: ui->toolButtonSplinePath->setChecked(false); currentScene->setFocus(Qt::OtherFocusReason); currentScene->clearSelection(); @@ -1005,7 +1021,7 @@ void MainWindow::CancelTool() currentScene->setFocus(Qt::OtherFocusReason); currentScene->clearSelection(); break; - case Tool::DetailTool: + case Tool::Detail: ui->toolButtonNewDetail->setChecked(false); break; case Tool::Height: @@ -1023,12 +1039,12 @@ void MainWindow::CancelTool() currentScene->setFocus(Qt::OtherFocusReason); currentScene->clearSelection(); break; - case Tool::CutSplineTool: + case Tool::CutSpline: ui->toolButtonSplineCutPoint->setChecked(false); currentScene->setFocus(Qt::OtherFocusReason); currentScene->clearSelection(); break; - case Tool::CutSplinePathTool: + case Tool::CutSplinePath: ui->toolButtonSplinePathCutPoint->setChecked(false); currentScene->setFocus(Qt::OtherFocusReason); currentScene->clearSelection(); @@ -1038,7 +1054,7 @@ void MainWindow::CancelTool() currentScene->setFocus(Qt::OtherFocusReason); currentScene->clearSelection(); break; - case Tool::CutArcTool: + case Tool::CutArc: ui->toolButtonArcCutPoint->setChecked(false); currentScene->setFocus(Qt::OtherFocusReason); currentScene->clearSelection(); @@ -1061,10 +1077,11 @@ void MainWindow::ArrowTool() { CancelTool(); ui->actionArrowTool->setChecked(true); - tool = Tool::ArrowTool; + tool = Tool::Arrow; QCursor cur(Qt::ArrowCursor); ui->view->setCursor(cur); helpLabel->setText(""); + ui->view->setShowToolOptions(true); } //--------------------------------------------------------------------------------------------------------------------- @@ -1959,6 +1976,27 @@ void MainWindow::CreateMenus() separatorAct = new QAction(this); separatorAct->setSeparator(true); ui->menuPatternPiece->insertAction(ui->actionPattern_properties, separatorAct); + AddDocks(); +} + +void MainWindow::AddDocks() +{ + ui->menuPatternPiece->insertAction(ui->actionPattern_properties, ui->dockWidgetHistory->toggleViewAction()); + ui->dockWidgetHistory->close();//Default don't show hostory + ui->menuPatternPiece->insertAction(ui->actionPattern_properties, ui->dockWidgetToolOptions->toggleViewAction()); + + separatorAct = new QAction(this); + separatorAct->setSeparator(true); + ui->menuPatternPiece->insertAction(ui->actionPattern_properties, separatorAct); +} + +//--------------------------------------------------------------------------------------------------------------------- +void MainWindow::PropertyBrowser() +{ + toolOptions = new VToolOptionsPropertyBrowser(ui->dockWidgetToolOptions); + + connect(ui->view, &VMainGraphicsView::itemClicked, toolOptions, &VToolOptionsPropertyBrowser::itemClicked); + connect(doc, &VPattern::FullUpdateFromFile, toolOptions, &VToolOptionsPropertyBrowser::UpdateOptions); } //--------------------------------------------------------------------------------------------------------------------- @@ -2213,6 +2251,7 @@ void MainWindow::ChangePP(int index, bool zoomBestFit) ui->view->NewFactor(ui->view->transform().m11()); } } + toolOptions->itemClicked(nullptr);//hide options for tool in previous pattern piece } } diff --git a/src/app/mainwindow.h b/src/app/mainwindow.h index b749251a9..4c860bd2b 100644 --- a/src/app/mainwindow.h +++ b/src/app/mainwindow.h @@ -44,6 +44,8 @@ namespace Ui class MainWindow; } +class VToolOptionsPropertyBrowser; + /** * @brief The MainWindow class main windows. */ @@ -194,6 +196,8 @@ private: bool guiEnabled; QComboBox *gradationHeights; QComboBox *gradationSizes; + VToolOptionsPropertyBrowser *toolOptions; + void ToolBarOption(); void ToolBarDraws(); void ToolBarTools(); @@ -243,6 +247,9 @@ private: void UpdateSizesList(const QStringList &list); void SetDefaultHeight(int value); void SetDefaultSize(int value); + + void AddDocks(); + void PropertyBrowser(); }; #endif // MAINWINDOW_H diff --git a/src/app/options.cpp b/src/app/options.cpp index 5e2f5139c..58b9da8da 100644 --- a/src/app/options.cpp +++ b/src/app/options.cpp @@ -29,6 +29,9 @@ #include "options.h" #include +//Same regexp in pattern.xsd shema file. Don't forget synchronize. +const QString nameRegExp = QStringLiteral("^([^0-9-*/^+=\\s\\(\\)%:;!.,]){1,1}([^-*/^+=\\s\\(\\)%:;!.,]){0,}$"); + // Keep synchronize all names with initialization in VApllication class. //measurements const QString headGirth_M = QStringLiteral("head_girth"); diff --git a/src/app/options.h b/src/app/options.h index 2baec9341..cf4c82516 100644 --- a/src/app/options.h +++ b/src/app/options.h @@ -37,30 +37,38 @@ class QString; +static const quint32 null_id = 0; + #define SceneSize 50000 #define DefPointRadius 2.0//mm -#define NULL_ID 0//use this value for initialization variables that keeps id values. 0 mean uknown id value. +#define NULL_ID null_id//use this value for initialization variables that keeps id values. 0 mean uknown id value. + +extern const QString nameRegExp; enum class SceneObject : char { Point, Line, Spline, Arc, SplinePath, Detail, Unknown }; -enum class Tool : char +enum class Tool : unsigned char { - ArrowTool, - SinglePointTool, - EndLineTool, - LineTool, - AlongLineTool, - ShoulderPointTool, - NormalTool, - BisectorTool, - LineIntersectTool, - SplineTool, - CutSplineTool, - CutArcTool, - ArcTool, - SplinePathTool, - CutSplinePathTool, + Arrow, + Point, + LinePoint, + AbstractSpline, + Cut, + SinglePoint, + EndLine, + Line, + AlongLine, + ShoulderPoint, + Normal, + Bisector, + LineIntersect, + Spline, + CutSpline, + CutArc, + Arc, + SplinePath, + CutSplinePath, PointOfContact, - DetailTool, + Detail, NodePoint, NodeArc, NodeSpline, @@ -71,6 +79,32 @@ enum class Tool : char UnionDetails }; +enum class Vis : unsigned char +{ + ControlPointSpline = 29, // increase this value if need more positions in Tool enum + GraphicsSimpleTextItem, + SimpleSplinePath, + Line, + Path, + ToolAlongLine, + ToolArc, + ToolBisector, + ToolCutArc, + ToolEndLine, + ToolHeight, + ToolLine, + ToolLineIntersect, + ToolNormal, + ToolPointOfContact, + ToolPointOfIntersection, + ToolShoulderPoint, + ToolSpline, + ToolTriangle, + ToolCutSpline, + ToolSplinePath, + ToolCutSplinePath +}; + enum class Source : char { FromGui, FromFile, FromTool }; enum class Draw : char { Calculation, Modeling }; enum class Unit : char { Mm, Cm, Inch }; diff --git a/src/app/tools/drawTools/vabstractspline.cpp b/src/app/tools/drawTools/vabstractspline.cpp index 78bbdfd57..305eb11d9 100644 --- a/src/app/tools/drawTools/vabstractspline.cpp +++ b/src/app/tools/drawTools/vabstractspline.cpp @@ -52,6 +52,12 @@ void VAbstractSpline::paint(QPainter *painter, const QStyleOptionGraphicsItem *o QGraphicsPathItem::paint(painter, &myOption, widget); } +//--------------------------------------------------------------------------------------------------------------------- +QString VAbstractSpline::getTagName() const +{ + return VAbstractSpline::TagName; +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief FullUpdateFromFile update tool data form file. @@ -211,3 +217,12 @@ QPainterPath VAbstractSpline::ToolPath(PathDirection direction) const path.setFillRule( Qt::WindingFill ); return path; } + +//--------------------------------------------------------------------------------------------------------------------- +void VAbstractSpline::ShowFoot(bool show) +{ + for (int i = 0; i < controlPoints.size(); ++i) + { + controlPoints.at(i)->setVisible(show); + } +} diff --git a/src/app/tools/drawTools/vabstractspline.h b/src/app/tools/drawTools/vabstractspline.h index 2dfe1fa88..96ac5d289 100644 --- a/src/app/tools/drawTools/vabstractspline.h +++ b/src/app/tools/drawTools/vabstractspline.h @@ -40,6 +40,10 @@ public: VAbstractSpline(VPattern *doc, VContainer *data, quint32 id, QGraphicsItem * parent = nullptr); static const QString TagName; virtual void paint(QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget = 0); + virtual int type() const {return Type;} + enum { Type = UserType + static_cast(Tool::AbstractSpline)}; + virtual QString getTagName() const; + void ShowFoot(bool show); public slots: virtual void FullUpdateFromFile (); void Disable(bool disable); diff --git a/src/app/tools/drawTools/vdrawtool.cpp b/src/app/tools/drawTools/vdrawtool.cpp index 2eda94d91..408b07b97 100644 --- a/src/app/tools/drawTools/vdrawtool.cpp +++ b/src/app/tools/drawTools/vdrawtool.cpp @@ -148,6 +148,36 @@ void VDrawTool::SaveDialogChange() } } +//--------------------------------------------------------------------------------------------------------------------- +/** + * @brief AddToFile add tag with informations about tool into file. + */ +void VDrawTool::AddToFile() +{ + QDomElement domElement = doc->createElement(getTagName()); + QSharedPointer obj = VAbstractTool::data.GetGObject(id); + SaveOptions(domElement, obj); + AddToCalculation(domElement); +} + +//--------------------------------------------------------------------------------------------------------------------- +/** + * @brief RefreshDataInFile refresh attributes in file. If attributes don't exist create them. + */ +void VDrawTool::RefreshDataInFile() +{ + QDomElement domElement = doc->elementById(QString().setNum(id)); + if (domElement.isElement()) + { + QSharedPointer obj = VAbstractTool::data.GetGObject(id); + SaveOptions(domElement, obj); + } + else + { + qDebug()<<"Can't find tool with id ="<< id << Q_FUNC_INFO; + } +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief DialogLinkDestroy removes dialog pointer @@ -209,6 +239,7 @@ qreal VDrawTool::CheckFormula(const quint32 &toolId, QString &formula, VContaine if (resultUndo == UndoButton::Fix) { DialogEditWrongFormula *dialog = new DialogEditWrongFormula(data, toolId, qApp->getMainWindow()); + dialog->setWindowTitle(tr("Edit wrong formula")); dialog->setFormula(formula); if (dialog->exec() == QDialog::Accepted) { diff --git a/src/app/tools/drawTools/vdrawtool.h b/src/app/tools/drawTools/vdrawtool.h index eeb750398..0254e5363 100644 --- a/src/app/tools/drawTools/vdrawtool.h +++ b/src/app/tools/drawTools/vdrawtool.h @@ -36,6 +36,7 @@ #include "../../dialogs/tools/dialogtool.h" #include "../../widgets/vmaingraphicsscene.h" #include "../../xml/vpattern.h" +#include "../../widgets/vmaingraphicsview.h" /** * @brief The VDrawTool abstract class for all draw tool. @@ -81,6 +82,8 @@ protected: /** @brief SaveDialog save options into file after change in dialog. */ virtual void SaveDialog(QDomElement &domElement)=0; void SaveDialogChange(); + virtual void AddToFile(); + virtual void RefreshDataInFile(); template /** @@ -118,6 +121,7 @@ protected: QAction *selectedAction = menu.exec(event->screenPos()); if (selectedAction == actionOption) { + qApp->getSceneView()->itemClicked(nullptr); dialog = new Dialog(getData(), id, qApp->getMainWindow()); dialog->setModal(true); @@ -134,6 +138,7 @@ protected: } if (selectedAction == actionRemove) { + qApp->getSceneView()->itemClicked(nullptr); DeleteTool(); } } diff --git a/src/app/tools/drawTools/vtoolalongline.cpp b/src/app/tools/drawTools/vtoolalongline.cpp index 1840e143e..cfb079e64 100644 --- a/src/app/tools/drawTools/vtoolalongline.cpp +++ b/src/app/tools/drawTools/vtoolalongline.cpp @@ -31,6 +31,7 @@ #include "../../dialogs/tools/dialogalongline.h" #include "../../geometry/vpointf.h" #include "exception/vexceptionobjecterror.h" +#include "../../visualization/vistoolalongline.h" const QString VToolAlongLine::ToolType = QStringLiteral("alongLine"); @@ -79,6 +80,16 @@ void VToolAlongLine::FullUpdateFromFile() secondPointId = domElement.attribute(AttrSecondPoint, "").toUInt(); } RefreshGeometry(); + + if (vis != nullptr) + { + VisToolAlongLine * visual = qobject_cast(vis); + visual->setPoint1Id(basePointId); + visual->setPoint2Id(secondPointId); + visual->setLength(formulaLength); + visual->setLineStyle(VAbstractTool::LineStyle(typeLine)); + visual->RefreshGeometry(); + } } //--------------------------------------------------------------------------------------------------------------------- @@ -113,49 +124,6 @@ void VToolAlongLine::ShowContextMenu(QGraphicsSceneContextMenuEvent *event) ContextMenu(this, event); } -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief AddToFile add tag with informations about tool into file. - */ -void VToolAlongLine::AddToFile() -{ - const QSharedPointer point = VAbstractTool::data.GeometricObject(id); - QDomElement domElement = doc->createElement(TagName); - - doc->SetAttribute(domElement, VDomDocument::AttrId, id); - doc->SetAttribute(domElement, AttrType, ToolType); - doc->SetAttribute(domElement, AttrName, point->name()); - doc->SetAttribute(domElement, AttrMx, qApp->fromPixel(point->mx())); - doc->SetAttribute(domElement, AttrMy, qApp->fromPixel(point->my())); - - doc->SetAttribute(domElement, AttrTypeLine, typeLine); - doc->SetAttribute(domElement, AttrLength, formulaLength); - doc->SetAttribute(domElement, AttrFirstPoint, basePointId); - doc->SetAttribute(domElement, AttrSecondPoint, secondPointId); - - AddToCalculation(domElement); -} - -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief RefreshDataInFile refresh attributes in file. If attributes don't exist create them. - */ -void VToolAlongLine::RefreshDataInFile() -{ - const QSharedPointer point = VAbstractTool::data.GeometricObject(id); - QDomElement domElement = doc->elementById(QString().setNum(id)); - if (domElement.isElement()) - { - doc->SetAttribute(domElement, AttrMx, qApp->fromPixel(point->mx())); - doc->SetAttribute(domElement, AttrMy, qApp->fromPixel(point->my())); - doc->SetAttribute(domElement, AttrName, point->name()); - doc->SetAttribute(domElement, AttrTypeLine, typeLine); - doc->SetAttribute(domElement, AttrLength, formulaLength); - doc->SetAttribute(domElement, AttrFirstPoint, basePointId); - doc->SetAttribute(domElement, AttrSecondPoint, secondPointId); - } -} - //--------------------------------------------------------------------------------------------------------------------- /** * @brief RemoveReferens decrement value of reference. @@ -182,6 +150,77 @@ void VToolAlongLine::SaveDialog(QDomElement &domElement) doc->SetAttribute(domElement, AttrSecondPoint, dialogTool->getSecondPointId()); } +//--------------------------------------------------------------------------------------------------------------------- +void VToolAlongLine::SaveOptions(QDomElement &tag, QSharedPointer &obj) +{ + QSharedPointer point = qSharedPointerDynamicCast(obj); + SCASSERT(point.isNull() == false); + + doc->SetAttribute(tag, VDomDocument::AttrId, id); + doc->SetAttribute(tag, AttrType, ToolType); + doc->SetAttribute(tag, AttrName, point->name()); + doc->SetAttribute(tag, AttrMx, qApp->fromPixel(point->mx())); + doc->SetAttribute(tag, AttrMy, qApp->fromPixel(point->my())); + + doc->SetAttribute(tag, AttrTypeLine, typeLine); + doc->SetAttribute(tag, AttrLength, formulaLength); + doc->SetAttribute(tag, AttrFirstPoint, basePointId); + doc->SetAttribute(tag, AttrSecondPoint, secondPointId); +} + +//--------------------------------------------------------------------------------------------------------------------- +quint32 VToolAlongLine::getSecondPointId() const +{ + return secondPointId; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolAlongLine::setSecondPointId(const quint32 &value) +{ + if (value != NULL_ID) + { + secondPointId = value; + + QSharedPointer obj = VAbstractTool::data.GetGObject(id); + SaveOption(obj); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolAlongLine::ShowVisualization(bool show) +{ + if (show) + { + if (vis == nullptr) + { + VisToolAlongLine *visual = new VisToolAlongLine(getData()); + VMainGraphicsScene *scene = qApp->getCurrentScene(); + connect(scene, &VMainGraphicsScene::NewFactor, visual, &Visualization::SetFactor); + scene->addItem(visual); + + visual->setPoint1Id(basePointId); + visual->setPoint2Id(secondPointId); + visual->setLength(formulaLength); + visual->setLineStyle(VAbstractTool::LineStyle(typeLine)); + visual->RefreshGeometry(); + vis = visual; + } + else + { + VisToolAlongLine * visual = qobject_cast(vis); + if (visual != nullptr) + { + visual->show(); + } + } + } + else + { + delete vis; + vis = nullptr; + } +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief setDialog set dialog when user want change tool option. @@ -272,7 +311,7 @@ VToolAlongLine* VToolAlongLine::Create(const quint32 _id, const QString &pointNa doc->UpdateToolData(id, data); } } - VDrawTool::AddRecord(id, Tool::AlongLineTool, doc); + VDrawTool::AddRecord(id, Tool::AlongLine, doc); if (parse == Document::FullParse) { VToolAlongLine *point = new VToolAlongLine(doc, data, id, formula, firstPointId, diff --git a/src/app/tools/drawTools/vtoolalongline.h b/src/app/tools/drawTools/vtoolalongline.h index 1b2218604..09b44ef31 100644 --- a/src/app/tools/drawTools/vtoolalongline.h +++ b/src/app/tools/drawTools/vtoolalongline.h @@ -49,16 +49,21 @@ public: const qreal &mx, const qreal &my, VMainGraphicsScene *scene, VPattern *doc, VContainer *data, const Document &parse, const Source &typeCreation); static const QString ToolType; + virtual int type() const {return Type;} + enum { Type = UserType + static_cast(Tool::AlongLine)}; + + quint32 getSecondPointId() const; + void setSecondPointId(const quint32 &value); + virtual void ShowVisualization(bool show); public slots: virtual void FullUpdateFromFile(); virtual void SetFactor(qreal factor); virtual void ShowContextMenu(QGraphicsSceneContextMenuEvent *event); protected: virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ); - virtual void AddToFile(); - virtual void RefreshDataInFile(); virtual void RemoveReferens(); virtual void SaveDialog(QDomElement &domElement); + virtual void SaveOptions(QDomElement &tag, QSharedPointer &obj); private: /** @brief secondPointId id second point of line. */ quint32 secondPointId; diff --git a/src/app/tools/drawTools/vtoolarc.cpp b/src/app/tools/drawTools/vtoolarc.cpp index 1bbd344fe..43e99971d 100644 --- a/src/app/tools/drawTools/vtoolarc.cpp +++ b/src/app/tools/drawTools/vtoolarc.cpp @@ -29,8 +29,11 @@ #include "vtoolarc.h" #include "../../container/calculator.h" #include "../../dialogs/tools/dialogarc.h" -#include #include "../../geometry/varc.h" +#include "../container/vformula.h" +#include "../../visualization/vistoolarc.h" + +#include const QString VToolArc::TagName = QStringLiteral("arc"); const QString VToolArc::ToolType = QStringLiteral("simple"); @@ -149,7 +152,7 @@ VToolArc* VToolArc::Create(const quint32 _id, const quint32 ¢er, QString &ra doc->UpdateToolData(id, data); } } - VDrawTool::AddRecord(id, Tool::ArcTool, doc); + VDrawTool::AddRecord(id, Tool::Arc, doc); if (parse == Document::FullParse) { VToolArc *toolArc = new VToolArc(doc, data, id, typeCreation); @@ -165,12 +168,144 @@ VToolArc* VToolArc::Create(const quint32 _id, const quint32 ¢er, QString &ra } //--------------------------------------------------------------------------------------------------------------------- -/** - * @brief FullUpdateFromFile update tool data form file. - */ -void VToolArc::FullUpdateFromFile() +QString VToolArc::getTagName() const { - RefreshGeometry(); + return VToolArc::TagName; +} + +//--------------------------------------------------------------------------------------------------------------------- +quint32 VToolArc::getCenter() const +{ + QSharedPointer arc = VAbstractTool::data.GeometricObject(id); + SCASSERT(arc.isNull() == false); + + return arc->GetCenter().id(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolArc::setCenter(const quint32 &value) +{ + if (value != NULL_ID) + { + QSharedPointer obj = VAbstractTool::data.GetGObject(id); + QSharedPointer arc = qSharedPointerDynamicCast(obj); + + QSharedPointer point = VAbstractTool::data.GeometricObject(value); + arc->SetCenter(*point.data()); + SaveOption(obj); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +VFormula VToolArc::getFormulaRadius() const +{ + QSharedPointer arc = VAbstractTool::data.GeometricObject(id); + SCASSERT(arc.isNull() == false); + + VFormula radius(arc->GetFormulaRadius(), getData()); + radius.setCheckZero(true); + radius.setToolId(id); + radius.setPostfix(VDomDocument::UnitsToStr(qApp->patternUnit())); + return radius; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolArc::setFormulaRadius(const VFormula &value) +{ + if (value.error() == false) + { + QSharedPointer obj = VAbstractTool::data.GetGObject(id); + QSharedPointer arc = qSharedPointerDynamicCast(obj); + arc->SetFormulaRadius(value); + SaveOption(obj); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +VFormula VToolArc::getFormulaF1() const +{ + QSharedPointer arc = VAbstractTool::data.GeometricObject(id); + SCASSERT(arc.isNull() == false); + + VFormula f1(arc->GetFormulaF1(), getData()); + f1.setCheckZero(false); + f1.setToolId(id); + f1.setPostfix(QStringLiteral("°")); + return f1; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolArc::setFormulaF1(const VFormula &value) +{ + if (value.error() == false) + { + QSharedPointer obj = VAbstractTool::data.GetGObject(id); + QSharedPointer arc = qSharedPointerDynamicCast(obj); + arc->SetFormulaF1(value); + SaveOption(obj); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +VFormula VToolArc::getFormulaF2() const +{ + QSharedPointer arc = VAbstractTool::data.GeometricObject(id); + SCASSERT(arc.isNull() == false); + + VFormula f2(arc->GetFormulaF2(), getData()); + f2.setCheckZero(false); + f2.setToolId(id); + f2.setPostfix(QStringLiteral("°")); + return f2; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolArc::setFormulaF2(const VFormula &value) +{ + if (value.error() == false) + { + QSharedPointer obj = VAbstractTool::data.GetGObject(id); + QSharedPointer arc = qSharedPointerDynamicCast(obj); + arc->SetFormulaF2(value); + SaveOption(obj); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolArc::ShowVisualization(bool show) +{ + if (show) + { + if (vis == nullptr) + { + VisToolArc * visual = new VisToolArc(getData()); + VMainGraphicsScene *scene = qApp->getCurrentScene(); + connect(scene, &VMainGraphicsScene::NewFactor, visual, &Visualization::SetFactor); + scene->addItem(visual); + + const QSharedPointer arc = VAbstractTool::data.GeometricObject(id); + + visual->setPoint1Id(arc->GetCenter().id()); + visual->setRadius(arc->GetFormulaRadius()); + visual->setF1(arc->GetFormulaF1()); + visual->setF2(arc->GetFormulaF2()); + visual->RefreshGeometry(); + vis = visual; + } + else + { + VisToolArc *visual = qobject_cast(vis); + if (visual != nullptr) + { + visual->show(); + } + } + } + else + { + delete vis; + vis = nullptr; + } } //--------------------------------------------------------------------------------------------------------------------- @@ -183,42 +318,6 @@ void VToolArc::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) ContextMenu(this, event); } -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief AddToFile add tag with informations about tool into file. - */ -void VToolArc::AddToFile() -{ - const QSharedPointer arc = VAbstractTool::data.GeometricObject(id); - QDomElement domElement = doc->createElement(TagName); - - doc->SetAttribute(domElement, VDomDocument::AttrId, id); - doc->SetAttribute(domElement, AttrType, ToolType); - doc->SetAttribute(domElement, AttrCenter, arc->GetCenter().id()); - doc->SetAttribute(domElement, AttrRadius, arc->GetFormulaRadius()); - doc->SetAttribute(domElement, AttrAngle1, arc->GetFormulaF1()); - doc->SetAttribute(domElement, AttrAngle2, arc->GetFormulaF2()); - - AddToCalculation(domElement); -} - -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief RefreshDataInFile refresh attributes in file. If attributes don't exist create them. - */ -void VToolArc::RefreshDataInFile() -{ - const QSharedPointer arc = VAbstractTool::data.GeometricObject(id); - QDomElement domElement = doc->elementById(QString().setNum(id)); - if (domElement.isElement()) - { - doc->SetAttribute(domElement, AttrCenter, arc->GetCenter().id()); - doc->SetAttribute(domElement, AttrRadius, arc->GetFormulaRadius()); - doc->SetAttribute(domElement, AttrAngle1, arc->GetFormulaF1()); - doc->SetAttribute(domElement, AttrAngle2, arc->GetFormulaF2()); - } -} - //--------------------------------------------------------------------------------------------------------------------- /** * @brief RemoveReferens decrement value of reference. @@ -244,6 +343,20 @@ void VToolArc::SaveDialog(QDomElement &domElement) doc->SetAttribute(domElement, AttrAngle2, dialogTool->GetF2()); } +//--------------------------------------------------------------------------------------------------------------------- +void VToolArc::SaveOptions(QDomElement &tag, QSharedPointer &obj) +{ + QSharedPointer arc = qSharedPointerDynamicCast(obj); + SCASSERT(arc.isNull() == false); + + doc->SetAttribute(tag, VDomDocument::AttrId, id); + doc->SetAttribute(tag, AttrType, ToolType); + doc->SetAttribute(tag, AttrCenter, arc->GetCenter().id()); + doc->SetAttribute(tag, AttrRadius, arc->GetFormulaRadius()); + doc->SetAttribute(tag, AttrAngle1, arc->GetFormulaF1()); + doc->SetAttribute(tag, AttrAngle2, arc->GetFormulaF2()); +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief RefreshGeometry refresh item on scene. @@ -252,4 +365,16 @@ void VToolArc::RefreshGeometry() { this->setPen(QPen(currentColor, qApp->toPixel(qApp->widthHairLine())/factor)); this->setPath(ToolPath()); + + if (vis != nullptr) + { + const QSharedPointer arc = VAbstractTool::data.GeometricObject(id); + VisToolArc *visual = qobject_cast(vis); + + visual->setPoint1Id(arc->GetCenter().id()); + visual->setRadius(arc->GetFormulaRadius()); + visual->setF1(arc->GetFormulaF1()); + visual->setF2(arc->GetFormulaF2()); + visual->RefreshGeometry(); + } } diff --git a/src/app/tools/drawTools/vtoolarc.h b/src/app/tools/drawTools/vtoolarc.h index 6e943e7d2..b8264694b 100644 --- a/src/app/tools/drawTools/vtoolarc.h +++ b/src/app/tools/drawTools/vtoolarc.h @@ -31,6 +31,8 @@ #include "vabstractspline.h" +class VFormula; + /** * @brief The VToolArc class tool for creation arc. */ @@ -46,14 +48,28 @@ public: const Source &typeCreation); static const QString TagName; static const QString ToolType; -public slots: - virtual void FullUpdateFromFile(); + virtual int type() const {return Type;} + enum { Type = UserType + static_cast(Tool::Arc)}; + virtual QString getTagName() const; + + quint32 getCenter() const; + void setCenter(const quint32 &value); + + VFormula getFormulaRadius() const; + void setFormulaRadius(const VFormula &value); + + VFormula getFormulaF1() const; + void setFormulaF1(const VFormula &value); + + VFormula getFormulaF2() const; + void setFormulaF2(const VFormula &value); + + virtual void ShowVisualization(bool show); protected: virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ); - virtual void AddToFile(); - virtual void RefreshDataInFile(); virtual void RemoveReferens(); virtual void SaveDialog(QDomElement &domElement); + virtual void SaveOptions(QDomElement &tag, QSharedPointer &obj); private: void RefreshGeometry(); }; diff --git a/src/app/tools/drawTools/vtoolbisector.cpp b/src/app/tools/drawTools/vtoolbisector.cpp index d6ff4d469..467d4ca8c 100644 --- a/src/app/tools/drawTools/vtoolbisector.cpp +++ b/src/app/tools/drawTools/vtoolbisector.cpp @@ -30,6 +30,7 @@ #include "../../container/calculator.h" #include "../../dialogs/tools/dialogbisector.h" #include "../../geometry/vpointf.h" +#include "../../visualization/vistoolbisector.h" const QString VToolBisector::ToolType = QStringLiteral("bisector"); @@ -196,7 +197,7 @@ VToolBisector* VToolBisector::Create(const quint32 _id, QString &formula, const doc->UpdateToolData(id, data); } } - VDrawTool::AddRecord(id, Tool::BisectorTool, doc); + VDrawTool::AddRecord(id, Tool::Bisector, doc); if (parse == Document::FullParse) { VToolBisector *point = new VToolBisector(doc, data, id, typeLine, formula, firstPointId, secondPointId, @@ -230,6 +231,17 @@ void VToolBisector::FullUpdateFromFile() thirdPointId = domElement.attribute(AttrThirdPoint, "").toUInt(); } RefreshGeometry(); + + if (vis != nullptr) + { + VisToolBisector *visual = qobject_cast(vis); + visual->setPoint1Id(firstPointId); + visual->setPoint2Id(basePointId); + visual->setPoint3Id(thirdPointId); + visual->setLength(formulaLength); + visual->setLineStyle(VAbstractTool::LineStyle(typeLine)); + visual->RefreshGeometry(); + } } //--------------------------------------------------------------------------------------------------------------------- @@ -263,51 +275,6 @@ void VToolBisector::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) ContextMenu(this, event); } -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief AddToFile add tag with informations about tool into file. - */ -void VToolBisector::AddToFile() -{ - const QSharedPointer point = VAbstractTool::data.GeometricObject(id); - QDomElement domElement = doc->createElement(TagName); - - doc->SetAttribute(domElement, VDomDocument::AttrId, id); - doc->SetAttribute(domElement, AttrType, ToolType); - doc->SetAttribute(domElement, AttrName, point->name()); - doc->SetAttribute(domElement, AttrMx, qApp->fromPixel(point->mx())); - doc->SetAttribute(domElement, AttrMy, qApp->fromPixel(point->my())); - - doc->SetAttribute(domElement, AttrTypeLine, typeLine); - doc->SetAttribute(domElement, AttrLength, formulaLength); - doc->SetAttribute(domElement, AttrFirstPoint, firstPointId); - doc->SetAttribute(domElement, AttrSecondPoint, basePointId); - doc->SetAttribute(domElement, AttrThirdPoint, thirdPointId); - - AddToCalculation(domElement); -} - -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief RefreshDataInFile refresh attributes in file. If attributes don't exist create them. - */ -void VToolBisector::RefreshDataInFile() -{ - const QSharedPointer point = VAbstractTool::data.GeometricObject(id); - QDomElement domElement = doc->elementById(QString().setNum(id)); - if (domElement.isElement()) - { - doc->SetAttribute(domElement, AttrMx, qApp->fromPixel(point->mx())); - doc->SetAttribute(domElement, AttrMy, qApp->fromPixel(point->my())); - doc->SetAttribute(domElement, AttrName, point->name()); - doc->SetAttribute(domElement, AttrTypeLine, typeLine); - doc->SetAttribute(domElement, AttrLength, formulaLength); - doc->SetAttribute(domElement, AttrFirstPoint, firstPointId); - doc->SetAttribute(domElement, AttrSecondPoint, basePointId); - doc->SetAttribute(domElement, AttrThirdPoint, thirdPointId); - } -} - //--------------------------------------------------------------------------------------------------------------------- /** * @brief RemoveReferens decrement value of reference. @@ -335,3 +302,95 @@ void VToolBisector::SaveDialog(QDomElement &domElement) doc->SetAttribute(domElement, AttrSecondPoint, QString().setNum(dialogTool->getSecondPointId())); doc->SetAttribute(domElement, AttrThirdPoint, QString().setNum(dialogTool->getThirdPointId())); } + +//--------------------------------------------------------------------------------------------------------------------- +void VToolBisector::SaveOptions(QDomElement &tag, QSharedPointer &obj) +{ + QSharedPointer point = qSharedPointerDynamicCast(obj); + SCASSERT(point.isNull() == false); + + doc->SetAttribute(tag, VDomDocument::AttrId, id); + doc->SetAttribute(tag, AttrType, ToolType); + doc->SetAttribute(tag, AttrName, point->name()); + doc->SetAttribute(tag, AttrMx, qApp->fromPixel(point->mx())); + doc->SetAttribute(tag, AttrMy, qApp->fromPixel(point->my())); + + doc->SetAttribute(tag, AttrTypeLine, typeLine); + doc->SetAttribute(tag, AttrLength, formulaLength); + doc->SetAttribute(tag, AttrFirstPoint, firstPointId); + doc->SetAttribute(tag, AttrSecondPoint, basePointId); + doc->SetAttribute(tag, AttrThirdPoint, thirdPointId); +} + +//--------------------------------------------------------------------------------------------------------------------- +quint32 VToolBisector::getThirdPointId() const +{ + return thirdPointId; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolBisector::setThirdPointId(const quint32 &value) +{ + if (value != NULL_ID) + { + thirdPointId = value; + + QSharedPointer obj = VAbstractTool::data.GetGObject(id); + SaveOption(obj); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolBisector::ShowVisualization(bool show) +{ + if (show) + { + if (vis == nullptr) + { + VisToolBisector * visual = new VisToolBisector(getData()); + VMainGraphicsScene *scene = qApp->getCurrentScene(); + connect(scene, &VMainGraphicsScene::NewFactor, visual, &Visualization::SetFactor); + scene->addItem(visual); + + visual->setPoint1Id(firstPointId); + visual->setPoint2Id(basePointId); + visual->setPoint3Id(thirdPointId); + visual->setLength(formulaLength); + visual->setLineStyle(VAbstractTool::LineStyle(typeLine)); + visual->RefreshGeometry(); + vis = visual; + } + else + { + VisToolBisector *visual = qobject_cast(vis); + if (visual != nullptr) + { + visual->show(); + } + } + } + else + { + delete vis; + vis = nullptr; + } +} + +//--------------------------------------------------------------------------------------------------------------------- +quint32 VToolBisector::getFirstPointId() const +{ + return firstPointId; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolBisector::setFirstPointId(const quint32 &value) +{ + if (value != NULL_ID) + { + firstPointId = value; + + QSharedPointer obj = VAbstractTool::data.GetGObject(id); + SaveOption(obj); + } +} + diff --git a/src/app/tools/drawTools/vtoolbisector.h b/src/app/tools/drawTools/vtoolbisector.h index 1b6bf211a..42ac58091 100644 --- a/src/app/tools/drawTools/vtoolbisector.h +++ b/src/app/tools/drawTools/vtoolbisector.h @@ -53,16 +53,25 @@ public: VPattern *doc, VContainer *data, const Document &parse, const Source &typeCreation); static const QString ToolType; + virtual int type() const {return Type;} + enum { Type = UserType + static_cast(Tool::Bisector)}; + + quint32 getFirstPointId() const; + void setFirstPointId(const quint32 &value); + + quint32 getThirdPointId() const; + void setThirdPointId(const quint32 &value); + + virtual void ShowVisualization(bool show); public slots: virtual void FullUpdateFromFile(); virtual void SetFactor(qreal factor); virtual void ShowContextMenu(QGraphicsSceneContextMenuEvent *event); protected: virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ); - virtual void AddToFile(); - virtual void RefreshDataInFile(); virtual void RemoveReferens(); virtual void SaveDialog(QDomElement &domElement); + virtual void SaveOptions(QDomElement &tag, QSharedPointer &obj); private: /** @brief firstPointId id first point of angle. */ quint32 firstPointId; diff --git a/src/app/tools/drawTools/vtoolcut.cpp b/src/app/tools/drawTools/vtoolcut.cpp index 4593f5112..984cf2729 100644 --- a/src/app/tools/drawTools/vtoolcut.cpp +++ b/src/app/tools/drawTools/vtoolcut.cpp @@ -28,6 +28,7 @@ #include "vtoolcut.h" #include "../../geometry/vpointf.h" +#include "../../container/vformula.h" //--------------------------------------------------------------------------------------------------------------------- VToolCut::VToolCut(VPattern *doc, VContainer *data, const quint32 &id, const QString &formula, @@ -84,6 +85,45 @@ void VToolCut::HoverPath(quint32 id, SimpleCurvePoint curvePosition, PathDirecti } } +//--------------------------------------------------------------------------------------------------------------------- +quint32 VToolCut::getCurveCutId() const +{ + return curveCutId; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolCut::setCurveCutId(const quint32 &value) +{ + if (value != NULL_ID) + { + curveCutId = value; + QSharedPointer obj = VAbstractTool::data.GetGObject(id); + SaveOption(obj); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +VFormula VToolCut::getFormula() const +{ + VFormula val(formula, getData()); + val.setCheckZero(true); + val.setToolId(id); + val.setPostfix(VDomDocument::UnitsToStr(qApp->patternUnit())); + return val; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolCut::setFormula(const VFormula &value) +{ + if (value.error() == false) + { + formula = value.getFormula(FormulaType::FromUser); + + QSharedPointer obj = VAbstractTool::data.GetGObject(id); + SaveOption(obj); + } +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief RefreshGeometry refresh item on scene. diff --git a/src/app/tools/drawTools/vtoolcut.h b/src/app/tools/drawTools/vtoolcut.h index d4bd20487..f99e82847 100644 --- a/src/app/tools/drawTools/vtoolcut.h +++ b/src/app/tools/drawTools/vtoolcut.h @@ -32,12 +32,23 @@ #include "vtoolpoint.h" #include "../../visualization/vsimplecurve.h" +class VFormula; + class VToolCut : public VToolPoint { Q_OBJECT public: VToolCut(VPattern *doc, VContainer *data, const quint32 &id, const QString &formula, const quint32 &curveCutId, const quint32 &curve1id, const quint32 &curve2id, QGraphicsItem * parent = nullptr); + virtual int type() const {return Type;} + enum { Type = UserType + static_cast(Tool::Cut)}; + + VFormula getFormula() const; + void setFormula(const VFormula &value); + + quint32 getCurveCutId() const; + void setCurveCutId(const quint32 &value); + public slots: virtual void ChangedActivDraw(const QString &newName); virtual void CurveChoosed(quint32 id)=0; diff --git a/src/app/tools/drawTools/vtoolcutarc.cpp b/src/app/tools/drawTools/vtoolcutarc.cpp index b89cdcdad..f7cad6a1f 100644 --- a/src/app/tools/drawTools/vtoolcutarc.cpp +++ b/src/app/tools/drawTools/vtoolcutarc.cpp @@ -31,6 +31,7 @@ #include "../../dialogs/tools/dialogcutarc.h" #include "../../geometry/vpointf.h" #include "../../geometry/varc.h" +#include "../../visualization/vistoolcutarc.h" const QString VToolCutArc::ToolType = QStringLiteral("cutArc"); const QString VToolCutArc::AttrArc = QStringLiteral("arc"); @@ -163,7 +164,7 @@ VToolCutArc* VToolCutArc::Create(const quint32 _id, const QString &pointName, QS } } - VDrawTool::AddRecord(id, Tool::CutArcTool, doc); + VDrawTool::AddRecord(id, Tool::CutArc, doc); if (parse == Document::FullParse) { VToolCutArc *point = new VToolCutArc(doc, data, id, formula, arcId, arc1id, arc2id, typeCreation); @@ -180,6 +181,39 @@ VToolCutArc* VToolCutArc::Create(const quint32 _id, const QString &pointName, QS return nullptr; } +//--------------------------------------------------------------------------------------------------------------------- +void VToolCutArc::ShowVisualization(bool show) +{ + if (show) + { + if (vis == nullptr) + { + VisToolCutArc * visual = new VisToolCutArc(getData()); + VMainGraphicsScene *scene = qApp->getCurrentScene(); + connect(scene, &VMainGraphicsScene::NewFactor, visual, &Visualization::SetFactor); + scene->addItem(visual); + + visual->setPoint1Id(curveCutId); + visual->setLength(formula); + visual->RefreshGeometry(); + vis = visual; + } + else + { + VisToolCutArc *visual = qobject_cast(vis); + if (visual != nullptr) + { + visual->show(); + } + } + } + else + { + delete vis; + vis = nullptr; + } +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief FullUpdateFromFile update tool data form file. @@ -187,6 +221,14 @@ VToolCutArc* VToolCutArc::Create(const quint32 _id, const QString &pointName, QS void VToolCutArc::FullUpdateFromFile() { FullUpdateCurveFromFile(AttrArc); + + if (vis != nullptr) + { + VisToolCutArc *visual = qobject_cast(vis); + visual->setPoint1Id(curveCutId); + visual->setLength(formula); + visual->RefreshGeometry(); + } } //--------------------------------------------------------------------------------------------------------------------- @@ -219,45 +261,6 @@ void VToolCutArc::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) ContextMenu(this, event); } -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief AddToFile add tag with informations about tool into file. - */ -void VToolCutArc::AddToFile() -{ - const QSharedPointer point = VAbstractTool::data.GeometricObject(id); - QDomElement domElement = doc->createElement(TagName); - - doc->SetAttribute(domElement, VDomDocument::AttrId, id); - doc->SetAttribute(domElement, AttrType, ToolType); - doc->SetAttribute(domElement, AttrName, point->name()); - doc->SetAttribute(domElement, AttrMx, qApp->fromPixel(point->mx())); - doc->SetAttribute(domElement, AttrMy, qApp->fromPixel(point->my())); - - doc->SetAttribute(domElement, AttrLength, formula); - doc->SetAttribute(domElement, AttrArc, curveCutId); - - AddToCalculation(domElement); -} - -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief RefreshDataInFile refresh attributes in file. If attributes don't exist create them. - */ -void VToolCutArc::RefreshDataInFile() -{ - const QSharedPointer point = VAbstractTool::data.GeometricObject(id); - QDomElement domElement = doc->elementById(QString().setNum(id)); - if (domElement.isElement()) - { - doc->SetAttribute(domElement, AttrName, point->name()); - doc->SetAttribute(domElement, AttrMx, qApp->fromPixel(point->mx())); - doc->SetAttribute(domElement, AttrMy, qApp->fromPixel(point->my())); - doc->SetAttribute(domElement, AttrLength, formula); - doc->SetAttribute(domElement, AttrArc, curveCutId); - } -} - //--------------------------------------------------------------------------------------------------------------------- /** * @brief SaveDialog save options into file after change in dialog. @@ -296,3 +299,19 @@ void VToolCutArc::RefreshCurve(VSimpleCurve *curve, quint32 curveId, SimpleCurve } curve->setPath(path); } + +//--------------------------------------------------------------------------------------------------------------------- +void VToolCutArc::SaveOptions(QDomElement &tag, QSharedPointer &obj) +{ + QSharedPointer point = qSharedPointerDynamicCast(obj); + SCASSERT(point.isNull() == false); + + doc->SetAttribute(tag, VDomDocument::AttrId, id); + doc->SetAttribute(tag, AttrType, ToolType); + doc->SetAttribute(tag, AttrName, point->name()); + doc->SetAttribute(tag, AttrMx, qApp->fromPixel(point->mx())); + doc->SetAttribute(tag, AttrMy, qApp->fromPixel(point->my())); + + doc->SetAttribute(tag, AttrLength, formula); + doc->SetAttribute(tag, AttrArc, curveCutId); +} diff --git a/src/app/tools/drawTools/vtoolcutarc.h b/src/app/tools/drawTools/vtoolcutarc.h index a7a762bef..2e852cdca 100644 --- a/src/app/tools/drawTools/vtoolcutarc.h +++ b/src/app/tools/drawTools/vtoolcutarc.h @@ -48,17 +48,19 @@ public: VContainer *data, const Document &parse, const Source &typeCreation); static const QString ToolType; static const QString AttrArc; + virtual int type() const {return Type;} + enum { Type = UserType + static_cast(Tool::CutArc)}; + virtual void ShowVisualization(bool show); public slots: virtual void FullUpdateFromFile(); virtual void CurveChoosed(quint32 id); virtual void ShowContextMenu(QGraphicsSceneContextMenuEvent *event); protected: virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ); - virtual void AddToFile(); - virtual void RefreshDataInFile(); virtual void SaveDialog(QDomElement &domElement); virtual void RefreshCurve(VSimpleCurve *curve, quint32 curveId, SimpleCurvePoint curvePosition, PathDirection direction = PathDirection::Hide); + virtual void SaveOptions(QDomElement &tag, QSharedPointer &obj); private: Q_DISABLE_COPY(VToolCutArc) }; diff --git a/src/app/tools/drawTools/vtoolcutspline.cpp b/src/app/tools/drawTools/vtoolcutspline.cpp index 7ab7352e5..1af6dbb10 100644 --- a/src/app/tools/drawTools/vtoolcutspline.cpp +++ b/src/app/tools/drawTools/vtoolcutspline.cpp @@ -30,6 +30,8 @@ #include "../../container/calculator.h" #include "../../dialogs/tools/dialogcutspline.h" #include "../../geometry/vpointf.h" +#include "../../visualization/vistoolcutspline.h" +#include "vabstractspline.h" #include @@ -88,7 +90,7 @@ void VToolCutSpline::setDialog() * @param doc dom document container. * @param data container with variables. */ -void VToolCutSpline::Create(DialogTool *dialog, VMainGraphicsScene *scene, +VToolCutSpline* VToolCutSpline::Create(DialogTool *dialog, VMainGraphicsScene *scene, VPattern *doc, VContainer *data) { SCASSERT(dialog != nullptr); @@ -97,7 +99,13 @@ void VToolCutSpline::Create(DialogTool *dialog, VMainGraphicsScene *scene, const QString pointName = dialogTool->getPointName(); QString formula = dialogTool->getFormula(); const quint32 splineId = dialogTool->getSplineId(); - Create(0, pointName, formula, splineId, 5, 10, scene, doc, data, Document::FullParse, Source::FromGui); + VToolCutSpline* point = nullptr; + point = Create(0, pointName, formula, splineId, 5, 10, scene, doc, data, Document::FullParse, Source::FromGui); + if (point != nullptr) + { + point->dialog=dialogTool; + } + return point; } //--------------------------------------------------------------------------------------------------------------------- @@ -115,9 +123,10 @@ void VToolCutSpline::Create(DialogTool *dialog, VMainGraphicsScene *scene, * @param parse parser file mode. * @param typeCreation way we create this tool. */ -void VToolCutSpline::Create(const quint32 _id, const QString &pointName, QString &formula, const quint32 &splineId, - const qreal &mx, const qreal &my, VMainGraphicsScene *scene, VPattern *doc, - VContainer *data, const Document &parse, const Source &typeCreation) +VToolCutSpline* VToolCutSpline::Create(const quint32 _id, const QString &pointName, QString &formula, + const quint32 &splineId, const qreal &mx, const qreal &my, + VMainGraphicsScene *scene, VPattern *doc, VContainer *data, + const Document &parse, const Source &typeCreation) { const QSharedPointer spl = data->GeometricObject(splineId); @@ -163,7 +172,7 @@ void VToolCutSpline::Create(const quint32 _id, const QString &pointName, QString doc->UpdateToolData(id, data); } } - VDrawTool::AddRecord(id, Tool::CutSplineTool, doc); + VDrawTool::AddRecord(id, Tool::CutSpline, doc); if (parse == Document::FullParse) { VToolCutSpline *point = new VToolCutSpline(doc, data, id, formula, splineId, spl1id, spl2id, typeCreation); @@ -175,6 +184,45 @@ void VToolCutSpline::Create(const quint32 _id, const QString &pointName, QString doc->AddTool(spl1id, point); doc->AddTool(spl2id, point); doc->IncrementReferens(splineId); + return point; + } + return nullptr; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolCutSpline::ShowVisualization(bool show) +{ + if (show) + { + if (vis == nullptr) + { + VisToolCutSpline * visual = new VisToolCutSpline(getData()); + VMainGraphicsScene *scene = qApp->getCurrentScene(); + connect(scene, &VMainGraphicsScene::NewFactor, visual, &Visualization::SetFactor); + scene->addItem(visual); + + visual->setPoint1Id(curveCutId); + visual->setLength(formula); + visual->RefreshGeometry(); + vis = visual; + } + else + { + VisToolCutSpline * visual = qobject_cast(vis); + if (visual != nullptr) + { + visual->show(); + } + } + } + else + { + delete vis; + vis = nullptr; + } + if (VAbstractSpline *parentCurve = qobject_cast(doc->getTool(curveCutId))) + { + parentCurve->ShowFoot(show); } } @@ -185,6 +233,14 @@ void VToolCutSpline::Create(const quint32 _id, const QString &pointName, QString void VToolCutSpline::FullUpdateFromFile() { FullUpdateCurveFromFile(AttrSpline); + + if (vis != nullptr) + { + VisToolCutSpline *visual = qobject_cast(vis); + visual->setPoint1Id(curveCutId); + visual->setLength(formula); + visual->RefreshGeometry(); + } } //--------------------------------------------------------------------------------------------------------------------- @@ -217,45 +273,6 @@ void VToolCutSpline::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) ContextMenu(this, event); } -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief AddToFile add tag with informations about tool into file. - */ -void VToolCutSpline::AddToFile() -{ - const QSharedPointer point = VAbstractTool::data.GeometricObject(id); - QDomElement domElement = doc->createElement(TagName); - - doc->SetAttribute(domElement, VDomDocument::AttrId, id); - doc->SetAttribute(domElement, AttrType, ToolType); - doc->SetAttribute(domElement, AttrName, point->name()); - doc->SetAttribute(domElement, AttrMx, qApp->fromPixel(point->mx())); - doc->SetAttribute(domElement, AttrMy, qApp->fromPixel(point->my())); - - doc->SetAttribute(domElement, AttrLength, formula); - doc->SetAttribute(domElement, AttrSpline, curveCutId); - - AddToCalculation(domElement); -} - -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief RefreshDataInFile refresh attributes in file. If attributes don't exist create them. - */ -void VToolCutSpline::RefreshDataInFile() -{ - const QSharedPointer point = VAbstractTool::data.GeometricObject(id); - QDomElement domElement = doc->elementById(QString().setNum(id)); - if (domElement.isElement()) - { - doc->SetAttribute(domElement, AttrName, point->name()); - doc->SetAttribute(domElement, AttrMx, qApp->fromPixel(point->mx())); - doc->SetAttribute(domElement, AttrMy, qApp->fromPixel(point->my())); - doc->SetAttribute(domElement, AttrLength, formula); - doc->SetAttribute(domElement, AttrSpline, curveCutId); - } -} - //--------------------------------------------------------------------------------------------------------------------- /** * @brief SaveDialog save options into file after change in dialog. @@ -294,3 +311,19 @@ void VToolCutSpline::RefreshCurve(VSimpleCurve *curve, quint32 curveId, SimpleCu } curve->setPath(path); } + +//--------------------------------------------------------------------------------------------------------------------- +void VToolCutSpline::SaveOptions(QDomElement &tag, QSharedPointer &obj) +{ + QSharedPointer point = qSharedPointerDynamicCast(obj); + SCASSERT(point.isNull() == false); + + doc->SetAttribute(tag, VDomDocument::AttrId, id); + doc->SetAttribute(tag, AttrType, ToolType); + doc->SetAttribute(tag, AttrName, point->name()); + doc->SetAttribute(tag, AttrMx, qApp->fromPixel(point->mx())); + doc->SetAttribute(tag, AttrMy, qApp->fromPixel(point->my())); + + doc->SetAttribute(tag, AttrLength, formula); + doc->SetAttribute(tag, AttrSpline, curveCutId); +} diff --git a/src/app/tools/drawTools/vtoolcutspline.h b/src/app/tools/drawTools/vtoolcutspline.h index 318851ab4..d1b184edc 100644 --- a/src/app/tools/drawTools/vtoolcutspline.h +++ b/src/app/tools/drawTools/vtoolcutspline.h @@ -43,23 +43,25 @@ public: const quint32 &splineId, const quint32 &spl1id, const quint32 &spl2id, const Source &typeCreation, QGraphicsItem * parent = nullptr); virtual void setDialog(); - static void Create(DialogTool *dialog, VMainGraphicsScene *scene, VPattern *doc, VContainer *data); - static void Create(const quint32 _id, const QString &pointName, QString &formula, const quint32 &splineId, - const qreal &mx, const qreal &my, VMainGraphicsScene *scene, VPattern *doc, VContainer *data, - const Document &parse, const Source &typeCreation); + static VToolCutSpline *Create(DialogTool *dialog, VMainGraphicsScene *scene, VPattern *doc, VContainer *data); + static VToolCutSpline *Create(const quint32 _id, const QString &pointName, QString &formula, + const quint32 &splineId, const qreal &mx, const qreal &my, VMainGraphicsScene *scene, + VPattern *doc, VContainer *data, const Document &parse, const Source &typeCreation); static const QString ToolType; static const QString AttrSpline; + virtual int type() const {return Type;} + enum { Type = UserType + static_cast(Tool::CutSpline)}; + virtual void ShowVisualization(bool show); public slots: virtual void FullUpdateFromFile(); virtual void CurveChoosed(quint32 id); virtual void ShowContextMenu(QGraphicsSceneContextMenuEvent *event); protected: virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ); - virtual void AddToFile(); - virtual void RefreshDataInFile(); virtual void SaveDialog(QDomElement &domElement); virtual void RefreshCurve(VSimpleCurve *curve, quint32 curveId, SimpleCurvePoint curvePosition, PathDirection direction = PathDirection::Hide); + virtual void SaveOptions(QDomElement &tag, QSharedPointer &obj); private: Q_DISABLE_COPY(VToolCutSpline) }; diff --git a/src/app/tools/drawTools/vtoolcutsplinepath.cpp b/src/app/tools/drawTools/vtoolcutsplinepath.cpp index 5148330a2..fc8d73562 100644 --- a/src/app/tools/drawTools/vtoolcutsplinepath.cpp +++ b/src/app/tools/drawTools/vtoolcutsplinepath.cpp @@ -30,6 +30,8 @@ #include "../../container/calculator.h" #include "../../dialogs/tools/dialogcutsplinepath.h" #include "../../geometry/vpointf.h" +#include "../../visualization/vistoolcutsplinepath.h" +#include "vabstractspline.h" #include "../../geometry/vsplinepath.h" @@ -91,7 +93,8 @@ void VToolCutSplinePath::setDialog() * @param doc dom document container. * @param data container with variables. */ -void VToolCutSplinePath::Create(DialogTool *dialog, VMainGraphicsScene *scene, VPattern *doc, VContainer *data) +VToolCutSplinePath* VToolCutSplinePath::Create(DialogTool *dialog, VMainGraphicsScene *scene, VPattern *doc, + VContainer *data) { SCASSERT(dialog != nullptr); DialogCutSplinePath *dialogTool = qobject_cast(dialog); @@ -99,7 +102,13 @@ void VToolCutSplinePath::Create(DialogTool *dialog, VMainGraphicsScene *scene, V const QString pointName = dialogTool->getPointName(); QString formula = dialogTool->getFormula(); const quint32 splinePathId = dialogTool->getSplinePathId(); - Create(0, pointName, formula, splinePathId, 5, 10, scene, doc, data, Document::FullParse, Source::FromGui); + VToolCutSplinePath* point = nullptr; + point = Create(0, pointName, formula, splinePathId, 5, 10, scene, doc, data, Document::FullParse, Source::FromGui); + if (point != nullptr) + { + point->dialog=dialogTool; + } + return point; } //--------------------------------------------------------------------------------------------------------------------- @@ -117,10 +126,10 @@ void VToolCutSplinePath::Create(DialogTool *dialog, VMainGraphicsScene *scene, V * @param parse parser file mode. * @param typeCreation way we create this tool. */ -void VToolCutSplinePath::Create(const quint32 _id, const QString &pointName, QString &formula, - const quint32 &splinePathId, const qreal &mx, const qreal &my, - VMainGraphicsScene *scene, VPattern *doc, VContainer *data, - const Document &parse, const Source &typeCreation) +VToolCutSplinePath* VToolCutSplinePath::Create(const quint32 _id, const QString &pointName, QString &formula, + const quint32 &splinePathId, const qreal &mx, const qreal &my, + VMainGraphicsScene *scene, VPattern *doc, VContainer *data, + const Document &parse, const Source &typeCreation) { const QSharedPointer splPath = data->GeometricObject(splinePathId); SCASSERT(splPath != nullptr); @@ -162,16 +171,16 @@ void VToolCutSplinePath::Create(const quint32 _id, const QString &pointName, QSt splPath1->append(VSplinePoint(splP1.P(), splP1.KAsm1(), spl1.GetAngle1()+180, spl1.GetKasm1(), spl1.GetAngle1())); VSplinePoint cutPoint; - if (typeCreation == Source::FromGui) - { - cutPoint = VSplinePoint(*p, spl1.GetKasm2(), spl1.GetAngle2(), spl1.GetAngle2()+180, - spl1.GetAngle2()); - } - else - { +// if (typeCreation == Source::FromGui) +// { +// cutPoint = VSplinePoint(*p, spl1.GetKasm2(), spl1.GetAngle2(), spl2.GetKasm1(), +// spl1.GetAngle2()); +// } +// else +// { cutPoint = VSplinePoint(*p, spl1.GetKasm2(), spl1.GetAngle2(), spl2.GetKasm1(), spl1.GetAngle2()+180); - } +// } splPath1->append(cutPoint); continue; } @@ -217,7 +226,7 @@ void VToolCutSplinePath::Create(const quint32 _id, const QString &pointName, QSt } } - VDrawTool::AddRecord(id, Tool::CutSplinePathTool, doc); + VDrawTool::AddRecord(id, Tool::CutSplinePath, doc); if (parse == Document::FullParse) { VToolCutSplinePath *point = new VToolCutSplinePath(doc, data, id, formula, splinePathId, splPath1id, @@ -230,6 +239,45 @@ void VToolCutSplinePath::Create(const quint32 _id, const QString &pointName, QSt doc->AddTool(splPath1id, point); doc->AddTool(splPath2id, point); doc->IncrementReferens(splinePathId); + return point; + } + return nullptr; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolCutSplinePath::ShowVisualization(bool show) +{ + if (show) + { + if (vis == nullptr) + { + VisToolCutSplinePath *visual = new VisToolCutSplinePath(getData()); + VMainGraphicsScene *scene = qApp->getCurrentScene(); + connect(scene, &VMainGraphicsScene::NewFactor, visual, &Visualization::SetFactor); + scene->addItem(visual); + + visual->setPoint1Id(curveCutId); + visual->setLength(formula); + visual->RefreshGeometry(); + vis = visual; + } + else + { + VisToolCutSplinePath *visual = qobject_cast(vis); + if (visual != nullptr) + { + visual->show(); + } + } + } + else + { + delete vis; + vis = nullptr; + } + if (VAbstractSpline *parentCurve = qobject_cast(doc->getTool(curveCutId))) + { + parentCurve->ShowFoot(show); } } @@ -240,6 +288,14 @@ void VToolCutSplinePath::Create(const quint32 _id, const QString &pointName, QSt void VToolCutSplinePath::FullUpdateFromFile() { FullUpdateCurveFromFile(AttrSplinePath); + + if (vis != nullptr) + { + VisToolCutSplinePath *visual = qobject_cast(vis); + visual->setPoint1Id(curveCutId); + visual->setLength(formula); + visual->RefreshGeometry(); + } } //--------------------------------------------------------------------------------------------------------------------- @@ -272,45 +328,6 @@ void VToolCutSplinePath::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) ContextMenu(this, event); } -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief AddToFile add tag with informations about tool into file. - */ -void VToolCutSplinePath::AddToFile() -{ - const QSharedPointer point = VAbstractTool::data.GeometricObject(id); - QDomElement domElement = doc->createElement(TagName); - - doc->SetAttribute(domElement, VDomDocument::AttrId, id); - doc->SetAttribute(domElement, AttrType, ToolType); - doc->SetAttribute(domElement, AttrName, point->name()); - doc->SetAttribute(domElement, AttrMx, qApp->fromPixel(point->mx())); - doc->SetAttribute(domElement, AttrMy, qApp->fromPixel(point->my())); - - doc->SetAttribute(domElement, AttrLength, formula); - doc->SetAttribute(domElement, AttrSplinePath, curveCutId); - - AddToCalculation(domElement); -} - -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief RefreshDataInFile refresh attributes in file. If attributes don't exist create them. - */ -void VToolCutSplinePath::RefreshDataInFile() -{ - const QSharedPointer point = VAbstractTool::data.GeometricObject(id); - QDomElement domElement = doc->elementById(QString().setNum(id)); - if (domElement.isElement()) - { - doc->SetAttribute(domElement, AttrName, point->name()); - doc->SetAttribute(domElement, AttrMx, qApp->fromPixel(point->mx())); - doc->SetAttribute(domElement, AttrMy, qApp->fromPixel(point->my())); - doc->SetAttribute(domElement, AttrLength, formula); - doc->SetAttribute(domElement, AttrSplinePath, curveCutId); - } -} - //--------------------------------------------------------------------------------------------------------------------- /** * @brief SaveDialog save options into file after change in dialog. @@ -351,3 +368,19 @@ void VToolCutSplinePath::RefreshCurve(VSimpleCurve *curve, quint32 curveId, Simp } curve->setPath(path); } + +//--------------------------------------------------------------------------------------------------------------------- +void VToolCutSplinePath::SaveOptions(QDomElement &tag, QSharedPointer &obj) +{ + QSharedPointer point = qSharedPointerDynamicCast(obj); + SCASSERT(point.isNull() == false); + + doc->SetAttribute(tag, VDomDocument::AttrId, id); + doc->SetAttribute(tag, AttrType, ToolType); + doc->SetAttribute(tag, AttrName, point->name()); + doc->SetAttribute(tag, AttrMx, qApp->fromPixel(point->mx())); + doc->SetAttribute(tag, AttrMy, qApp->fromPixel(point->my())); + + doc->SetAttribute(tag, AttrLength, formula); + doc->SetAttribute(tag, AttrSplinePath, curveCutId); +} diff --git a/src/app/tools/drawTools/vtoolcutsplinepath.h b/src/app/tools/drawTools/vtoolcutsplinepath.h index 9bb29913c..6f5db493c 100644 --- a/src/app/tools/drawTools/vtoolcutsplinepath.h +++ b/src/app/tools/drawTools/vtoolcutsplinepath.h @@ -44,23 +44,26 @@ public: const quint32 &splinePathId, const quint32 &splPath1id, const quint32 &splPath2id, const Source &typeCreation, QGraphicsItem * parent = nullptr); virtual void setDialog(); - static void Create(DialogTool *dialog, VMainGraphicsScene *scene, VPattern *doc, VContainer *data); - static void Create(const quint32 _id, const QString &pointName, QString &formula, const quint32 &splinePathId, - const qreal &mx, const qreal &my, VMainGraphicsScene *scene, VPattern *doc, VContainer *data, - const Document &parse, const Source &typeCreation); + static VToolCutSplinePath *Create(DialogTool *dialog, VMainGraphicsScene *scene, VPattern *doc, VContainer *data); + static VToolCutSplinePath *Create(const quint32 _id, const QString &pointName, QString &formula, + const quint32 &splinePathId, const qreal &mx, const qreal &my, + VMainGraphicsScene *scene, VPattern *doc, VContainer *data, + const Document &parse, const Source &typeCreation); static const QString ToolType; static const QString AttrSplinePath; + virtual int type() const {return Type;} + enum { Type = UserType + static_cast(Tool::CutSplinePath)}; + virtual void ShowVisualization(bool show); public slots: virtual void FullUpdateFromFile(); virtual void CurveChoosed(quint32 id); virtual void ShowContextMenu(QGraphicsSceneContextMenuEvent *event); protected: virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ); - virtual void AddToFile(); - virtual void RefreshDataInFile(); virtual void SaveDialog(QDomElement &domElement); virtual void RefreshCurve(VSimpleCurve *curve, quint32 curveId, SimpleCurvePoint curvePosition, PathDirection direction = PathDirection::Hide); + virtual void SaveOptions(QDomElement &tag, QSharedPointer &obj); private: Q_DISABLE_COPY(VToolCutSplinePath) }; diff --git a/src/app/tools/drawTools/vtoolendline.cpp b/src/app/tools/drawTools/vtoolendline.cpp index b77479a13..5ddad6a71 100644 --- a/src/app/tools/drawTools/vtoolendline.cpp +++ b/src/app/tools/drawTools/vtoolendline.cpp @@ -32,6 +32,7 @@ #include "../../dialogs/tools/dialogendline.h" #include "../../dialogs/tools/dialogeditwrongformula.h" #include "../../geometry/vpointf.h" +#include "./../visualization/vistoolendline.h" const QString VToolEndLine::ToolType = QStringLiteral("endLine"); @@ -154,7 +155,7 @@ VToolEndLine* VToolEndLine::Create(const quint32 _id, const QString &pointName, doc->UpdateToolData(id, data); } } - VDrawTool::AddRecord(id, Tool::EndLineTool, doc); + VDrawTool::AddRecord(id, Tool::EndLine, doc); if (parse == Document::FullParse) { VToolEndLine *point = new VToolEndLine(doc, data, id, typeLine, formulaLength, formulaAngle, basePointId, @@ -185,6 +186,16 @@ void VToolEndLine::FullUpdateFromFile() formulaAngle = domElement.attribute(AttrAngle, ""); } RefreshGeometry(); + + if (vis != nullptr) + { + VisToolEndLine *visual = qobject_cast(vis); + visual->setPoint1Id(basePointId); + visual->setLength(formulaLength); + visual->setAngle(formulaAngle); + visual->setLineStyle(VAbstractTool::LineStyle(typeLine)); + visual->RefreshGeometry(); + } } //--------------------------------------------------------------------------------------------------------------------- @@ -207,49 +218,6 @@ void VToolEndLine::ShowContextMenu(QGraphicsSceneContextMenuEvent *event) ContextMenu(this, event); } -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief AddToFile add tag with informations about tool into file. - */ -void VToolEndLine::AddToFile() -{ - const QSharedPointer point = VAbstractTool::data.GeometricObject(id); - QDomElement domElement = doc->createElement(TagName); - - doc->SetAttribute(domElement, VDomDocument::AttrId, id); - doc->SetAttribute(domElement, AttrType, ToolType); - doc->SetAttribute(domElement, AttrName, point->name()); - doc->SetAttribute(domElement, AttrMx, qApp->fromPixel(point->mx())); - doc->SetAttribute(domElement, AttrMy, qApp->fromPixel(point->my())); - - doc->SetAttribute(domElement, AttrTypeLine, typeLine); - doc->SetAttribute(domElement, AttrLength, formulaLength); - doc->SetAttribute(domElement, AttrAngle, formulaAngle); - doc->SetAttribute(domElement, AttrBasePoint, basePointId); - - AddToCalculation(domElement); -} - -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief RefreshDataInFile refresh attributes in file. If attributes don't exist create them. - */ -void VToolEndLine::RefreshDataInFile() -{ - const QSharedPointer point = VAbstractTool::data.GeometricObject(id); - QDomElement domElement = doc->elementById(QString().setNum(id)); - if (domElement.isElement()) - { - doc->SetAttribute(domElement, AttrName, point->name()); - doc->SetAttribute(domElement, AttrMx, qApp->fromPixel(point->mx())); - doc->SetAttribute(domElement, AttrMy, qApp->fromPixel(point->my())); - doc->SetAttribute(domElement, AttrTypeLine, typeLine); - doc->SetAttribute(domElement, AttrLength, formulaLength); - doc->SetAttribute(domElement, AttrAngle, formulaAngle); - doc->SetAttribute(domElement, AttrBasePoint, basePointId); - } -} - //--------------------------------------------------------------------------------------------------------------------- /** * @brief SaveDialog save options into file after change in dialog. @@ -265,3 +233,78 @@ void VToolEndLine::SaveDialog(QDomElement &domElement) doc->SetAttribute(domElement, AttrAngle, dialogTool->getAngle()); doc->SetAttribute(domElement, AttrBasePoint, QString().setNum(dialogTool->getBasePointId())); } + +//--------------------------------------------------------------------------------------------------------------------- +void VToolEndLine::SaveOptions(QDomElement &tag, QSharedPointer &obj) +{ + QSharedPointer point = qSharedPointerDynamicCast(obj); + SCASSERT(point.isNull() == false); + + doc->SetAttribute(tag, VDomDocument::AttrId, id); + doc->SetAttribute(tag, AttrType, ToolType); + doc->SetAttribute(tag, AttrName, point->name()); + doc->SetAttribute(tag, AttrMx, qApp->fromPixel(point->mx())); + doc->SetAttribute(tag, AttrMy, qApp->fromPixel(point->my())); + + doc->SetAttribute(tag, AttrTypeLine, typeLine); + doc->SetAttribute(tag, AttrLength, formulaLength); + doc->SetAttribute(tag, AttrAngle, formulaAngle); + doc->SetAttribute(tag, AttrBasePoint, basePointId); +} + +//--------------------------------------------------------------------------------------------------------------------- +VFormula VToolEndLine::getFormulaAngle() const +{ + VFormula fAngle(formulaAngle, getData()); + fAngle.setCheckZero(false); + fAngle.setToolId(id); + fAngle.setPostfix(QStringLiteral("°")); + return fAngle; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolEndLine::setFormulaAngle(const VFormula &value) +{ + if (value.error() == false) + { + formulaAngle = value.getFormula(FormulaType::FromUser); + + QSharedPointer obj = VAbstractTool::data.GetGObject(id); + SaveOption(obj); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolEndLine::ShowVisualization(bool show) +{ + if (show) + { + if (vis == nullptr) + { + VisToolEndLine * visual = new VisToolEndLine(getData()); + VMainGraphicsScene *scene = qApp->getCurrentScene(); + connect(scene, &VMainGraphicsScene::NewFactor, visual, &Visualization::SetFactor); + scene->addItem(visual); + + visual->setPoint1Id(basePointId); + visual->setLength(formulaLength); + visual->setAngle(formulaAngle); + visual->setLineStyle(VAbstractTool::LineStyle(typeLine)); + visual->RefreshGeometry(); + vis = visual; + } + else + { + VisToolEndLine *visual = qobject_cast(vis); + if (visual != nullptr) + { + visual->show(); + } + } + } + else + { + delete vis; + vis = nullptr; + } +} diff --git a/src/app/tools/drawTools/vtoolendline.h b/src/app/tools/drawTools/vtoolendline.h index 22798fcb4..794f51cfe 100644 --- a/src/app/tools/drawTools/vtoolendline.h +++ b/src/app/tools/drawTools/vtoolendline.h @@ -49,14 +49,19 @@ public: const qreal &mx, const qreal &my, VMainGraphicsScene *scene, VPattern *doc, VContainer *data, const Document &parse, const Source &typeCreation); static const QString ToolType; + virtual int type() const {return Type;} + enum { Type = UserType + static_cast(Tool::EndLine)}; + + VFormula getFormulaAngle() const; + void setFormulaAngle(const VFormula &value); + virtual void ShowVisualization(bool show); public slots: virtual void FullUpdateFromFile(); virtual void ShowContextMenu(QGraphicsSceneContextMenuEvent *event); protected: virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ); - virtual void AddToFile(); - virtual void RefreshDataInFile(); virtual void SaveDialog(QDomElement &domElement); + virtual void SaveOptions(QDomElement &tag, QSharedPointer &obj); private: QString formulaAngle; }; diff --git a/src/app/tools/drawTools/vtoolheight.cpp b/src/app/tools/drawTools/vtoolheight.cpp index 8425e50f7..19e24e9c3 100644 --- a/src/app/tools/drawTools/vtoolheight.cpp +++ b/src/app/tools/drawTools/vtoolheight.cpp @@ -29,6 +29,7 @@ #include "vtoolheight.h" #include "../../dialogs/tools/dialogheight.h" #include "../../geometry/vpointf.h" +#include "../../visualization/vistoolheight.h" const QString VToolHeight::ToolType = QStringLiteral("height"); @@ -202,6 +203,15 @@ void VToolHeight::FullUpdateFromFile() } RefreshGeometry(); + if (vis != nullptr) + { + VisToolHeight *visual = qobject_cast(vis); + visual->setPoint1Id(basePointId); + visual->setLineP1Id(p1LineId); + visual->setLineP2Id(p2LineId); + visual->setLineStyle(VAbstractTool::LineStyle(typeLine)); + visual->RefreshGeometry(); + } } //--------------------------------------------------------------------------------------------------------------------- @@ -224,50 +234,6 @@ void VToolHeight::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) ContextMenu(this, event); } -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief AddToFile add tag with informations about tool into file. - */ -void VToolHeight::AddToFile() -{ - const QSharedPointer point = VAbstractTool::data.GeometricObject(id); - QDomElement domElement = doc->createElement(TagName); - - doc->SetAttribute(domElement, VDomDocument::AttrId, id); - doc->SetAttribute(domElement, AttrType, ToolType); - doc->SetAttribute(domElement, AttrName, point->name()); - doc->SetAttribute(domElement, AttrMx, qApp->fromPixel(point->mx())); - doc->SetAttribute(domElement, AttrMy, qApp->fromPixel(point->my())); - - doc->SetAttribute(domElement, AttrTypeLine, typeLine); - doc->SetAttribute(domElement, AttrBasePoint, basePointId); - doc->SetAttribute(domElement, AttrP1Line, p1LineId); - doc->SetAttribute(domElement, AttrP2Line, p2LineId); - - AddToCalculation(domElement); - -} - -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief RefreshDataInFile refresh attributes in file. If attributes don't exist create them. - */ -void VToolHeight::RefreshDataInFile() -{ - const QSharedPointer point = VAbstractTool::data.GeometricObject(id); - QDomElement domElement = doc->elementById(QString().setNum(id)); - if (domElement.isElement()) - { - doc->SetAttribute(domElement, AttrName, point->name()); - doc->SetAttribute(domElement, AttrMx, qApp->fromPixel(point->mx())); - doc->SetAttribute(domElement, AttrMy, qApp->fromPixel(point->my())); - doc->SetAttribute(domElement, AttrTypeLine, typeLine); - doc->SetAttribute(domElement, AttrBasePoint, basePointId); - doc->SetAttribute(domElement, AttrP1Line, p1LineId); - doc->SetAttribute(domElement, AttrP2Line, p2LineId); - } -} - //--------------------------------------------------------------------------------------------------------------------- /** * @brief SaveDialog save options into file after change in dialog. @@ -283,3 +249,93 @@ void VToolHeight::SaveDialog(QDomElement &domElement) doc->SetAttribute(domElement, AttrP1Line, QString().setNum(dialogTool->getP1LineId())); doc->SetAttribute(domElement, AttrP2Line, QString().setNum(dialogTool->getP2LineId())); } + +//--------------------------------------------------------------------------------------------------------------------- +void VToolHeight::SaveOptions(QDomElement &tag, QSharedPointer &obj) +{ + QSharedPointer point = qSharedPointerDynamicCast(obj); + SCASSERT(point.isNull() == false); + + doc->SetAttribute(tag, VDomDocument::AttrId, id); + doc->SetAttribute(tag, AttrType, ToolType); + doc->SetAttribute(tag, AttrName, point->name()); + doc->SetAttribute(tag, AttrMx, qApp->fromPixel(point->mx())); + doc->SetAttribute(tag, AttrMy, qApp->fromPixel(point->my())); + + doc->SetAttribute(tag, AttrTypeLine, typeLine); + doc->SetAttribute(tag, AttrBasePoint, basePointId); + doc->SetAttribute(tag, AttrP1Line, p1LineId); + doc->SetAttribute(tag, AttrP2Line, p2LineId); +} + +//--------------------------------------------------------------------------------------------------------------------- +quint32 VToolHeight::getP2LineId() const +{ + return p2LineId; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolHeight::setP2LineId(const quint32 &value) +{ + if (value != NULL_ID) + { + p2LineId = value; + + QSharedPointer obj = VAbstractTool::data.GetGObject(id); + SaveOption(obj); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolHeight::ShowVisualization(bool show) +{ + if (show) + { + if (vis == nullptr) + { + VisToolHeight * visual = new VisToolHeight(getData()); + VMainGraphicsScene *scene = qApp->getCurrentScene(); + connect(scene, &VMainGraphicsScene::NewFactor, visual, &Visualization::SetFactor); + scene->addItem(visual); + + visual->setPoint1Id(basePointId); + visual->setLineP1Id(p1LineId); + visual->setLineP2Id(p2LineId); + visual->setLineStyle(VAbstractTool::LineStyle(typeLine)); + visual->RefreshGeometry(); + vis = visual; + } + else + { + VisToolHeight *visual = qobject_cast(vis); + if (visual != nullptr) + { + visual->show(); + } + } + } + else + { + delete vis; + vis = nullptr; + } +} + +//--------------------------------------------------------------------------------------------------------------------- +quint32 VToolHeight::getP1LineId() const +{ + return p1LineId; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolHeight::setP1LineId(const quint32 &value) +{ + if (value != NULL_ID) + { + p1LineId = value; + + QSharedPointer obj = VAbstractTool::data.GetGObject(id); + SaveOption(obj); + } +} + diff --git a/src/app/tools/drawTools/vtoolheight.h b/src/app/tools/drawTools/vtoolheight.h index b8e680930..79dcfe08f 100644 --- a/src/app/tools/drawTools/vtoolheight.h +++ b/src/app/tools/drawTools/vtoolheight.h @@ -50,14 +50,23 @@ public: VContainer *data, const Document &parse, const Source &typeCreation); static QPointF FindPoint(const QLineF &line, const QPointF &point); static const QString ToolType; + virtual int type() const {return Type;} + enum { Type = UserType + static_cast(Tool::Height)}; + + quint32 getP1LineId() const; + void setP1LineId(const quint32 &value); + + quint32 getP2LineId() const; + void setP2LineId(const quint32 &value); + + virtual void ShowVisualization(bool show); public slots: virtual void FullUpdateFromFile(); virtual void ShowContextMenu(QGraphicsSceneContextMenuEvent *event); protected: virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ); - virtual void AddToFile(); - virtual void RefreshDataInFile(); virtual void SaveDialog(QDomElement &domElement); + virtual void SaveOptions(QDomElement &tag, QSharedPointer &obj); private: /** @brief p1LineId id first point of line. */ quint32 p1LineId; diff --git a/src/app/tools/drawTools/vtoolline.cpp b/src/app/tools/drawTools/vtoolline.cpp index ef718f501..5f9db41c6 100644 --- a/src/app/tools/drawTools/vtoolline.cpp +++ b/src/app/tools/drawTools/vtoolline.cpp @@ -31,6 +31,7 @@ #include #include "../../geometry/vpointf.h" #include "../../dialogs/tools/dialogline.h" +#include "../../visualization/vistoolline.h" const QString VToolLine::TagName = QStringLiteral("line"); @@ -147,7 +148,7 @@ VToolLine * VToolLine::Create(const quint32 &_id, const quint32 &firstPoint, con doc->UpdateToolData(id, data); } } - VDrawTool::AddRecord(id, Tool::LineTool, doc); + VDrawTool::AddRecord(id, Tool::Line, doc); if (parse == Document::FullParse) { VToolLine *line = new VToolLine(doc, data, id, firstPoint, secondPoint, typeLine, typeCreation); @@ -176,6 +177,12 @@ void VToolLine::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QGraphicsLineItem::paint(painter, &myOption, widget); } +//--------------------------------------------------------------------------------------------------------------------- +QString VToolLine::getTagName() const +{ + return VToolLine::TagName; +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief FullUpdateFromFile update tool data form file. @@ -183,6 +190,15 @@ void VToolLine::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, void VToolLine::FullUpdateFromFile() { RefreshGeometry(); + + if (vis != nullptr) + { + VisToolLine *visual = qobject_cast(vis); + visual->setPoint1Id(firstPoint); + visual->setPoint2Id(secondPoint); + visual->setLineStyle(VAbstractTool::LineStyle(typeLine)); + visual->RefreshGeometry(); + } } //--------------------------------------------------------------------------------------------------------------------- @@ -254,11 +270,8 @@ void VToolLine::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) void VToolLine::AddToFile() { QDomElement domElement = doc->createElement(TagName); - doc->SetAttribute(domElement, VDomDocument::AttrId, id); - doc->SetAttribute(domElement, AttrFirstPoint, firstPoint); - doc->SetAttribute(domElement, AttrSecondPoint, secondPoint); - doc->SetAttribute(domElement, AttrTypeLine, typeLine); - + QSharedPointer obj = QSharedPointer (); + SaveOptions(domElement, obj); AddToCalculation(domElement); } @@ -271,9 +284,12 @@ void VToolLine::RefreshDataInFile() QDomElement domElement = doc->elementById(QString().setNum(id)); if (domElement.isElement()) { - doc->SetAttribute(domElement, AttrFirstPoint, firstPoint); - doc->SetAttribute(domElement, AttrSecondPoint, secondPoint); - doc->SetAttribute(domElement, AttrTypeLine, typeLine); + QSharedPointer obj = QSharedPointer (); + SaveOptions(domElement, obj); + } + else + { + qDebug()<<"Can't find tool with id ="<< id << Q_FUNC_INFO; } } @@ -366,6 +382,87 @@ void VToolLine::SaveDialog(QDomElement &domElement) doc->SetAttribute(domElement, AttrTypeLine, dialogTool->getTypeLine()); } +//--------------------------------------------------------------------------------------------------------------------- +void VToolLine::SaveOptions(QDomElement &tag, QSharedPointer &obj) +{ + Q_UNUSED(obj) + + doc->SetAttribute(tag, VDomDocument::AttrId, id); + doc->SetAttribute(tag, AttrFirstPoint, firstPoint); + doc->SetAttribute(tag, AttrSecondPoint, secondPoint); + doc->SetAttribute(tag, AttrTypeLine, typeLine); +} + +//--------------------------------------------------------------------------------------------------------------------- +quint32 VToolLine::getSecondPoint() const +{ + return secondPoint; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolLine::setSecondPoint(const quint32 &value) +{ + if (value != NULL_ID) + { + secondPoint = value; + + QSharedPointer obj = VAbstractTool::data.GetGObject(id); + SaveOption(obj); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolLine::ShowVisualization(bool show) +{ + if (show) + { + if (vis == nullptr) + { + VisToolLine * visual = new VisToolLine(getData()); + VMainGraphicsScene *scene = qApp->getCurrentScene(); + connect(scene, &VMainGraphicsScene::NewFactor, visual, &Visualization::SetFactor); + scene->addItem(visual); + + visual->setPoint1Id(firstPoint); + visual->setPoint2Id(secondPoint); + visual->setLineStyle(VAbstractTool::LineStyle(typeLine)); + visual->RefreshGeometry(); + vis = visual; + } + else + { + VisToolLine *visual = qobject_cast(vis); + if (visual != nullptr) + { + visual->show(); + } + } + } + else + { + delete vis; + vis = nullptr; + } +} + +//--------------------------------------------------------------------------------------------------------------------- +quint32 VToolLine::getFirstPoint() const +{ + return firstPoint; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolLine::setFirstPoint(const quint32 &value) +{ + if (value != NULL_ID) + { + firstPoint = value; + + QSharedPointer obj = VAbstractTool::data.GetGObject(id); + SaveOption(obj); + } +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief RefreshGeometry refresh item on scene. diff --git a/src/app/tools/drawTools/vtoolline.h b/src/app/tools/drawTools/vtoolline.h index 74ef14a59..5e333e391 100644 --- a/src/app/tools/drawTools/vtoolline.h +++ b/src/app/tools/drawTools/vtoolline.h @@ -48,6 +48,16 @@ public: const Document &parse, const Source &typeCreation); static const QString TagName; virtual void paint(QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget = 0); + virtual int type() const {return Type;} + enum { Type = UserType + static_cast(Tool::Line)}; + virtual QString getTagName() const; + quint32 getFirstPoint() const; + void setFirstPoint(const quint32 &value); + + quint32 getSecondPoint() const; + void setSecondPoint(const quint32 &value); + + virtual void ShowVisualization(bool show); public slots: virtual void FullUpdateFromFile(); virtual void ChangedActivDraw(const QString &newName); @@ -64,6 +74,7 @@ protected: virtual QVariant itemChange ( GraphicsItemChange change, const QVariant &value ); virtual void keyReleaseEvent(QKeyEvent * event); virtual void SaveDialog(QDomElement &domElement); + virtual void SaveOptions(QDomElement &tag, QSharedPointer &obj); private: /** @brief firstPoint id first line point. */ quint32 firstPoint; diff --git a/src/app/tools/drawTools/vtoollineintersect.cpp b/src/app/tools/drawTools/vtoollineintersect.cpp index 84c594214..286605a05 100644 --- a/src/app/tools/drawTools/vtoollineintersect.cpp +++ b/src/app/tools/drawTools/vtoollineintersect.cpp @@ -29,6 +29,7 @@ #include "vtoollineintersect.h" #include "../../dialogs/tools/dialoglineintersect.h" #include "../../geometry/vpointf.h" +#include "../../visualization/vistoollineintersect.h" const QString VToolLineIntersect::ToolType = QStringLiteral("lineIntersect"); @@ -166,7 +167,7 @@ VToolLineIntersect* VToolLineIntersect::Create(const quint32 _id, const quint32 doc->UpdateToolData(id, data); } } - VDrawTool::AddRecord(id, Tool::LineIntersectTool, doc); + VDrawTool::AddRecord(id, Tool::LineIntersect, doc); if (parse == Document::FullParse) { VToolLineIntersect *point = new VToolLineIntersect(doc, data, id, p1Line1Id, p2Line1Id, p1Line2Id, @@ -201,6 +202,16 @@ void VToolLineIntersect::FullUpdateFromFile() p2Line2 = domElement.attribute(AttrP2Line2, "").toUInt(); } RefreshPointGeometry(*VAbstractTool::data.GeometricObject(id)); + + if (vis != nullptr) + { + VisToolLineIntersect *visual = qobject_cast(vis); + visual->setPoint1Id(p1Line1); + visual->setLine1P2Id(p2Line1); + visual->setLine2P1Id(p1Line2); + visual->setLine2P2Id(p2Line2); + vis->RefreshGeometry(); + } } //--------------------------------------------------------------------------------------------------------------------- @@ -234,49 +245,6 @@ void VToolLineIntersect::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) ContextMenu(this, event); } -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief AddToFile add tag with informations about tool into file. - */ -void VToolLineIntersect::AddToFile() -{ - const QSharedPointer point = VAbstractTool::data.GeometricObject(id); - QDomElement domElement = doc->createElement(TagName); - - doc->SetAttribute(domElement, VDomDocument::AttrId, id); - doc->SetAttribute(domElement, AttrType, ToolType); - doc->SetAttribute(domElement, AttrName, point->name()); - doc->SetAttribute(domElement, AttrMx, qApp->fromPixel(point->mx())); - doc->SetAttribute(domElement, AttrMy, qApp->fromPixel(point->my())); - - doc->SetAttribute(domElement, AttrP1Line1, p1Line1); - doc->SetAttribute(domElement, AttrP2Line1, p2Line1); - doc->SetAttribute(domElement, AttrP1Line2, p1Line2); - doc->SetAttribute(domElement, AttrP2Line2, p2Line2); - - AddToCalculation(domElement); -} - -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief RefreshDataInFile refresh attributes in file. If attributes don't exist create them. - */ -void VToolLineIntersect::RefreshDataInFile() -{ - const QSharedPointer point = VAbstractTool::data.GeometricObject(id); - QDomElement domElement = doc->elementById(QString().setNum(id)); - if (domElement.isElement()) - { - doc->SetAttribute(domElement, AttrName, point->name()); - doc->SetAttribute(domElement, AttrMx, qApp->fromPixel(point->mx())); - doc->SetAttribute(domElement, AttrMy, qApp->fromPixel(point->my())); - doc->SetAttribute(domElement, AttrP1Line1, p1Line1); - doc->SetAttribute(domElement, AttrP2Line1, p2Line1); - doc->SetAttribute(domElement, AttrP1Line2, p1Line2); - doc->SetAttribute(domElement, AttrP2Line2, p2Line2); - } -} - //--------------------------------------------------------------------------------------------------------------------- /** * @brief RemoveReferens decrement value of reference. @@ -304,3 +272,129 @@ void VToolLineIntersect::SaveDialog(QDomElement &domElement) doc->SetAttribute(domElement, AttrP1Line2, QString().setNum(dialogTool->getP1Line2())); doc->SetAttribute(domElement, AttrP2Line2, QString().setNum(dialogTool->getP2Line2())); } + +//--------------------------------------------------------------------------------------------------------------------- +void VToolLineIntersect::SaveOptions(QDomElement &tag, QSharedPointer &obj) +{ + QSharedPointer point = qSharedPointerDynamicCast(obj); + SCASSERT(point.isNull() == false); + + doc->SetAttribute(tag, VDomDocument::AttrId, id); + doc->SetAttribute(tag, AttrType, ToolType); + doc->SetAttribute(tag, AttrName, point->name()); + doc->SetAttribute(tag, AttrMx, qApp->fromPixel(point->mx())); + doc->SetAttribute(tag, AttrMy, qApp->fromPixel(point->my())); + + doc->SetAttribute(tag, AttrP1Line1, p1Line1); + doc->SetAttribute(tag, AttrP2Line1, p2Line1); + doc->SetAttribute(tag, AttrP1Line2, p1Line2); + doc->SetAttribute(tag, AttrP2Line2, p2Line2); +} + +//--------------------------------------------------------------------------------------------------------------------- +quint32 VToolLineIntersect::getP2Line2() const +{ + return p2Line2; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolLineIntersect::setP2Line2(const quint32 &value) +{ + if (value != NULL_ID) + { + p2Line2 = value; + + QSharedPointer obj = VAbstractTool::data.GetGObject(id); + SaveOption(obj); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolLineIntersect::ShowVisualization(bool show) +{ + if (show) + { + if (vis == nullptr) + { + VisToolLineIntersect * visual = new VisToolLineIntersect(getData()); + VMainGraphicsScene *scene = qApp->getCurrentScene(); + connect(scene, &VMainGraphicsScene::NewFactor, visual, &Visualization::SetFactor); + scene->addItem(visual); + + visual->setPoint1Id(p1Line1); + visual->setLine1P2Id(p2Line1); + visual->setLine2P1Id(p1Line2); + visual->setLine2P2Id(p2Line2); + visual->RefreshGeometry(); + vis = visual; + } + else + { + VisToolLineIntersect *visual = qobject_cast(vis); + if (visual != nullptr) + { + visual->show(); + } + } + } + else + { + delete vis; + vis = nullptr; + } +} + +//--------------------------------------------------------------------------------------------------------------------- +quint32 VToolLineIntersect::getP1Line2() const +{ + return p1Line2; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolLineIntersect::setP1Line2(const quint32 &value) +{ + if (value != NULL_ID) + { + p1Line2 = value; + + QSharedPointer obj = VAbstractTool::data.GetGObject(id); + SaveOption(obj); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +quint32 VToolLineIntersect::getP2Line1() const +{ + return p2Line1; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolLineIntersect::setP2Line1(const quint32 &value) +{ + if (value != NULL_ID) + { + p2Line1 = value; + + QSharedPointer obj = VAbstractTool::data.GetGObject(id); + SaveOption(obj); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +quint32 VToolLineIntersect::getP1Line1() const +{ + return p1Line1; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolLineIntersect::setP1Line1(const quint32 &value) +{ + if (value != NULL_ID) + { + p1Line1 = value; + + QSharedPointer obj = VAbstractTool::data.GetGObject(id); + SaveOption(obj); + } +} + diff --git a/src/app/tools/drawTools/vtoollineintersect.h b/src/app/tools/drawTools/vtoollineintersect.h index 7a8e3fd1c..dd28d16b9 100644 --- a/src/app/tools/drawTools/vtoollineintersect.h +++ b/src/app/tools/drawTools/vtoollineintersect.h @@ -48,16 +48,31 @@ public: const qreal &mx, const qreal &my, VMainGraphicsScene *scene, VPattern *doc, VContainer *data, const Document &parse, const Source &typeCreation); static const QString ToolType; + virtual int type() const {return Type;} + enum { Type = UserType + static_cast(Tool::LineIntersect)}; + + quint32 getP1Line1() const; + void setP1Line1(const quint32 &value); + + quint32 getP2Line1() const; + void setP2Line1(const quint32 &value); + + quint32 getP1Line2() const; + void setP1Line2(const quint32 &value); + + quint32 getP2Line2() const; + void setP2Line2(const quint32 &value); + + virtual void ShowVisualization(bool show); public slots: virtual void FullUpdateFromFile(); virtual void SetFactor(qreal factor); virtual void ShowContextMenu(QGraphicsSceneContextMenuEvent *event); protected: virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ); - virtual void AddToFile(); - virtual void RefreshDataInFile(); virtual void RemoveReferens(); virtual void SaveDialog(QDomElement &domElement); + virtual void SaveOptions(QDomElement &tag, QSharedPointer &obj); private: /** @brief p1Line1 id first point first line. */ quint32 p1Line1; diff --git a/src/app/tools/drawTools/vtoollinepoint.cpp b/src/app/tools/drawTools/vtoollinepoint.cpp index 6340b1c45..8f66014ac 100644 --- a/src/app/tools/drawTools/vtoollinepoint.cpp +++ b/src/app/tools/drawTools/vtoollinepoint.cpp @@ -107,3 +107,58 @@ void VToolLinePoint::SetFactor(qreal factor) VDrawTool::SetFactor(factor); RefreshGeometry(); } + +//--------------------------------------------------------------------------------------------------------------------- +qreal VToolLinePoint::getAngle() const +{ + return angle; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolLinePoint::setAngle(const qreal &value) +{ + angle = value; + QSharedPointer obj = VAbstractTool::data.GetGObject(id); + SaveOption(obj); +} + +//--------------------------------------------------------------------------------------------------------------------- +quint32 VToolLinePoint::getBasePointId() const +{ + return basePointId; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolLinePoint::setBasePointId(const quint32 &value) +{ + if (value != NULL_ID) + { + basePointId = value; + + QSharedPointer obj = VAbstractTool::data.GetGObject(id); + SaveOption(obj); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +VFormula VToolLinePoint::getFormulaLength() const +{ + VFormula fLength(formulaLength, this->getData()); + fLength.setCheckZero(true); + fLength.setToolId(id); + fLength.setPostfix(VDomDocument::UnitsToStr(qApp->patternUnit())); + + return fLength; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolLinePoint::setFormulaLength(const VFormula &value) +{ + if (value.error() == false) + { + formulaLength = value.getFormula(FormulaType::FromUser); + + QSharedPointer obj = VAbstractTool::data.GetGObject(id); + SaveOption(obj); + } +} diff --git a/src/app/tools/drawTools/vtoollinepoint.h b/src/app/tools/drawTools/vtoollinepoint.h index 08a0e34f9..dc77b5962 100644 --- a/src/app/tools/drawTools/vtoollinepoint.h +++ b/src/app/tools/drawTools/vtoollinepoint.h @@ -30,6 +30,7 @@ #define VTOOLLINEPOINT_H #include "vtoolpoint.h" +#include "../container/vformula.h" /** * @brief The VToolLinePoint class parent for all tools what create point with line. @@ -40,6 +41,17 @@ class VToolLinePoint : public VToolPoint public: VToolLinePoint(VPattern *doc, VContainer *data, const quint32 &id, const QString &typeLine, const QString &formula, const quint32 &basePointId, const qreal &angle, QGraphicsItem * parent = nullptr); + virtual int type() const {return Type;} + enum { Type = UserType + static_cast(Tool::LinePoint)}; + VFormula getFormulaLength() const; + void setFormulaLength(const VFormula &value); + + quint32 getBasePointId() const; + void setBasePointId(const quint32 &value); + + qreal getAngle() const; + void setAngle(const qreal &value); + public slots: virtual void ChangedActivDraw(const QString &newName); virtual void SetFactor(qreal factor); diff --git a/src/app/tools/drawTools/vtoolnormal.cpp b/src/app/tools/drawTools/vtoolnormal.cpp index 41ea76357..ff9334dfc 100644 --- a/src/app/tools/drawTools/vtoolnormal.cpp +++ b/src/app/tools/drawTools/vtoolnormal.cpp @@ -30,6 +30,7 @@ #include "../../container/calculator.h" #include "../../dialogs/tools/dialognormal.h" #include "../../geometry/vpointf.h" +#include "../../visualization/vistoolnormal.h" const QString VToolNormal::ToolType = QStringLiteral("normal"); @@ -157,7 +158,7 @@ VToolNormal* VToolNormal::Create(const quint32 _id, QString &formula, const quin doc->UpdateToolData(id, data); } } - VDrawTool::AddRecord(id, Tool::NormalTool, doc); + VDrawTool::AddRecord(id, Tool::Normal, doc); if (parse == Document::FullParse) { VToolNormal *point = new VToolNormal(doc, data, id, typeLine, formula, angle, @@ -209,6 +210,17 @@ void VToolNormal::FullUpdateFromFile() angle = domElement.attribute(AttrAngle, "").toDouble(); } RefreshGeometry(); + + if (vis != nullptr) + { + VisToolNormal *visual = qobject_cast(vis); + visual->setPoint1Id(basePointId); + visual->setPoint2Id(secondPointId); + visual->setLength(formulaLength); + visual->setAngle(angle); + visual->setLineStyle(VAbstractTool::LineStyle(typeLine)); + visual->RefreshGeometry(); + } } //--------------------------------------------------------------------------------------------------------------------- @@ -242,51 +254,6 @@ void VToolNormal::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) ContextMenu(this, event); } -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief AddToFile add tag with informations about tool into file. - */ -void VToolNormal::AddToFile() -{ - const QSharedPointer point = VAbstractTool::data.GeometricObject(id); - QDomElement domElement = doc->createElement(TagName); - - doc->SetAttribute(domElement, VDomDocument::AttrId, id); - doc->SetAttribute(domElement, AttrType, ToolType); - doc->SetAttribute(domElement, AttrName, point->name()); - doc->SetAttribute(domElement, AttrMx, qApp->fromPixel(point->mx())); - doc->SetAttribute(domElement, AttrMy, qApp->fromPixel(point->my())); - - doc->SetAttribute(domElement, AttrTypeLine, typeLine); - doc->SetAttribute(domElement, AttrLength, formulaLength); - doc->SetAttribute(domElement, AttrAngle, angle); - doc->SetAttribute(domElement, AttrFirstPoint, basePointId); - doc->SetAttribute(domElement, AttrSecondPoint, secondPointId); - - AddToCalculation(domElement); -} - -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief RefreshDataInFile refresh attributes in file. If attributes don't exist create them. - */ -void VToolNormal::RefreshDataInFile() -{ - const QSharedPointer point = VAbstractTool::data.GeometricObject(id); - QDomElement domElement = doc->elementById(QString().setNum(id)); - if (domElement.isElement()) - { - doc->SetAttribute(domElement, AttrName, point->name()); - doc->SetAttribute(domElement, AttrMx, qApp->fromPixel(point->mx())); - doc->SetAttribute(domElement, AttrMy, qApp->fromPixel(point->my())); - doc->SetAttribute(domElement, AttrTypeLine, typeLine); - doc->SetAttribute(domElement, AttrLength, formulaLength); - doc->SetAttribute(domElement, AttrAngle, angle); - doc->SetAttribute(domElement, AttrFirstPoint, basePointId); - doc->SetAttribute(domElement, AttrSecondPoint, secondPointId); - } -} - //--------------------------------------------------------------------------------------------------------------------- /** * @brief RemoveReferens decrement value of reference. @@ -313,3 +280,77 @@ void VToolNormal::SaveDialog(QDomElement &domElement) doc->SetAttribute(domElement, AttrFirstPoint, QString().setNum(dialogTool->getFirstPointId())); doc->SetAttribute(domElement, AttrSecondPoint, QString().setNum(dialogTool->getSecondPointId())); } + +//--------------------------------------------------------------------------------------------------------------------- +void VToolNormal::SaveOptions(QDomElement &tag, QSharedPointer &obj) +{ + QSharedPointer point = qSharedPointerDynamicCast(obj); + SCASSERT(point.isNull() == false); + + doc->SetAttribute(tag, VDomDocument::AttrId, id); + doc->SetAttribute(tag, AttrType, ToolType); + doc->SetAttribute(tag, AttrName, point->name()); + doc->SetAttribute(tag, AttrMx, qApp->fromPixel(point->mx())); + doc->SetAttribute(tag, AttrMy, qApp->fromPixel(point->my())); + + doc->SetAttribute(tag, AttrTypeLine, typeLine); + doc->SetAttribute(tag, AttrLength, formulaLength); + doc->SetAttribute(tag, AttrAngle, angle); + doc->SetAttribute(tag, AttrFirstPoint, basePointId); + doc->SetAttribute(tag, AttrSecondPoint, secondPointId); +} + +//--------------------------------------------------------------------------------------------------------------------- +quint32 VToolNormal::getSecondPointId() const +{ + return secondPointId; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolNormal::setSecondPointId(const quint32 &value) +{ + if (value != NULL_ID) + { + secondPointId = value; + + QSharedPointer obj = VAbstractTool::data.GetGObject(id); + SaveOption(obj); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolNormal::ShowVisualization(bool show) +{ + if (show) + { + if (vis == nullptr) + { + VisToolNormal * visual = new VisToolNormal(getData()); + VMainGraphicsScene *scene = qApp->getCurrentScene(); + connect(scene, &VMainGraphicsScene::NewFactor, visual, &Visualization::SetFactor); + scene->addItem(visual); + + visual->setPoint1Id(basePointId); + visual->setPoint2Id(secondPointId); + visual->setLength(formulaLength); + visual->setAngle(angle); + visual->setLineStyle(VAbstractTool::LineStyle(typeLine)); + visual->RefreshGeometry(); + vis = visual; + } + else + { + VisToolNormal *visual = qobject_cast(vis); + if (visual != nullptr) + { + visual->show(); + } + } + } + else + { + delete vis; + vis = nullptr; + } +} + diff --git a/src/app/tools/drawTools/vtoolnormal.h b/src/app/tools/drawTools/vtoolnormal.h index e1e65921e..3c85cb439 100644 --- a/src/app/tools/drawTools/vtoolnormal.h +++ b/src/app/tools/drawTools/vtoolnormal.h @@ -50,16 +50,22 @@ public: static QPointF FindPoint(const QPointF &firstPoint, const QPointF &secondPoint, const qreal &length, const qreal &angle = 0); static const QString ToolType; + virtual int type() const {return Type;} + enum { Type = UserType + static_cast(Tool::Normal)}; + + quint32 getSecondPointId() const; + void setSecondPointId(const quint32 &value); + + virtual void ShowVisualization(bool show); public slots: virtual void FullUpdateFromFile(); virtual void SetFactor(qreal factor); virtual void ShowContextMenu(QGraphicsSceneContextMenuEvent *event); protected: virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ); - virtual void AddToFile(); - virtual void RefreshDataInFile(); virtual void RemoveReferens(); virtual void SaveDialog(QDomElement &domElement); + virtual void SaveOptions(QDomElement &tag, QSharedPointer &obj); private: /** @brief secondPointId id second line point. */ quint32 secondPointId; diff --git a/src/app/tools/drawTools/vtoolpoint.cpp b/src/app/tools/drawTools/vtoolpoint.cpp index 3f4c8cb1c..8a40360a1 100644 --- a/src/app/tools/drawTools/vtoolpoint.cpp +++ b/src/app/tools/drawTools/vtoolpoint.cpp @@ -72,6 +72,26 @@ void VToolPoint::paint(QPainter *painter, const QStyleOptionGraphicsItem *option QGraphicsEllipseItem::paint(painter, &myOption, widget); } +//--------------------------------------------------------------------------------------------------------------------- +QString VToolPoint::name() const +{ + return VAbstractTool::data.GeometricObject(id)->name(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolPoint::setName(const QString &name) +{ + QSharedPointer obj = VAbstractTool::data.GetGObject(id); + obj->setName(name); + SaveOption(obj); +} + +//--------------------------------------------------------------------------------------------------------------------- +QString VToolPoint::getTagName() const +{ + return VToolPoint::TagName; +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief NameChangePosition handle change posion point label. diff --git a/src/app/tools/drawTools/vtoolpoint.h b/src/app/tools/drawTools/vtoolpoint.h index 926b59cbf..5c19d073a 100644 --- a/src/app/tools/drawTools/vtoolpoint.h +++ b/src/app/tools/drawTools/vtoolpoint.h @@ -44,8 +44,11 @@ class VToolPoint: public VDrawTool, public QGraphicsEllipseItem public: VToolPoint(VPattern *doc, VContainer *data, quint32 id, QGraphicsItem * parent = nullptr); virtual ~VToolPoint(){} - static const QString TagName; virtual void paint(QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget = 0); + QString name() const; + void setName(const QString &name); + virtual QString getTagName() const; + static const QString TagName; public slots: void NameChangePosition(const QPointF &pos); virtual void ChangedActivDraw(const QString &newName); diff --git a/src/app/tools/drawTools/vtoolpointofcontact.cpp b/src/app/tools/drawTools/vtoolpointofcontact.cpp index 0f7ae3e28..dd8d4f27e 100644 --- a/src/app/tools/drawTools/vtoolpointofcontact.cpp +++ b/src/app/tools/drawTools/vtoolpointofcontact.cpp @@ -30,6 +30,8 @@ #include "../../container/calculator.h" #include "../../dialogs/tools/dialogpointofcontact.h" #include "../../geometry/vpointf.h" +#include "../../container/vformula.h" +#include "../../visualization/vistoolpointofcontact.h" const QString VToolPointOfContact::ToolType = QStringLiteral("pointOfContact"); @@ -227,6 +229,16 @@ void VToolPointOfContact::FullUpdateFromFile() secondPointId = domElement.attribute(AttrSecondPoint, "").toUInt(); } RefreshPointGeometry(*VAbstractTool::data.GeometricObject(id)); + + if (vis != nullptr) + { + VisToolPointOfContact *visual = qobject_cast(vis); + visual->setPoint1Id(firstPointId); + visual->setLineP2Id(secondPointId); + visual->setRadiusId(center); + visual->setRadius(arcRadius); + visual->RefreshGeometry(); + } } //--------------------------------------------------------------------------------------------------------------------- @@ -260,49 +272,6 @@ void VToolPointOfContact::contextMenuEvent(QGraphicsSceneContextMenuEvent *event ContextMenu(this, event); } -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief AddToFile add tag with informations about tool into file. - */ -void VToolPointOfContact::AddToFile() -{ - const QSharedPointer point = VAbstractTool::data.GeometricObject(id); - QDomElement domElement = doc->createElement(TagName); - - doc->SetAttribute(domElement, VDomDocument::AttrId, id); - doc->SetAttribute(domElement, AttrType, ToolType); - doc->SetAttribute(domElement, AttrName, point->name()); - doc->SetAttribute(domElement, AttrMx, qApp->fromPixel(point->mx())); - doc->SetAttribute(domElement, AttrMy, qApp->fromPixel(point->my())); - - doc->SetAttribute(domElement, AttrRadius, arcRadius); - doc->SetAttribute(domElement, AttrCenter, center); - doc->SetAttribute(domElement, AttrFirstPoint, firstPointId); - doc->SetAttribute(domElement, AttrSecondPoint, secondPointId); - - AddToCalculation(domElement); -} - -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief RefreshDataInFile refresh attributes in file. If attributes don't exist create them. - */ -void VToolPointOfContact::RefreshDataInFile() -{ - const QSharedPointer point = VAbstractTool::data.GeometricObject(id); - QDomElement domElement = doc->elementById(QString().setNum(id)); - if (domElement.isElement()) - { - doc->SetAttribute(domElement, AttrName, point->name()); - doc->SetAttribute(domElement, AttrMx, qApp->fromPixel(point->mx())); - doc->SetAttribute(domElement, AttrMy, qApp->fromPixel(point->my())); - doc->SetAttribute(domElement, AttrRadius, arcRadius); - doc->SetAttribute(domElement, AttrCenter, center); - doc->SetAttribute(domElement, AttrFirstPoint, firstPointId); - doc->SetAttribute(domElement, AttrSecondPoint, secondPointId); - } -} - //--------------------------------------------------------------------------------------------------------------------- /** * @brief RemoveReferens decrement value of reference. @@ -329,3 +298,121 @@ void VToolPointOfContact::SaveDialog(QDomElement &domElement) doc->SetAttribute(domElement, AttrFirstPoint, QString().setNum(dialogTool->getFirstPoint())); doc->SetAttribute(domElement, AttrSecondPoint, QString().setNum(dialogTool->getSecondPoint())); } + +//--------------------------------------------------------------------------------------------------------------------- +void VToolPointOfContact::SaveOptions(QDomElement &tag, QSharedPointer &obj) +{ + QSharedPointer point = qSharedPointerDynamicCast(obj); + SCASSERT(point.isNull() == false); + + doc->SetAttribute(tag, VDomDocument::AttrId, id); + doc->SetAttribute(tag, AttrType, ToolType); + doc->SetAttribute(tag, AttrName, point->name()); + doc->SetAttribute(tag, AttrMx, qApp->fromPixel(point->mx())); + doc->SetAttribute(tag, AttrMy, qApp->fromPixel(point->my())); + + doc->SetAttribute(tag, AttrRadius, arcRadius); + doc->SetAttribute(tag, AttrCenter, center); + doc->SetAttribute(tag, AttrFirstPoint, firstPointId); + doc->SetAttribute(tag, AttrSecondPoint, secondPointId); +} + +//--------------------------------------------------------------------------------------------------------------------- +quint32 VToolPointOfContact::getSecondPointId() const +{ + return secondPointId; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolPointOfContact::setSecondPointId(const quint32 &value) +{ + secondPointId = value; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolPointOfContact::ShowVisualization(bool show) +{ + if (show) + { + if (vis == nullptr) + { + VisToolPointOfContact * visual = new VisToolPointOfContact(getData()); + VMainGraphicsScene *scene = qApp->getCurrentScene(); + connect(scene, &VMainGraphicsScene::NewFactor, visual, &Visualization::SetFactor); + scene->addItem(visual); + + visual->setPoint1Id(firstPointId); + visual->setLineP2Id(secondPointId); + visual->setRadiusId(center); + visual->setRadius(arcRadius); + visual->RefreshGeometry(); + vis = visual; + } + else + { + VisToolPointOfContact *visual = qobject_cast(vis); + if (visual != nullptr) + { + visual->show(); + } + } + } + else + { + delete vis; + vis = nullptr; + } +} + +//--------------------------------------------------------------------------------------------------------------------- +quint32 VToolPointOfContact::getFirstPointId() const +{ + return firstPointId; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolPointOfContact::setFirstPointId(const quint32 &value) +{ + firstPointId = value; +} + +//--------------------------------------------------------------------------------------------------------------------- +quint32 VToolPointOfContact::getCenter() const +{ + return center; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolPointOfContact::setCenter(const quint32 &value) +{ + if (value != NULL_ID) + { + center = value; + + QSharedPointer obj = VAbstractTool::data.GetGObject(id); + SaveOption(obj); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +VFormula VToolPointOfContact::getArcRadius() const +{ + VFormula radius(arcRadius, this->getData()); + radius.setCheckZero(true); + radius.setToolId(id); + radius.setPostfix(VDomDocument::UnitsToStr(qApp->patternUnit())); + + return radius; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolPointOfContact::setArcRadius(const VFormula &value) +{ + if (value.error() == false) + { + arcRadius = value.getFormula(FormulaType::FromUser); + + QSharedPointer obj = VAbstractTool::data.GetGObject(id); + SaveOption(obj); + } +} diff --git a/src/app/tools/drawTools/vtoolpointofcontact.h b/src/app/tools/drawTools/vtoolpointofcontact.h index 942378c17..1cbc84815 100644 --- a/src/app/tools/drawTools/vtoolpointofcontact.h +++ b/src/app/tools/drawTools/vtoolpointofcontact.h @@ -31,6 +31,8 @@ #include "vtoolpoint.h" +class VFormula; + /** * @brief The VToolPointOfContact class tool for creation point intersection line and arc. */ @@ -51,28 +53,43 @@ public: const qreal &mx, const qreal &my, VMainGraphicsScene *scene, VPattern *doc, VContainer *data, const Document &parse, const Source &typeCreation); static const QString ToolType; + virtual int type() const {return Type;} + enum { Type = UserType + static_cast(Tool::PointOfContact) }; + + VFormula getArcRadius() const; + void setArcRadius(const VFormula &value); + + quint32 getCenter() const; + void setCenter(const quint32 &value); + + quint32 getFirstPointId() const; + void setFirstPointId(const quint32 &value); + + quint32 getSecondPointId() const; + void setSecondPointId(const quint32 &value); + + virtual void ShowVisualization(bool show); public slots: virtual void FullUpdateFromFile(); virtual void SetFactor(qreal factor); virtual void ShowContextMenu(QGraphicsSceneContextMenuEvent *event); protected: virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ); - virtual void AddToFile(); - virtual void RefreshDataInFile(); virtual void RemoveReferens(); virtual void SaveDialog(QDomElement &domElement); + virtual void SaveOptions(QDomElement &tag, QSharedPointer &obj); private: /** @brief radius string with formula radius arc. */ QString arcRadius; /** @brief center id center arc point. */ - quint32 center; + quint32 center; /** @brief firstPointId id first line point. */ - quint32 firstPointId; + quint32 firstPointId; /** @brief secondPointId id second line point. */ - quint32 secondPointId; + quint32 secondPointId; }; #endif // VTOOLPOINTOFCONTACT_H diff --git a/src/app/tools/drawTools/vtoolpointofintersection.cpp b/src/app/tools/drawTools/vtoolpointofintersection.cpp index 10790a8b4..52ef71132 100644 --- a/src/app/tools/drawTools/vtoolpointofintersection.cpp +++ b/src/app/tools/drawTools/vtoolpointofintersection.cpp @@ -29,6 +29,7 @@ #include "vtoolpointofintersection.h" #include "../../dialogs/tools/dialogpointofintersection.h" #include "../../geometry/vpointf.h" +#include "../../visualization/vistoolpointofintersection.h" const QString VToolPointOfIntersection::ToolType = QStringLiteral("pointOfIntersection"); @@ -171,6 +172,14 @@ void VToolPointOfIntersection::FullUpdateFromFile() secondPointId = domElement.attribute(AttrSecondPoint, "").toUInt(); } VToolPoint::RefreshPointGeometry(*VDrawTool::data.GeometricObject(id)); + + if (vis != nullptr) + { + VisToolPointOfIntersection *visual = qobject_cast(vis); + visual->setPoint1Id(firstPointId); + visual->setPoint2Id(secondPointId); + visual->RefreshGeometry(); + } } //--------------------------------------------------------------------------------------------------------------------- @@ -203,45 +212,6 @@ void VToolPointOfIntersection::contextMenuEvent(QGraphicsSceneContextMenuEvent * ContextMenu(this, event); } -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief AddToFile add tag with informations about tool into file. - */ -void VToolPointOfIntersection::AddToFile() -{ - const QSharedPointer point = VAbstractTool::data.GeometricObject(id); - QDomElement domElement = doc->createElement(TagName); - - doc->SetAttribute(domElement, VDomDocument::AttrId, id); - doc->SetAttribute(domElement, AttrType, ToolType); - doc->SetAttribute(domElement, AttrName, point->name()); - doc->SetAttribute(domElement, AttrMx, qApp->fromPixel(point->mx())); - doc->SetAttribute(domElement, AttrMy, qApp->fromPixel(point->my())); - - doc->SetAttribute(domElement, AttrFirstPoint, firstPointId); - doc->SetAttribute(domElement, AttrSecondPoint, secondPointId); - - AddToCalculation(domElement); -} - -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief RefreshDataInFile refresh attributes in file. If attributes don't exist create them. - */ -void VToolPointOfIntersection::RefreshDataInFile() -{ - const QSharedPointer point = VAbstractTool::data.GeometricObject(id); - QDomElement domElement = doc->elementById(QString().setNum(id)); - if (domElement.isElement()) - { - doc->SetAttribute(domElement, AttrName, point->name()); - doc->SetAttribute(domElement, AttrMx, qApp->fromPixel(point->mx())); - doc->SetAttribute(domElement, AttrMy, qApp->fromPixel(point->my())); - doc->SetAttribute(domElement, AttrFirstPoint, firstPointId); - doc->SetAttribute(domElement, AttrSecondPoint, secondPointId); - } -} - //--------------------------------------------------------------------------------------------------------------------- /** * @brief SaveDialog save options into file after change in dialog. @@ -255,3 +225,88 @@ void VToolPointOfIntersection::SaveDialog(QDomElement &domElement) doc->SetAttribute(domElement, AttrFirstPoint, QString().setNum(dialogTool->getFirstPointId())); doc->SetAttribute(domElement, AttrSecondPoint, QString().setNum(dialogTool->getSecondPointId())); } + +//--------------------------------------------------------------------------------------------------------------------- +void VToolPointOfIntersection::SaveOptions(QDomElement &tag, QSharedPointer &obj) +{ + QSharedPointer point = qSharedPointerDynamicCast(obj); + SCASSERT(point.isNull() == false); + + doc->SetAttribute(tag, VDomDocument::AttrId, id); + doc->SetAttribute(tag, AttrType, ToolType); + doc->SetAttribute(tag, AttrName, point->name()); + doc->SetAttribute(tag, AttrMx, qApp->fromPixel(point->mx())); + doc->SetAttribute(tag, AttrMy, qApp->fromPixel(point->my())); + + doc->SetAttribute(tag, AttrFirstPoint, firstPointId); + doc->SetAttribute(tag, AttrSecondPoint, secondPointId); +} + +//--------------------------------------------------------------------------------------------------------------------- +quint32 VToolPointOfIntersection::getSecondPointId() const +{ + return secondPointId; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolPointOfIntersection::setSecondPointId(const quint32 &value) +{ + if (value != NULL_ID) + { + secondPointId = value; + + QSharedPointer obj = VAbstractTool::data.GetGObject(id); + SaveOption(obj); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolPointOfIntersection::ShowVisualization(bool show) +{ + if (show) + { + if (vis == nullptr) + { + VisToolPointOfIntersection * visual = new VisToolPointOfIntersection(getData()); + VMainGraphicsScene *scene = qApp->getCurrentScene(); + connect(scene, &VMainGraphicsScene::NewFactor, visual, &Visualization::SetFactor); + scene->addItem(visual); + + visual->setPoint1Id(firstPointId); + visual->setPoint2Id(secondPointId); + visual->RefreshGeometry(); + vis = visual; + } + else + { + VisToolPointOfIntersection *visual = qobject_cast(vis); + if (visual != nullptr) + { + visual->show(); + } + } + } + else + { + delete vis; + vis = nullptr; + } +} + +//--------------------------------------------------------------------------------------------------------------------- +quint32 VToolPointOfIntersection::getFirstPointId() const +{ + return firstPointId; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolPointOfIntersection::setFirstPointId(const quint32 &value) +{ + if (value != NULL_ID) + { + firstPointId = value; + + QSharedPointer obj = VAbstractTool::data.GetGObject(id); + SaveOption(obj); + } +} diff --git a/src/app/tools/drawTools/vtoolpointofintersection.h b/src/app/tools/drawTools/vtoolpointofintersection.h index ef8518dce..80e2980de 100644 --- a/src/app/tools/drawTools/vtoolpointofintersection.h +++ b/src/app/tools/drawTools/vtoolpointofintersection.h @@ -49,15 +49,24 @@ public: VMainGraphicsScene *scene, VPattern *doc, VContainer *data, const Document &parse, const Source &typeCreation); static const QString ToolType; + virtual int type() const {return Type;} + enum { Type = UserType + static_cast(Tool::PointOfIntersection) }; + + quint32 getFirstPointId() const; + void setFirstPointId(const quint32 &value); + + quint32 getSecondPointId() const; + void setSecondPointId(const quint32 &value); + + virtual void ShowVisualization(bool show); public slots: virtual void FullUpdateFromFile(); virtual void ShowContextMenu(QGraphicsSceneContextMenuEvent *event); protected: virtual void RemoveReferens(); virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ); - virtual void AddToFile(); - virtual void RefreshDataInFile(); virtual void SaveDialog(QDomElement &domElement); + virtual void SaveOptions(QDomElement &tag, QSharedPointer &obj); private: Q_DISABLE_COPY(VToolPointOfIntersection) /** @brief firstPointId id first line point. */ diff --git a/src/app/tools/drawTools/vtoolshoulderpoint.cpp b/src/app/tools/drawTools/vtoolshoulderpoint.cpp index da67ecb83..679fa0929 100644 --- a/src/app/tools/drawTools/vtoolshoulderpoint.cpp +++ b/src/app/tools/drawTools/vtoolshoulderpoint.cpp @@ -30,6 +30,7 @@ #include "../../container/calculator.h" #include "../../dialogs/tools/dialogshoulderpoint.h" #include "../../geometry/vpointf.h" +#include "../../visualization/vistoolshoulderpoint.h" const QString VToolShoulderPoint::ToolType = QStringLiteral("shoulder"); @@ -199,7 +200,7 @@ VToolShoulderPoint* VToolShoulderPoint::Create(const quint32 _id, QString &formu doc->UpdateToolData(id, data); } } - VDrawTool::AddRecord(id, Tool::ShoulderPointTool, doc); + VDrawTool::AddRecord(id, Tool::ShoulderPoint, doc); if (parse == Document::FullParse) { VToolShoulderPoint *point = new VToolShoulderPoint(doc, data, id, typeLine, formula, @@ -234,6 +235,17 @@ void VToolShoulderPoint::FullUpdateFromFile() pShoulder = domElement.attribute(AttrPShoulder, "").toUInt(); } RefreshGeometry(); + + if (vis != nullptr) + { + VisToolShoulderPoint *visual = qobject_cast(vis); + visual->setPoint1Id(pShoulder); + visual->setLineP1Id(basePointId); + visual->setLineP2Id(p2Line); + visual->setLength(formulaLength); + visual->setLineStyle(VAbstractTool::LineStyle(typeLine)); + visual->RefreshGeometry(); + } } //--------------------------------------------------------------------------------------------------------------------- @@ -267,51 +279,6 @@ void VToolShoulderPoint::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) ContextMenu(this, event); } -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief AddToFile add tag with informations about tool into file. - */ -void VToolShoulderPoint::AddToFile() -{ - const QSharedPointer point = VAbstractTool::data.GeometricObject(id); - QDomElement domElement = doc->createElement(TagName); - - doc->SetAttribute(domElement, VDomDocument::AttrId, id); - doc->SetAttribute(domElement, AttrType, ToolType); - doc->SetAttribute(domElement, AttrName, point->name()); - doc->SetAttribute(domElement, AttrMx, qApp->fromPixel(point->mx())); - doc->SetAttribute(domElement, AttrMy, qApp->fromPixel(point->my())); - - doc->SetAttribute(domElement, AttrTypeLine, typeLine); - doc->SetAttribute(domElement, AttrLength, formulaLength); - doc->SetAttribute(domElement, AttrP1Line, basePointId); - doc->SetAttribute(domElement, AttrP2Line, p2Line); - doc->SetAttribute(domElement, AttrPShoulder, pShoulder); - - AddToCalculation(domElement); -} - -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief RefreshDataInFile refresh attributes in file. If attributes don't exist create them. - */ -void VToolShoulderPoint::RefreshDataInFile() -{ - const QSharedPointer point = VAbstractTool::data.GeometricObject(id); - QDomElement domElement = doc->elementById(QString().setNum(id)); - if (domElement.isElement()) - { - doc->SetAttribute(domElement, AttrName, point->name()); - doc->SetAttribute(domElement, AttrName, qApp->fromPixel(point->mx())); - doc->SetAttribute(domElement, AttrName, qApp->fromPixel(point->my())); - doc->SetAttribute(domElement, AttrTypeLine, typeLine); - doc->SetAttribute(domElement, AttrLength, formulaLength); - doc->SetAttribute(domElement, AttrP1Line, basePointId); - doc->SetAttribute(domElement, AttrP2Line, p2Line); - doc->SetAttribute(domElement, AttrPShoulder, pShoulder); - } -} - //--------------------------------------------------------------------------------------------------------------------- /** * @brief RemoveReferens decrement value of reference. @@ -339,3 +306,95 @@ void VToolShoulderPoint::SaveDialog(QDomElement &domElement) doc->SetAttribute(domElement, AttrP2Line, QString().setNum(dialogTool->getP2Line())); doc->SetAttribute(domElement, AttrPShoulder, QString().setNum(dialogTool->getPShoulder())); } + +//--------------------------------------------------------------------------------------------------------------------- +void VToolShoulderPoint::SaveOptions(QDomElement &tag, QSharedPointer &obj) +{ + QSharedPointer point = qSharedPointerDynamicCast(obj); + SCASSERT(point.isNull() == false); + + doc->SetAttribute(tag, VDomDocument::AttrId, id); + doc->SetAttribute(tag, AttrType, ToolType); + doc->SetAttribute(tag, AttrName, point->name()); + doc->SetAttribute(tag, AttrMx, qApp->fromPixel(point->mx())); + doc->SetAttribute(tag, AttrMy, qApp->fromPixel(point->my())); + + doc->SetAttribute(tag, AttrTypeLine, typeLine); + doc->SetAttribute(tag, AttrLength, formulaLength); + doc->SetAttribute(tag, AttrP1Line, basePointId); + doc->SetAttribute(tag, AttrP2Line, p2Line); + doc->SetAttribute(tag, AttrPShoulder, pShoulder); +} + +//--------------------------------------------------------------------------------------------------------------------- +quint32 VToolShoulderPoint::getPShoulder() const +{ + return pShoulder; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolShoulderPoint::setPShoulder(const quint32 &value) +{ + if (value != NULL_ID) + { + pShoulder = value; + + QSharedPointer obj = VAbstractTool::data.GetGObject(id); + SaveOption(obj); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolShoulderPoint::ShowVisualization(bool show) +{ + if (show) + { + if (vis == nullptr) + { + VisToolShoulderPoint * visual = new VisToolShoulderPoint(getData()); + VMainGraphicsScene *scene = qApp->getCurrentScene(); + connect(scene, &VMainGraphicsScene::NewFactor, visual, &Visualization::SetFactor); + scene->addItem(visual); + + visual->setPoint1Id(pShoulder); + visual->setLineP1Id(basePointId); + visual->setLineP2Id(p2Line); + visual->setLength(formulaLength); + visual->setLineStyle(VAbstractTool::LineStyle(typeLine)); + visual->RefreshGeometry(); + vis = visual; + } + else + { + VisToolShoulderPoint *visual = qobject_cast(vis); + if (visual != nullptr) + { + visual->show(); + } + } + } + else + { + delete vis; + vis = nullptr; + } +} + +//--------------------------------------------------------------------------------------------------------------------- +quint32 VToolShoulderPoint::getP2Line() const +{ + return p2Line; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolShoulderPoint::setP2Line(const quint32 &value) +{ + if (value != NULL_ID) + { + p2Line = value; + + QSharedPointer obj = VAbstractTool::data.GetGObject(id); + SaveOption(obj); + } +} + diff --git a/src/app/tools/drawTools/vtoolshoulderpoint.h b/src/app/tools/drawTools/vtoolshoulderpoint.h index c6acd946e..ef8c08df6 100644 --- a/src/app/tools/drawTools/vtoolshoulderpoint.h +++ b/src/app/tools/drawTools/vtoolshoulderpoint.h @@ -51,16 +51,25 @@ public: const qreal &mx, const qreal &my, VMainGraphicsScene *scene, VPattern *doc, VContainer *data, const Document &parse, const Source &typeCreation); static const QString ToolType; + virtual int type() const {return Type;} + enum { Type = UserType + static_cast(Tool::ShoulderPoint) }; + + quint32 getP2Line() const; + void setP2Line(const quint32 &value); + + quint32 getPShoulder() const; + void setPShoulder(const quint32 &value); + + virtual void ShowVisualization(bool show); public slots: virtual void FullUpdateFromFile(); virtual void SetFactor(qreal factor); virtual void ShowContextMenu(QGraphicsSceneContextMenuEvent *event); protected: virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ); - virtual void AddToFile(); - virtual void RefreshDataInFile(); virtual void RemoveReferens(); virtual void SaveDialog(QDomElement &domElement); + virtual void SaveOptions(QDomElement &tag, QSharedPointer &obj); private: /** @brief p2Line id second line point. */ quint32 p2Line; diff --git a/src/app/tools/drawTools/vtoolsinglepoint.cpp b/src/app/tools/drawTools/vtoolsinglepoint.cpp index 408af790e..45bd66058 100644 --- a/src/app/tools/drawTools/vtoolsinglepoint.cpp +++ b/src/app/tools/drawTools/vtoolsinglepoint.cpp @@ -82,6 +82,12 @@ void VToolSinglePoint::setDialog() dialogTool->setData(p->name(), p->toQPointF()); } +//--------------------------------------------------------------------------------------------------------------------- +void VToolSinglePoint::ShowVisualization(bool show) +{ + Q_UNUSED(show); //don't have any visualization for base point yet +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief AddToFile add tag with informations about tool into file. @@ -90,17 +96,11 @@ void VToolSinglePoint::AddToFile() { Q_ASSERT_X(namePP.isEmpty() == false, "AddToFile", "name pattern piece is empty"); - const QSharedPointer point = VAbstractTool::data.GeometricObject(id); QDomElement sPoint = doc->createElement(TagName); // Create SPoint tag - doc->SetAttribute(sPoint, VDomDocument::AttrId, id); - doc->SetAttribute(sPoint, AttrType, ToolType); - doc->SetAttribute(sPoint, AttrName, point->name()); - doc->SetAttribute(sPoint, AttrX, qApp->fromPixel(point->x())); - doc->SetAttribute(sPoint, AttrY, qApp->fromPixel(point->y())); - doc->SetAttribute(sPoint, AttrMx, qApp->fromPixel(point->mx())); - doc->SetAttribute(sPoint, AttrMy, qApp->fromPixel(point->my())); + QSharedPointer obj = VAbstractTool::data.GetGObject(id); + SaveOptions(sPoint, obj); //Create pattern piece structure QDomElement patternPiece = doc->createElement(VPattern::TagDraw); @@ -119,24 +119,6 @@ void VToolSinglePoint::AddToFile() qApp->getUndoStack()->push(addPP); } -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief RefreshDataInFile refresh attributes in file. If attributes don't exist create them. - */ -void VToolSinglePoint::RefreshDataInFile() -{ - const QSharedPointer point = VAbstractTool::data.GeometricObject(id); - QDomElement domElement = doc->elementById(QString().setNum(id)); - if (domElement.isElement()) - { - doc->SetAttribute(domElement, AttrName, point->name()); - doc->SetAttribute(domElement, AttrX, QString().setNum(qApp->fromPixel(point->x()))); - doc->SetAttribute(domElement, AttrY, QString().setNum(qApp->fromPixel(point->y()))); - doc->SetAttribute(domElement, AttrMx, QString().setNum(qApp->fromPixel(point->mx()))); - doc->SetAttribute(domElement, AttrMy, QString().setNum(qApp->fromPixel(point->my()))); - } -} - //--------------------------------------------------------------------------------------------------------------------- /** * @brief itemChange handle tool change. @@ -240,7 +222,7 @@ void VToolSinglePoint::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) //--------------------------------------------------------------------------------------------------------------------- void VToolSinglePoint::mousePressEvent(QGraphicsSceneMouseEvent *event) { - if (event->button() == Qt::LeftButton) + if (event->button() == Qt::LeftButton && event->type() != QEvent::GraphicsSceneMouseDoubleClick) { #ifndef QT_NO_CURSOR QPixmap pixmap(QLatin1String("://cursor/cursor-arrow-closehand.png")); @@ -253,7 +235,7 @@ void VToolSinglePoint::mousePressEvent(QGraphicsSceneMouseEvent *event) //--------------------------------------------------------------------------------------------------------------------- void VToolSinglePoint::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) { - if (event->button() == Qt::LeftButton) + if (event->button() == Qt::LeftButton && event->type() != QEvent::GraphicsSceneMouseDoubleClick) { //Disable cursor-arrow-closehand #ifndef QT_NO_CURSOR @@ -274,6 +256,21 @@ void VToolSinglePoint::setColorLabel(const Qt::GlobalColor &color) lineName->setPen(QPen(color, qApp->toPixel(qApp->widthHairLine())/factor)); } +//--------------------------------------------------------------------------------------------------------------------- +void VToolSinglePoint::SaveOptions(QDomElement &tag, QSharedPointer &obj) +{ + QSharedPointer point = qSharedPointerDynamicCast(obj); + SCASSERT(point.isNull() == false); + + doc->SetAttribute(tag, VDomDocument::AttrId, id); + doc->SetAttribute(tag, AttrType, ToolType); + doc->SetAttribute(tag, AttrName, point->name()); + doc->SetAttribute(tag, AttrX, qApp->fromPixel(point->x())); + doc->SetAttribute(tag, AttrY, qApp->fromPixel(point->y())); + doc->SetAttribute(tag, AttrMx, qApp->fromPixel(point->mx())); + doc->SetAttribute(tag, AttrMy, qApp->fromPixel(point->my())); +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief contextMenuEvent handle context menu events. diff --git a/src/app/tools/drawTools/vtoolsinglepoint.h b/src/app/tools/drawTools/vtoolsinglepoint.h index c3b34f9d5..2e9aa14f1 100644 --- a/src/app/tools/drawTools/vtoolsinglepoint.h +++ b/src/app/tools/drawTools/vtoolsinglepoint.h @@ -43,6 +43,9 @@ public: const QString &namePP, const QString &mPath, QGraphicsItem * parent = nullptr ); virtual void setDialog(); static const QString ToolType; + virtual int type() const {return Type;} + enum { Type = UserType + static_cast(Tool::SinglePoint)}; + virtual void ShowVisualization(bool show); public slots: virtual void FullUpdateFromFile(); virtual void ChangedActivDraw(const QString &newName); @@ -56,7 +59,6 @@ signals: protected: virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ); virtual void AddToFile(); - virtual void RefreshDataInFile(); QVariant itemChange ( GraphicsItemChange change, const QVariant &value ); virtual void decrementReferens(); virtual void DeleteTool(bool ask = true); @@ -65,10 +67,12 @@ protected: virtual void hoverLeaveEvent ( QGraphicsSceneHoverEvent * event ); virtual void mousePressEvent( QGraphicsSceneMouseEvent * event ); virtual void mouseReleaseEvent ( QGraphicsSceneMouseEvent * event ); + virtual void SaveOptions(QDomElement &tag, QSharedPointer &obj); private: QString namePP; QString mPath; void setColorLabel(const Qt::GlobalColor & color); + }; #endif // VTOOLSINGLEPOINT_H diff --git a/src/app/tools/drawTools/vtoolspline.cpp b/src/app/tools/drawTools/vtoolspline.cpp index 47e71f20d..983f37bb0 100644 --- a/src/app/tools/drawTools/vtoolspline.cpp +++ b/src/app/tools/drawTools/vtoolspline.cpp @@ -30,6 +30,7 @@ #include "../../geometry/vspline.h" #include "../../dialogs/tools/dialogspline.h" #include "../../undocommands/movespline.h" +#include "../../visualization/vistoolspline.h" const QString VToolSpline::ToolType = QStringLiteral("simple"); @@ -71,6 +72,8 @@ VToolSpline::VToolSpline(VPattern *doc, VContainer *data, quint32 id, const Sour connect(this, &VToolSpline::setEnabledPoint, controlPoint2, &VControlPointSpline::setEnabledPoint); controlPoints.append(controlPoint2); + ShowFoot(false); + if (typeCreation == Source::FromGui) { AddToFile(); @@ -172,7 +175,7 @@ VToolSpline* VToolSpline::Create(const quint32 _id, const quint32 &p1, const qui doc->UpdateToolData(id, data); } } - VDrawTool::AddRecord(id, Tool::SplineTool, doc); + VDrawTool::AddRecord(id, Tool::Spline, doc); if (parse == Document::FullParse) { VToolSpline *spl = new VToolSpline(doc, data, id, typeCreation); @@ -188,6 +191,62 @@ VToolSpline* VToolSpline::Create(const quint32 _id, const quint32 &p1, const qui return nullptr; } +//--------------------------------------------------------------------------------------------------------------------- +VSpline VToolSpline::getSpline() const +{ + QSharedPointer spline = VAbstractTool::data.GeometricObject(id); + return *spline.data(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolSpline::setSpline(const VSpline &spl) +{ + QSharedPointer obj = VAbstractTool::data.GetGObject(id); + QSharedPointer spline = qSharedPointerDynamicCast(obj); + *spline.data() = spl; + SaveOption(obj); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolSpline::ShowVisualization(bool show) +{ + if (show) + { + if (vis == nullptr) + { + VisToolSpline *visual = new VisToolSpline(getData()); + VMainGraphicsScene *scene = qApp->getCurrentScene(); + connect(scene, &VMainGraphicsScene::NewFactor, visual, &Visualization::SetFactor); + scene->addItem(visual); + + const QSharedPointer spl = VAbstractTool::data.GeometricObject(id); + visual->setPoint1Id(spl->GetP1().id()); + visual->setPoint4Id(spl->GetP4().id()); + visual->setAngle1(spl->GetAngle1()); + visual->setAngle2(spl->GetAngle2()); + visual->setKAsm1(spl->GetKasm1()); + visual->setKAsm2(spl->GetKasm2()); + visual->setKCurve(spl->GetKcurve()); + visual->RefreshGeometry(); + vis = visual; + } + else + { + VisToolSpline *visual = qobject_cast(vis); + if (visual != nullptr) + { + visual->show(); + } + } + } + else + { + delete vis; + vis = nullptr; + } + ShowFoot(show); +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief ControlPointChangePosition handle change position control point. @@ -225,48 +284,6 @@ void VToolSpline::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) ContextMenu(this, event); } -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief AddToFile add tag with informations about tool into file. - */ -void VToolSpline::AddToFile() -{ - const QSharedPointer spl = VAbstractTool::data.GeometricObject(id); - QDomElement domElement = doc->createElement(TagName); - - doc->SetAttribute(domElement, VDomDocument::AttrId, id); - doc->SetAttribute(domElement, AttrType, ToolType); - doc->SetAttribute(domElement, AttrPoint1, spl->GetP1().id()); - doc->SetAttribute(domElement, AttrPoint4, spl->GetP4().id()); - doc->SetAttribute(domElement, AttrAngle1, spl->GetAngle1()); - doc->SetAttribute(domElement, AttrAngle2, spl->GetAngle2()); - doc->SetAttribute(domElement, AttrKAsm1, spl->GetKasm1()); - doc->SetAttribute(domElement, AttrKAsm2, spl->GetKasm2()); - doc->SetAttribute(domElement, AttrKCurve, spl->GetKcurve()); - - AddToCalculation(domElement); -} - -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief RefreshDataInFile refresh attributes in file. If attributes don't exist create them. - */ -void VToolSpline::RefreshDataInFile() -{ - const QSharedPointer spl = VAbstractTool::data.GeometricObject(id); - QDomElement domElement = doc->elementById(QString().setNum(id)); - if (domElement.isElement()) - { - doc->SetAttribute(domElement, AttrPoint1, spl->GetP1().id()); - doc->SetAttribute(domElement, AttrPoint4, spl->GetP4().id()); - doc->SetAttribute(domElement, AttrAngle1, spl->GetAngle1()); - doc->SetAttribute(domElement, AttrAngle2, spl->GetAngle2()); - doc->SetAttribute(domElement, AttrKAsm1, spl->GetKasm1()); - doc->SetAttribute(domElement, AttrKAsm2, spl->GetKasm2()); - doc->SetAttribute(domElement, AttrKCurve, spl->GetKcurve()); - } -} - //--------------------------------------------------------------------------------------------------------------------- /** * @brief RemoveReferens decrement value of reference. @@ -313,6 +330,23 @@ void VToolSpline::SaveDialog(QDomElement &domElement) doc->SetAttribute(domElement, AttrKCurve, spl.GetKcurve()); } +//--------------------------------------------------------------------------------------------------------------------- +void VToolSpline::SaveOptions(QDomElement &tag, QSharedPointer &obj) +{ + QSharedPointer spl = qSharedPointerDynamicCast(obj); + SCASSERT(spl.isNull() == false); + + doc->SetAttribute(tag, VDomDocument::AttrId, id); + doc->SetAttribute(tag, AttrType, ToolType); + doc->SetAttribute(tag, AttrPoint1, spl->GetP1().id()); + doc->SetAttribute(tag, AttrPoint4, spl->GetP4().id()); + doc->SetAttribute(tag, AttrAngle1, spl->GetAngle1()); + doc->SetAttribute(tag, AttrAngle2, spl->GetAngle2()); + doc->SetAttribute(tag, AttrKAsm1, spl->GetKasm1()); + doc->SetAttribute(tag, AttrKAsm2, spl->GetKasm2()); + doc->SetAttribute(tag, AttrKCurve, spl->GetKcurve()); +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief RefreshGeometry refresh item on scene. @@ -345,4 +379,17 @@ void VToolSpline::RefreshGeometry() controlPoints[0]->blockSignals(false); controlPoints[1]->blockSignals(false); + + if (vis != nullptr) + { + VisToolSpline *visual = qobject_cast(vis); + visual->setPoint1Id(spl->GetP1().id()); + visual->setPoint4Id(spl->GetP4().id()); + visual->setAngle1(spl->GetAngle1()); + visual->setAngle2(spl->GetAngle2()); + visual->setKAsm1(spl->GetKasm1()); + visual->setKAsm2(spl->GetKasm2()); + visual->setKCurve(spl->GetKcurve()); + visual->RefreshGeometry(); + } } diff --git a/src/app/tools/drawTools/vtoolspline.h b/src/app/tools/drawTools/vtoolspline.h index 153d4f917..a0c8faa33 100644 --- a/src/app/tools/drawTools/vtoolspline.h +++ b/src/app/tools/drawTools/vtoolspline.h @@ -48,15 +48,21 @@ public: VMainGraphicsScene *scene, VPattern *doc, VContainer *data, const Document &parse, const Source &typeCreation); static const QString ToolType; + virtual int type() const {return Type;} + enum { Type = UserType + static_cast(Tool::Spline)}; + + VSpline getSpline()const; + void setSpline(const VSpline &spl); + + virtual void ShowVisualization(bool show); public slots: void ControlPointChangePosition (const qint32 &indexSpline, const SplinePointPosition &position, const QPointF &pos); protected: virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ); - virtual void AddToFile (); - virtual void RefreshDataInFile(); virtual void RemoveReferens(); virtual void SaveDialog(QDomElement &domElement); + virtual void SaveOptions(QDomElement &tag, QSharedPointer &obj); private: void RefreshGeometry (); }; diff --git a/src/app/tools/drawTools/vtoolsplinepath.cpp b/src/app/tools/drawTools/vtoolsplinepath.cpp index d66847b4e..6b00f1c27 100644 --- a/src/app/tools/drawTools/vtoolsplinepath.cpp +++ b/src/app/tools/drawTools/vtoolsplinepath.cpp @@ -29,6 +29,7 @@ #include "vtoolsplinepath.h" #include "../../dialogs/tools/dialogsplinepath.h" #include "../../undocommands/movesplinepath.h" +#include "../../visualization/vistoolsplinepath.h" const QString VToolSplinePath::ToolType = QStringLiteral("path"); @@ -73,6 +74,9 @@ VToolSplinePath::VToolSplinePath(VPattern *doc, VContainer *data, quint32 id, co connect(this, &VToolSplinePath::setEnabledPoint, controlPoint, &VControlPointSpline::setEnabledPoint); controlPoints.append(controlPoint); } + + ShowFoot(false); + if (typeCreation == Source::FromGui) { AddToFile(); @@ -104,7 +108,7 @@ void VToolSplinePath::setDialog() * @param doc dom document container. * @param data container with variables. */ -void VToolSplinePath::Create(DialogTool *dialog, VMainGraphicsScene *scene, VPattern *doc, VContainer *data) +VToolSplinePath* VToolSplinePath::Create(DialogTool *dialog, VMainGraphicsScene *scene, VPattern *doc, VContainer *data) { SCASSERT(dialog != nullptr); DialogSplinePath *dialogTool = qobject_cast(dialog); @@ -114,7 +118,13 @@ void VToolSplinePath::Create(DialogTool *dialog, VMainGraphicsScene *scene, VPat { doc->IncrementReferens((*path)[i].P().id()); } - Create(0, path, scene, doc, data, Document::FullParse, Source::FromGui); + VToolSplinePath* spl = nullptr; + spl = Create(0, path, scene, doc, data, Document::FullParse, Source::FromGui); + if (spl != nullptr) + { + spl->dialog=dialogTool; + } + return spl; } //--------------------------------------------------------------------------------------------------------------------- @@ -128,7 +138,7 @@ void VToolSplinePath::Create(DialogTool *dialog, VMainGraphicsScene *scene, VPat * @param parse parser file mode. * @param typeCreation way we create this tool. */ -void VToolSplinePath::Create(const quint32 _id, VSplinePath *path, VMainGraphicsScene *scene, VPattern *doc, +VToolSplinePath* VToolSplinePath::Create(const quint32 _id, VSplinePath *path, VMainGraphicsScene *scene, VPattern *doc, VContainer *data, const Document &parse, const Source &typeCreation) { quint32 id = _id; @@ -146,7 +156,7 @@ void VToolSplinePath::Create(const quint32 _id, VSplinePath *path, VMainGraphics doc->UpdateToolData(id, data); } } - VDrawTool::AddRecord(id, Tool::SplinePathTool, doc); + VDrawTool::AddRecord(id, Tool::SplinePath, doc); if (parse == Document::FullParse) { VToolSplinePath *spl = new VToolSplinePath(doc, data, id, typeCreation); @@ -155,7 +165,9 @@ void VToolSplinePath::Create(const quint32 _id, VSplinePath *path, VMainGraphics connect(scene, &VMainGraphicsScene::NewFactor, spl, &VToolSplinePath::SetFactor); connect(scene, &VMainGraphicsScene::DisableItem, spl, &VToolSplinePath::Disable); doc->AddTool(id, spl); + return spl; } + return nullptr; } //--------------------------------------------------------------------------------------------------------------------- @@ -256,6 +268,57 @@ void VToolSplinePath::UpdatePathPoint(VPattern *doc, QDomNode& node, const VSpli } } +//--------------------------------------------------------------------------------------------------------------------- +VSplinePath VToolSplinePath::getSplinePath() const +{ + QSharedPointer splPath = VAbstractTool::data.GeometricObject(id); + return *splPath.data(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolSplinePath::setSplinePath(const VSplinePath &splPath) +{ + QSharedPointer obj = VAbstractTool::data.GetGObject(id); + QSharedPointer splinePath = qSharedPointerDynamicCast(obj); + *splinePath.data() = splPath; + SaveOption(obj); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolSplinePath::ShowVisualization(bool show) +{ + if (show) + { + if (vis == nullptr) + { + VisToolSplinePath *visual = new VisToolSplinePath(getData()); + VMainGraphicsScene *scene = qApp->getCurrentScene(); + connect(scene, &VMainGraphicsScene::NewFactor, visual, &Visualization::SetFactor); + scene->addItem(visual); + + QSharedPointer splPath = VAbstractTool::data.GeometricObject(id); + visual->setPath(*splPath.data()); + visual->setMode(Mode::Show); + visual->RefreshGeometry(); + vis = visual; + } + else + { + VisToolSplinePath *visual = qobject_cast(vis); + if (visual != nullptr) + { + visual->show(); + } + } + } + else + { + delete vis; + vis = nullptr; + } + ShowFoot(show); +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief contextMenuEvent handle context menu events. @@ -266,27 +329,6 @@ void VToolSplinePath::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) ContextMenu(this, event); } -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief AddToFile add tag with informations about tool into file. - */ -void VToolSplinePath::AddToFile() -{ - VSplinePath splPath = *VAbstractTool::data.GeometricObject(id); - QDomElement domElement = doc->createElement(TagName); - - doc->SetAttribute(domElement, VDomDocument::AttrId, id); - doc->SetAttribute(domElement, AttrType, ToolType); - doc->SetAttribute(domElement, AttrKCurve, splPath.getKCurve()); - - for (qint32 i = 0; i < splPath.CountPoint(); ++i) - { - AddPathPoint(domElement, splPath.at(i)); - } - - AddToCalculation(domElement); -} - //--------------------------------------------------------------------------------------------------------------------- /** * @brief RefreshDataInFile refresh attributes in file. If attributes don't exist create them. @@ -352,6 +394,23 @@ void VToolSplinePath::SaveDialog(QDomElement &domElement) UpdatePathPoint(doc, domElement, splPath); } +//--------------------------------------------------------------------------------------------------------------------- +void VToolSplinePath::SaveOptions(QDomElement &tag, QSharedPointer &obj) +{ + QSharedPointer splPath = qSharedPointerDynamicCast(obj); + SCASSERT(splPath.isNull() == false); + + doc->SetAttribute(tag, VDomDocument::AttrId, id); + doc->SetAttribute(tag, AttrType, ToolType); + doc->SetAttribute(tag, AttrKCurve, splPath->getKCurve()); + + doc->RemoveAllChild(tag); + for (qint32 i = 0; i < splPath->CountPoint(); ++i) + { + AddPathPoint(tag, splPath->at(i)); + } +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief RefreshGeometry refresh item on scene. @@ -389,4 +448,13 @@ void VToolSplinePath::RefreshGeometry() controlPoints[j-2]->blockSignals(false); controlPoints[j-1]->blockSignals(false); } + + if (vis != nullptr) + { + VisToolSplinePath *visual = qobject_cast(vis); + QSharedPointer splPath = VAbstractTool::data.GeometricObject(id); + visual->setPath(*splPath.data()); + visual->setMode(Mode::Show); + visual->RefreshGeometry(); + } } diff --git a/src/app/tools/drawTools/vtoolsplinepath.h b/src/app/tools/drawTools/vtoolsplinepath.h index c5e39955c..3943a4626 100644 --- a/src/app/tools/drawTools/vtoolsplinepath.h +++ b/src/app/tools/drawTools/vtoolsplinepath.h @@ -41,11 +41,18 @@ public: VToolSplinePath(VPattern *doc, VContainer *data, quint32 id, const Source &typeCreation, QGraphicsItem * parent = nullptr); virtual void setDialog(); - static void Create(DialogTool *dialog, VMainGraphicsScene *scene, VPattern *doc, VContainer *data); - static void Create(const quint32 _id, VSplinePath *path, VMainGraphicsScene *scene, VPattern *doc, - VContainer *data, const Document &parse, const Source &typeCreation); + static VToolSplinePath *Create(DialogTool *dialog, VMainGraphicsScene *scene, VPattern *doc, VContainer *data); + static VToolSplinePath *Create(const quint32 _id, VSplinePath *path, VMainGraphicsScene *scene, VPattern *doc, + VContainer *data, const Document &parse, const Source &typeCreation); static const QString ToolType; static void UpdatePathPoint(VPattern *doc, QDomNode& node, const VSplinePath &path); + virtual int type() const {return Type;} + enum { Type = UserType + static_cast(Tool::SplinePath)}; + + VSplinePath getSplinePath()const; + void setSplinePath(const VSplinePath &splPath); + + virtual void ShowVisualization(bool show); signals: /** * @brief RefreshLine refresh control line. @@ -67,10 +74,10 @@ public slots: const QPointF &pos); protected: virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ); - virtual void AddToFile(); virtual void RefreshDataInFile(); virtual void RemoveReferens(); virtual void SaveDialog(QDomElement &domElement); + virtual void SaveOptions(QDomElement &tag, QSharedPointer &obj); private: void RefreshGeometry(); void AddPathPoint(QDomElement &domElement, const VSplinePoint &splPoint); diff --git a/src/app/tools/drawTools/vtooltriangle.cpp b/src/app/tools/drawTools/vtooltriangle.cpp index 73021e3f2..6c1eee49c 100644 --- a/src/app/tools/drawTools/vtooltriangle.cpp +++ b/src/app/tools/drawTools/vtooltriangle.cpp @@ -29,6 +29,7 @@ #include "vtooltriangle.h" #include "../../dialogs/tools/dialogtriangle.h" #include "../../geometry/vpointf.h" +#include "../../visualization/vistooltriangle.h" #include @@ -229,6 +230,16 @@ void VToolTriangle::FullUpdateFromFile() secondPointId = domElement.attribute(AttrSecondPoint, "").toUInt(); } VToolPoint::RefreshPointGeometry(*VDrawTool::data.GeometricObject(id)); + + if (vis != nullptr) + { + VisToolTriangle * visual = qobject_cast(vis); + visual->setPoint1Id(axisP1Id); + visual->setPoint2Id(axisP2Id); + visual->setHypotenuseP1Id(firstPointId); + visual->setHypotenuseP2Id(secondPointId); + visual->RefreshGeometry(); + } } //--------------------------------------------------------------------------------------------------------------------- @@ -263,49 +274,6 @@ void VToolTriangle::contextMenuEvent(QGraphicsSceneContextMenuEvent *event) ContextMenu(this, event); } -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief AddToFile add tag with informations about tool into file. - */ -void VToolTriangle::AddToFile() -{ - const QSharedPointer point = VAbstractTool::data.GeometricObject(id); - QDomElement domElement = doc->createElement(TagName); - - doc->SetAttribute(domElement, VDomDocument::AttrId, id); - doc->SetAttribute(domElement, AttrType, ToolType); - doc->SetAttribute(domElement, AttrName, point->name()); - doc->SetAttribute(domElement, AttrMx, qApp->fromPixel(point->mx())); - doc->SetAttribute(domElement, AttrMy, qApp->fromPixel(point->my())); - - doc->SetAttribute(domElement, AttrAxisP1, axisP1Id); - doc->SetAttribute(domElement, AttrAxisP2, axisP2Id); - doc->SetAttribute(domElement, AttrFirstPoint, firstPointId); - doc->SetAttribute(domElement, AttrSecondPoint, secondPointId); - - AddToCalculation(domElement); -} - -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief RefreshDataInFile refresh attributes in file. If attributes don't exist create them. - */ -void VToolTriangle::RefreshDataInFile() -{ - const QSharedPointer point = VAbstractTool::data.GeometricObject(id); - QDomElement domElement = doc->elementById(QString().setNum(id)); - if (domElement.isElement()) - { - doc->SetAttribute(domElement, AttrName, point->name()); - doc->SetAttribute(domElement, AttrMx, qApp->fromPixel(point->mx())); - doc->SetAttribute(domElement, AttrMy, qApp->fromPixel(point->my())); - doc->SetAttribute(domElement, AttrAxisP1, axisP1Id); - doc->SetAttribute(domElement, AttrAxisP2, axisP2Id); - doc->SetAttribute(domElement, AttrFirstPoint, firstPointId); - doc->SetAttribute(domElement, AttrSecondPoint, secondPointId); - } -} - //--------------------------------------------------------------------------------------------------------------------- /** * @brief SaveDialog save options into file after change in dialog. @@ -321,3 +289,128 @@ void VToolTriangle::SaveDialog(QDomElement &domElement) doc->SetAttribute(domElement, AttrFirstPoint, QString().setNum(dialogTool->getFirstPointId())); doc->SetAttribute(domElement, AttrSecondPoint, QString().setNum(dialogTool->getSecondPointId())); } + +//--------------------------------------------------------------------------------------------------------------------- +void VToolTriangle::SaveOptions(QDomElement &tag, QSharedPointer &obj) +{ + QSharedPointer point = qSharedPointerDynamicCast(obj); + SCASSERT(point.isNull() == false); + + doc->SetAttribute(tag, VDomDocument::AttrId, id); + doc->SetAttribute(tag, AttrType, ToolType); + doc->SetAttribute(tag, AttrName, point->name()); + doc->SetAttribute(tag, AttrMx, qApp->fromPixel(point->mx())); + doc->SetAttribute(tag, AttrMy, qApp->fromPixel(point->my())); + + doc->SetAttribute(tag, AttrAxisP1, axisP1Id); + doc->SetAttribute(tag, AttrAxisP2, axisP2Id); + doc->SetAttribute(tag, AttrFirstPoint, firstPointId); + doc->SetAttribute(tag, AttrSecondPoint, secondPointId); +} + +//--------------------------------------------------------------------------------------------------------------------- +quint32 VToolTriangle::getSecondPointId() const +{ + return secondPointId; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolTriangle::setSecondPointId(const quint32 &value) +{ + if (value != NULL_ID) + { + secondPointId = value; + + QSharedPointer obj = VAbstractTool::data.GetGObject(id); + SaveOption(obj); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolTriangle::ShowVisualization(bool show) +{ + if (show) + { + if (vis == nullptr) + { + VisToolTriangle * visual = new VisToolTriangle(getData()); + VMainGraphicsScene *scene = qApp->getCurrentScene(); + connect(scene, &VMainGraphicsScene::NewFactor, visual, &Visualization::SetFactor); + scene->addItem(visual); + + visual->setPoint1Id(axisP1Id); + visual->setPoint2Id(axisP2Id); + visual->setHypotenuseP1Id(firstPointId); + visual->setHypotenuseP2Id(secondPointId); + visual->RefreshGeometry(); + vis = visual; + } + else + { + VisToolTriangle * visual = qobject_cast(vis); + if (visual != nullptr) + { + visual->show(); + } + } + } + else + { + delete vis; + vis = nullptr; + } +} + +//--------------------------------------------------------------------------------------------------------------------- +quint32 VToolTriangle::getFirstPointId() const +{ + return firstPointId; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolTriangle::setFirstPointId(const quint32 &value) +{ + if (value != NULL_ID) + { + firstPointId = value; + + QSharedPointer obj = VAbstractTool::data.GetGObject(id); + SaveOption(obj); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +quint32 VToolTriangle::getAxisP2Id() const +{ + return axisP2Id; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolTriangle::setAxisP2Id(const quint32 &value) +{ + if (value != NULL_ID) + { + axisP2Id = value; + + QSharedPointer obj = VAbstractTool::data.GetGObject(id); + SaveOption(obj); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +quint32 VToolTriangle::getAxisP1Id() const +{ + return axisP1Id; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolTriangle::setAxisP1Id(const quint32 &value) +{ + if (value != NULL_ID) + { + axisP1Id = value; + + QSharedPointer obj = VAbstractTool::data.GetGObject(id); + SaveOption(obj); + } +} diff --git a/src/app/tools/drawTools/vtooltriangle.h b/src/app/tools/drawTools/vtooltriangle.h index f845c4786..5ae0743dc 100644 --- a/src/app/tools/drawTools/vtooltriangle.h +++ b/src/app/tools/drawTools/vtooltriangle.h @@ -51,15 +51,30 @@ public: static QPointF FindPoint(const QPointF &axisP1, const QPointF &axisP2, const QPointF &firstPoint, const QPointF &secondPoint); static const QString ToolType; + virtual int type() const {return Type;} + enum { Type = UserType + static_cast(Tool::Triangle)}; + + quint32 getAxisP1Id() const; + void setAxisP1Id(const quint32 &value); + + quint32 getAxisP2Id() const; + void setAxisP2Id(const quint32 &value); + + quint32 getFirstPointId() const; + void setFirstPointId(const quint32 &value); + + quint32 getSecondPointId() const; + void setSecondPointId(const quint32 &value); + + virtual void ShowVisualization(bool show); public slots: virtual void FullUpdateFromFile(); virtual void ShowContextMenu(QGraphicsSceneContextMenuEvent *event); protected: virtual void RemoveReferens(); virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ); - virtual void AddToFile(); - virtual void RefreshDataInFile(); virtual void SaveDialog(QDomElement &domElement); + virtual void SaveOptions(QDomElement &tag, QSharedPointer &obj); private: Q_DISABLE_COPY(VToolTriangle) /** @brief axisP1Id id first axis point. */ diff --git a/src/app/tools/nodeDetails/vabstractnode.cpp b/src/app/tools/nodeDetails/vabstractnode.cpp index 09f6e1da8..ae02381c8 100644 --- a/src/app/tools/nodeDetails/vabstractnode.cpp +++ b/src/app/tools/nodeDetails/vabstractnode.cpp @@ -69,6 +69,12 @@ void VAbstractNode::RestoreNode() } } +//--------------------------------------------------------------------------------------------------------------------- +void VAbstractNode::ShowVisualization(bool show) +{ + Q_UNUSED(show) +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief AddToModeling add tag to modeling tag current pattern peace. @@ -130,3 +136,9 @@ void VAbstractNode::RestoreReferens() doc->IncrementReferens(idNode); } } + +//--------------------------------------------------------------------------------------------------------------------- +void VAbstractNode::SaveOptions(QDomElement &tag, QSharedPointer &obj) +{ + +} diff --git a/src/app/tools/nodeDetails/vabstractnode.h b/src/app/tools/nodeDetails/vabstractnode.h index 9cca668bf..61f505ccc 100644 --- a/src/app/tools/nodeDetails/vabstractnode.h +++ b/src/app/tools/nodeDetails/vabstractnode.h @@ -45,6 +45,7 @@ public: static const QString AttrIdTool; virtual void DeleteNode(); virtual void RestoreNode(); + virtual void ShowVisualization(bool show); protected: /** @brief idNodenode id. */ quint32 idNode; @@ -56,6 +57,7 @@ protected: virtual void decrementReferens(); virtual void RemoveReferens(); virtual void RestoreReferens(); + virtual void SaveOptions(QDomElement &tag, QSharedPointer &obj); }; #endif // VABSTRACTNODE_H diff --git a/src/app/tools/nodeDetails/vnodearc.cpp b/src/app/tools/nodeDetails/vnodearc.cpp index 802265e19..829d86b22 100644 --- a/src/app/tools/nodeDetails/vnodearc.cpp +++ b/src/app/tools/nodeDetails/vnodearc.cpp @@ -124,6 +124,12 @@ void VNodeArc::RestoreNode() } } +//--------------------------------------------------------------------------------------------------------------------- +QString VNodeArc::getTagName() const +{ + return VNodeArc::TagName; +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief FullUpdateFromFile update tool data form file. @@ -144,7 +150,7 @@ void VNodeArc::AddToFile() doc->SetAttribute(domElement, VDomDocument::AttrId, id); doc->SetAttribute(domElement, AttrType, ToolType); doc->SetAttribute(domElement, AttrIdObject, idNode); - if (idTool != 0) + if (idTool != NULL_ID) { doc->SetAttribute(domElement, AttrIdTool, idTool); } @@ -162,7 +168,7 @@ void VNodeArc::RefreshDataInFile() if (domElement.isElement()) { doc->SetAttribute(domElement, AttrIdObject, idNode); - if (idTool != 0) + if (idTool != NULL_ID) { doc->SetAttribute(domElement, AttrIdTool, idTool); } diff --git a/src/app/tools/nodeDetails/vnodearc.h b/src/app/tools/nodeDetails/vnodearc.h index f0bd899be..5341a3f99 100644 --- a/src/app/tools/nodeDetails/vnodearc.h +++ b/src/app/tools/nodeDetails/vnodearc.h @@ -49,6 +49,9 @@ public: static const QString ToolType; virtual void DeleteNode(); virtual void RestoreNode(); + virtual int type() const {return Type;} + enum { Type = UserType + static_cast(Tool::NodeArc)}; + virtual QString getTagName() const; public slots: virtual void FullUpdateFromFile(); protected: diff --git a/src/app/tools/nodeDetails/vnodepoint.cpp b/src/app/tools/nodeDetails/vnodepoint.cpp index 5e02e2443..cce6c8629 100644 --- a/src/app/tools/nodeDetails/vnodepoint.cpp +++ b/src/app/tools/nodeDetails/vnodepoint.cpp @@ -136,6 +136,12 @@ void VNodePoint::RestoreNode() } } +//--------------------------------------------------------------------------------------------------------------------- +QString VNodePoint::getTagName() const +{ + return VNodePoint::TagName; +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief FullUpdateFromFile update tool data form file. @@ -159,7 +165,7 @@ void VNodePoint::AddToFile() doc->SetAttribute(domElement, AttrIdObject, idNode); doc->SetAttribute(domElement, AttrMx, qApp->fromPixel(point->mx())); doc->SetAttribute(domElement, AttrMy, qApp->fromPixel(point->my())); - if (idTool != 0) + if (idTool != NULL_ID) { doc->SetAttribute(domElement, AttrIdTool, idTool); } @@ -180,7 +186,7 @@ void VNodePoint::RefreshDataInFile() doc->SetAttribute(domElement, AttrIdObject, idNode); doc->SetAttribute(domElement, AttrMx, qApp->fromPixel(point->mx())); doc->SetAttribute(domElement, AttrMy, qApp->fromPixel(point->my())); - if (idTool != 0) + if (idTool != NULL_ID) { doc->SetAttribute(domElement, AttrIdTool, idTool); } diff --git a/src/app/tools/nodeDetails/vnodepoint.h b/src/app/tools/nodeDetails/vnodepoint.h index 2e3a7f535..23e666aa8 100644 --- a/src/app/tools/nodeDetails/vnodepoint.h +++ b/src/app/tools/nodeDetails/vnodepoint.h @@ -55,6 +55,9 @@ public: static const QString ToolType; virtual void DeleteNode(); virtual void RestoreNode(); + virtual int type() const {return Type;} + enum { Type = UserType + static_cast(Tool::NodePoint)}; + virtual QString getTagName() const; public slots: virtual void FullUpdateFromFile(); void NameChangePosition(const QPointF &pos); diff --git a/src/app/tools/nodeDetails/vnodespline.cpp b/src/app/tools/nodeDetails/vnodespline.cpp index ffbe5327d..73227ca84 100644 --- a/src/app/tools/nodeDetails/vnodespline.cpp +++ b/src/app/tools/nodeDetails/vnodespline.cpp @@ -127,6 +127,12 @@ void VNodeSpline::RestoreNode() } } +//--------------------------------------------------------------------------------------------------------------------- +QString VNodeSpline::getTagName() const +{ + return VNodeSpline::TagName; +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief FullUpdateFromFile update tool data form file. @@ -147,7 +153,7 @@ void VNodeSpline::AddToFile() doc->SetAttribute(domElement, VDomDocument::AttrId, id); doc->SetAttribute(domElement, AttrType, ToolType); doc->SetAttribute(domElement, AttrIdObject, idNode); - if (idTool != 0) + if (idTool != NULL_ID) { doc->SetAttribute(domElement, AttrIdTool, idTool); } @@ -165,7 +171,7 @@ void VNodeSpline::RefreshDataInFile() if (domElement.isElement()) { doc->SetAttribute(domElement, AttrIdObject, QString().setNum(idNode)); - if (idTool != 0) + if (idTool != NULL_ID) { doc->SetAttribute(domElement, AttrIdTool, idTool); } diff --git a/src/app/tools/nodeDetails/vnodespline.h b/src/app/tools/nodeDetails/vnodespline.h index 0492d9381..4ae2225f5 100644 --- a/src/app/tools/nodeDetails/vnodespline.h +++ b/src/app/tools/nodeDetails/vnodespline.h @@ -49,6 +49,9 @@ public: static const QString ToolType; virtual void DeleteNode(); virtual void RestoreNode(); + virtual int type() const {return Type;} + enum { Type = UserType + static_cast(Tool::NodeSpline)}; + virtual QString getTagName() const; public slots: virtual void FullUpdateFromFile (); protected: diff --git a/src/app/tools/nodeDetails/vnodesplinepath.cpp b/src/app/tools/nodeDetails/vnodesplinepath.cpp index 9451e3f11..5047aea9d 100644 --- a/src/app/tools/nodeDetails/vnodesplinepath.cpp +++ b/src/app/tools/nodeDetails/vnodesplinepath.cpp @@ -130,6 +130,12 @@ void VNodeSplinePath::RestoreNode() } } +//--------------------------------------------------------------------------------------------------------------------- +QString VNodeSplinePath::getTagName() const +{ + return VNodeSplinePath::TagName; +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief FullUpdateFromFile update tool data form file. diff --git a/src/app/tools/nodeDetails/vnodesplinepath.h b/src/app/tools/nodeDetails/vnodesplinepath.h index 91026e642..d92bed5a3 100644 --- a/src/app/tools/nodeDetails/vnodesplinepath.h +++ b/src/app/tools/nodeDetails/vnodesplinepath.h @@ -48,6 +48,9 @@ public: static const QString ToolType; virtual void DeleteNode(); virtual void RestoreNode(); + virtual int type() const {return Type;} + enum { Type = UserType + static_cast(Tool::SplinePath)}; + virtual QString getTagName() const; public slots: virtual void FullUpdateFromFile(); protected: diff --git a/src/app/tools/vabstracttool.cpp b/src/app/tools/vabstracttool.cpp index 5e157743d..3147abb45 100644 --- a/src/app/tools/vabstracttool.cpp +++ b/src/app/tools/vabstracttool.cpp @@ -31,6 +31,8 @@ #include #include "../undocommands/deltool.h" #include "../widgets/vapplication.h" +#include "../geometry/vpointf.h" +#include "../undocommands/savetooloptions.h" const QString VAbstractTool::AttrType = QStringLiteral("type"); const QString VAbstractTool::AttrMx = QStringLiteral("mx"); @@ -82,7 +84,8 @@ const QString VAbstractTool::TypeLineDashDotDotLine = QStringLiteral("dashDotDot * @param parent parent object. */ VAbstractTool::VAbstractTool(VPattern *doc, VContainer *data, quint32 id, QObject *parent) - :VDataTool(data, parent), doc(doc), id(id), baseColor(Qt::black), currentColor(Qt::black), typeLine(TypeLineLine) + :VDataTool(data, parent), doc(doc), id(id), baseColor(Qt::black), currentColor(Qt::black), typeLine(TypeLineLine), + vis(nullptr) { SCASSERT(doc != nullptr); connect(this, &VAbstractTool::toolhaveChange, this->doc, &VPattern::haveLiteChange); @@ -90,6 +93,10 @@ VAbstractTool::VAbstractTool(VPattern *doc, VContainer *data, quint32 id, QObjec connect(this, &VAbstractTool::LiteUpdateTree, this->doc, &VPattern::LiteParseTree); } +//--------------------------------------------------------------------------------------------------------------------- +VAbstractTool::~VAbstractTool() +{} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief NewSceneRect calculate scene rect what contains all items and doesn't less that size of scene view. @@ -289,6 +296,42 @@ Qt::PenStyle VAbstractTool::LineStyle(const QString &typeLine) } } +//--------------------------------------------------------------------------------------------------------------------- +QString VAbstractTool::getLineType() const +{ + return typeLine; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VAbstractTool::setTypeLine(const QString &value) +{ + typeLine = value; + + QSharedPointer obj = VAbstractTool::data.GetGObject(id); + SaveOption(obj); +} + +//--------------------------------------------------------------------------------------------------------------------- +QMap VAbstractTool::PointsList() const +{ + const QHash > *objs = data.DataGObjects(); + QMap list; + QHash >::const_iterator i; + for (i = objs->constBegin(); i != objs->constEnd(); ++i) + { + if (i.key() != id) + { + QSharedPointer obj = i.value(); + if (obj->getType() == GOType::Point && obj->getMode() == Draw::Calculation) + { + const QSharedPointer point = data.GeometricObject(i.key()); + list[point->name()] = i.key(); + } + } + } + return list; +} + //--------------------------------------------------------------------------------------------------------------------- int VAbstractTool::ConfirmDeletion() { @@ -301,6 +344,26 @@ int VAbstractTool::ConfirmDeletion() return msgBox.exec(); } +//--------------------------------------------------------------------------------------------------------------------- +void VAbstractTool::SaveOption(QSharedPointer &obj) +{ + QDomElement oldDomElement = doc->elementById(QString().setNum(id)); + if (oldDomElement.isElement()) + { + QDomElement newDomElement = oldDomElement.cloneNode().toElement(); + + SaveOptions(newDomElement, obj); + + SaveToolOptions *saveOptions = new SaveToolOptions(oldDomElement, newDomElement, doc, id); + connect(saveOptions, &SaveToolOptions::NeedLiteParsing, doc, &VPattern::LiteParseTree); + qApp->getUndoStack()->push(saveOptions); + } + else + { + qDebug()<<"Can't find tool with id ="<< id << Q_FUNC_INFO; + } +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief LineCoefficients coefficient for equation of segment. Segment equestion ax+by+c=0. diff --git a/src/app/tools/vabstracttool.h b/src/app/tools/vabstracttool.h index e8297f8a8..3ae5b9246 100644 --- a/src/app/tools/vabstracttool.h +++ b/src/app/tools/vabstracttool.h @@ -39,6 +39,7 @@ class QGraphicsScene; class QGraphicsView; class QGraphicsItem; class QRectF; +class Visualization; /** * @brief The VAbstractTool abstract class for all tools. @@ -48,7 +49,7 @@ class VAbstractTool: public VDataTool Q_OBJECT public: VAbstractTool(VPattern *doc, VContainer *data, quint32 id, QObject *parent = nullptr); - virtual ~VAbstractTool(){} + virtual ~VAbstractTool(); static void NewSceneRect(QGraphicsScene *sc, QGraphicsView *view); static QPointF LineIntersectRect(QRectF rec, QLineF line); static qint32 LineIntersectCircle(const QPointF ¢er, qreal radius, const QLineF &line, QPointF &p1, @@ -100,6 +101,12 @@ public: static void AddRecord(const quint32 id, const Tool &toolType, VPattern *doc); static Qt::PenStyle LineStyle(const QString &typeLine); const VContainer *getData() const; + + QString getLineType() const; + void setTypeLine(const QString &value); + QMap PointsList() const; + virtual QString getTagName() const =0; + virtual void ShowVisualization(bool show) =0; public slots: /** * @brief FullUpdateFromFile update tool data form file. @@ -135,6 +142,9 @@ protected: /** @brief typeLine line type. */ QString typeLine; + + Visualization *vis; + /** * @brief AddToFile add tag with informations about tool into file. */ @@ -149,6 +159,8 @@ protected: virtual void RemoveReferens(){} virtual void DeleteTool(bool ask = true); static int ConfirmDeletion(); + void SaveOption(QSharedPointer &obj); + virtual void SaveOptions(QDomElement &tag, QSharedPointer &obj)=0; private: Q_DISABLE_COPY(VAbstractTool) }; diff --git a/src/app/tools/vtooldetail.cpp b/src/app/tools/vtooldetail.cpp index 747b3f185..4cbe065ba 100644 --- a/src/app/tools/vtooldetail.cpp +++ b/src/app/tools/vtooldetail.cpp @@ -216,7 +216,7 @@ void VToolDetail::Create(const quint32 &_id, const VDetail &newDetail, VMainGrap doc->UpdateToolData(id, data); } } - VAbstractTool::AddRecord(id, Tool::DetailTool, doc); + VAbstractTool::AddRecord(id, Tool::Detail, doc); if (parse == Document::FullParse) { VToolDetail *detail = new VToolDetail(doc, data, id, typeCreation, scene); @@ -370,6 +370,12 @@ void VToolDetail::keyReleaseEvent(QKeyEvent *event) QGraphicsItem::keyReleaseEvent ( event ); } +//--------------------------------------------------------------------------------------------------------------------- +void VToolDetail::SaveOptions(QDomElement &tag, QSharedPointer &obj) +{ + +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief mouseReleaseEvent handle mouse release events. @@ -475,6 +481,18 @@ void VToolDetail::AddNode(VPattern *doc, QDomElement &domElement, const VNodeDet domElement.appendChild(nod); } +//--------------------------------------------------------------------------------------------------------------------- +QString VToolDetail::getTagName() const +{ + return VToolDetail::TagName; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolDetail::ShowVisualization(bool show) +{ + +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief RefreshGeometry refresh item on scene. diff --git a/src/app/tools/vtooldetail.h b/src/app/tools/vtooldetail.h index df90ad8e5..61cf79210 100644 --- a/src/app/tools/vtooldetail.h +++ b/src/app/tools/vtooldetail.h @@ -82,6 +82,10 @@ public: static const QString NodeSplinePath; void Remove(bool ask); static void AddNode(VPattern *doc, QDomElement &domElement, const VNodeDetail &node); + virtual int type() const {return Type;} + enum { Type = UserType + static_cast(Tool::Detail)}; + virtual QString getTagName() const; + virtual void ShowVisualization(bool show); public slots: virtual void FullUpdateFromFile (); virtual void FullUpdateFromGuiOk(int result); @@ -93,6 +97,7 @@ protected: virtual void contextMenuEvent ( QGraphicsSceneContextMenuEvent * event ); virtual void RemoveReferens(); virtual void keyReleaseEvent(QKeyEvent * event); + virtual void SaveOptions(QDomElement &tag, QSharedPointer &obj); private: Q_DISABLE_COPY(VToolDetail) /** @brief dialog dialog options. */ diff --git a/src/app/tools/vtooluniondetails.cpp b/src/app/tools/vtooluniondetails.cpp index 76b9dfc7c..54db8727d 100644 --- a/src/app/tools/vtooluniondetails.cpp +++ b/src/app/tools/vtooluniondetails.cpp @@ -435,6 +435,18 @@ void VToolUnionDetails::BiasRotatePoint(VPointF *point, const qreal &dx, const q point->setY(line.p2().y()); } +//--------------------------------------------------------------------------------------------------------------------- +QString VToolUnionDetails::getTagName() const +{ + return VToolUnionDetails::TagName; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolUnionDetails::ShowVisualization(bool show) +{ + +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief Create help create tool from GUI. @@ -442,7 +454,8 @@ void VToolUnionDetails::BiasRotatePoint(VPointF *point, const qreal &dx, const q * @param doc dom document container. * @param data container with variables. */ -void VToolUnionDetails::Create(DialogTool *dialog, VMainGraphicsScene *scene, VPattern *doc, VContainer *data) +VToolUnionDetails* VToolUnionDetails::Create(DialogTool *dialog, VMainGraphicsScene *scene, VPattern *doc, + VContainer *data) { SCASSERT(dialog != nullptr); DialogUnionDetails *dialogTool = qobject_cast(dialog); @@ -452,9 +465,11 @@ void VToolUnionDetails::Create(DialogTool *dialog, VMainGraphicsScene *scene, VP quint32 indexD1 = static_cast(dialogTool->getIndexD1()); quint32 indexD2 = static_cast(dialogTool->getIndexD2()); qApp->getUndoStack()->beginMacro("union details"); - Create(0, d1, d2, dialogTool->getD1(), dialogTool->getD2(), indexD1, indexD2, scene, doc, data, Document::FullParse, - Source::FromGui); + VToolUnionDetails* tool = nullptr; + tool = Create(0, d1, d2, dialogTool->getD1(), dialogTool->getD2(), indexD1, indexD2, scene, doc, data, + Document::FullParse, Source::FromGui); qApp->getUndoStack()->endMacro(); + return tool; } //--------------------------------------------------------------------------------------------------------------------- @@ -473,10 +488,10 @@ void VToolUnionDetails::Create(DialogTool *dialog, VMainGraphicsScene *scene, VP * @param parse parser file mode. * @param typeCreation way we create this tool. */ -void VToolUnionDetails::Create(const quint32 _id, const VDetail &d1, const VDetail &d2, const quint32 &d1id, - const quint32 &d2id, const quint32 &indexD1, const quint32 &indexD2, - VMainGraphicsScene *scene, VPattern *doc, VContainer *data, - const Document &parse, const Source &typeCreation) +VToolUnionDetails* VToolUnionDetails::Create(const quint32 _id, const VDetail &d1, const VDetail &d2, + const quint32 &d1id, const quint32 &d2id, const quint32 &indexD1, + const quint32 &indexD2, VMainGraphicsScene *scene, VPattern *doc, + VContainer *data, const Document &parse, const Source &typeCreation) { VToolUnionDetails *unionDetails = 0; quint32 id = _id; @@ -609,6 +624,7 @@ void VToolUnionDetails::Create(const quint32 _id, const VDetail &d1, const VDeta } } while (i &obj) +{ + +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief AddDetail add detail to xml file. diff --git a/src/app/tools/vtooluniondetails.h b/src/app/tools/vtooluniondetails.h index bc610a0c3..737778532 100644 --- a/src/app/tools/vtooluniondetails.h +++ b/src/app/tools/vtooluniondetails.h @@ -50,11 +50,11 @@ public: * @brief setDialog set dialog when user want change tool option. */ virtual void setDialog() {} - static void Create(DialogTool *dialog, VMainGraphicsScene *scene, VPattern *doc, VContainer *data); - static void Create(const quint32 _id, const VDetail &d1, const VDetail &d2, const quint32 &d1id, - const quint32 &d2id, const quint32 &indexD1, const quint32 &indexD2, VMainGraphicsScene *scene, - VPattern *doc, VContainer *data, const Document &parse, - const Source &typeCreation); + static VToolUnionDetails *Create(DialogTool *dialog, VMainGraphicsScene *scene, VPattern *doc, VContainer *data); + static VToolUnionDetails *Create(const quint32 _id, const VDetail &d1, const VDetail &d2, const quint32 &d1id, + const quint32 &d2id, const quint32 &indexD1, const quint32 &indexD2, + VMainGraphicsScene *scene, VPattern *doc, VContainer *data, const Document &parse, + const Source &typeCreation); static void PointsOnEdge(const VDetail &d, const quint32 &index, VPointF &p1, VPointF &p2, VContainer *data); static void FindJ(const qint32 &pointsD2, const VDetail &d2, const quint32 &indexD2, qint32 &j); static QVector GetDetailFromFile(VPattern *doc, const QDomElement &domElement); @@ -76,6 +76,8 @@ public: const qreal &angle = 0); static void BiasRotatePoint(VPointF *point, const qreal &dx, const qreal &dy, const QPointF &pRotate, const qreal &angle); + virtual QString getTagName() const; + virtual void ShowVisualization(bool show); public slots: /** * @brief FullUpdateFromFile update tool data form file. @@ -84,6 +86,7 @@ public slots: protected: virtual void AddToFile(); virtual void RefreshDataInFile(); + virtual void SaveOptions(QDomElement &tag, QSharedPointer &obj); private: Q_DISABLE_COPY(VToolUnionDetails) /** @brief d1 first detail. */ diff --git a/src/app/visualization/vcontrolpointspline.cpp b/src/app/visualization/vcontrolpointspline.cpp index ba1644310..70b73bda3 100644 --- a/src/app/visualization/vcontrolpointspline.cpp +++ b/src/app/visualization/vcontrolpointspline.cpp @@ -127,7 +127,7 @@ QVariant VControlPointSpline::itemChange(QGraphicsItem::GraphicsItemChange chang //--------------------------------------------------------------------------------------------------------------------- void VControlPointSpline::mousePressEvent(QGraphicsSceneMouseEvent *event) { - if (event->button() == Qt::LeftButton) + if (event->button() == Qt::LeftButton && event->type() != QEvent::GraphicsSceneMouseDoubleClick) { #ifndef QT_NO_CURSOR QPixmap pixmap(QLatin1String("://cursor/cursor-arrow-closehand.png")); @@ -140,7 +140,7 @@ void VControlPointSpline::mousePressEvent(QGraphicsSceneMouseEvent *event) //--------------------------------------------------------------------------------------------------------------------- void VControlPointSpline::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) { - if (event->button() == Qt::LeftButton) + if (event->button() == Qt::LeftButton && event->type() != QEvent::GraphicsSceneMouseDoubleClick) { //Disable cursor-arrow-closehand #ifndef QT_NO_CURSOR diff --git a/src/app/visualization/vcontrolpointspline.h b/src/app/visualization/vcontrolpointspline.h index 0ae115fc7..e72c78951 100644 --- a/src/app/visualization/vcontrolpointspline.h +++ b/src/app/visualization/vcontrolpointspline.h @@ -43,6 +43,8 @@ public: VControlPointSpline(const qint32 &indexSpline, SplinePointPosition position, const QPointF &controlPoint, const QPointF &splinePoint, QGraphicsItem * parent = nullptr); virtual void paint(QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget = 0); + virtual int type() const {return Type;} + enum { Type = UserType + static_cast(Vis::ControlPointSpline)}; signals: /** * @brief ControlPointChangePosition emit when control point change position. diff --git a/src/app/visualization/vgraphicssimpletextitem.cpp b/src/app/visualization/vgraphicssimpletextitem.cpp index 9de68966f..825362721 100644 --- a/src/app/visualization/vgraphicssimpletextitem.cpp +++ b/src/app/visualization/vgraphicssimpletextitem.cpp @@ -31,6 +31,7 @@ #include #include #include +#include //--------------------------------------------------------------------------------------------------------------------- /** @@ -141,7 +142,7 @@ void VGraphicsSimpleTextItem::contextMenuEvent(QGraphicsSceneContextMenuEvent *e //--------------------------------------------------------------------------------------------------------------------- void VGraphicsSimpleTextItem::mousePressEvent(QGraphicsSceneMouseEvent *event) { - if (event->button() == Qt::LeftButton) + if (event->button() == Qt::LeftButton && event->type() != QEvent::GraphicsSceneMouseDoubleClick) { #ifndef QT_NO_CURSOR QPixmap pixmap(QLatin1String("://cursor/cursor-arrow-closehand.png")); @@ -154,7 +155,7 @@ void VGraphicsSimpleTextItem::mousePressEvent(QGraphicsSceneMouseEvent *event) //--------------------------------------------------------------------------------------------------------------------- void VGraphicsSimpleTextItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) { - if (event->button() == Qt::LeftButton) + if (event->button() == Qt::LeftButton && event->type() != QEvent::GraphicsSceneMouseDoubleClick) { //Disable cursor-arrow-closehand #ifndef QT_NO_CURSOR diff --git a/src/app/visualization/vgraphicssimpletextitem.h b/src/app/visualization/vgraphicssimpletextitem.h index b6622feda..122b02b20 100644 --- a/src/app/visualization/vgraphicssimpletextitem.h +++ b/src/app/visualization/vgraphicssimpletextitem.h @@ -31,6 +31,7 @@ #include #include +#include "../options.h" /** * @brief The VGraphicsSimpleTextItem class pointer label. @@ -44,6 +45,8 @@ public: qint32 FontSize()const; virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0); + virtual int type() const {return Type;} + enum { Type = UserType + static_cast(Vis::GraphicsSimpleTextItem)}; signals: /** * @brief NameChangePosition emit when label change position. diff --git a/src/app/visualization/visline.h b/src/app/visualization/visline.h index ec7933a1f..8f8c4d884 100644 --- a/src/app/visualization/visline.h +++ b/src/app/visualization/visline.h @@ -42,6 +42,8 @@ public: VisLine(const VContainer *data, QGraphicsItem *parent = 0); virtual ~VisLine(); + virtual int type() const {return Type;} + enum { Type = UserType + static_cast(Vis::Line)}; protected: QLineF Line(const QPointF &p1, const qreal& length, const qreal &angle); qreal CorrectAngle(const qreal &angle) const; diff --git a/src/app/visualization/vispath.h b/src/app/visualization/vispath.h index 67ef9974a..54d226863 100644 --- a/src/app/visualization/vispath.h +++ b/src/app/visualization/vispath.h @@ -39,6 +39,8 @@ public: VisPath(const VContainer *data, QGraphicsItem *parent = 0); virtual ~VisPath(); + virtual int type() const {return Type;} + enum { Type = UserType + static_cast(Vis::Path)}; protected: virtual void InitPen(); virtual void AddOnScene(); diff --git a/src/app/visualization/vistoolalongline.h b/src/app/visualization/vistoolalongline.h index 791d2cf1d..45d6d61e3 100644 --- a/src/app/visualization/vistoolalongline.h +++ b/src/app/visualization/vistoolalongline.h @@ -43,6 +43,8 @@ public: virtual void RefreshGeometry(); void setPoint2Id(const quint32 &value); void setLength(const QString &expression); + virtual int type() const {return Type;} + enum { Type = UserType + static_cast(Vis::ToolAlongLine)}; private: Q_DISABLE_COPY(VisToolAlongLine) quint32 point2Id; diff --git a/src/app/visualization/vistoolarc.h b/src/app/visualization/vistoolarc.h index 3c06737c8..5e44d0f1a 100644 --- a/src/app/visualization/vistoolarc.h +++ b/src/app/visualization/vistoolarc.h @@ -43,6 +43,8 @@ public: void setRadius(const QString &expression); void setF1(const QString &expression); void setF2(const QString &expression); + virtual int type() const {return Type;} + enum { Type = UserType + static_cast(Vis::ToolArc)}; private: Q_DISABLE_COPY(VisToolArc) QGraphicsEllipseItem *arcCenter; diff --git a/src/app/visualization/vistoolbisector.h b/src/app/visualization/vistoolbisector.h index 9b8aade23..be85db27b 100644 --- a/src/app/visualization/vistoolbisector.h +++ b/src/app/visualization/vistoolbisector.h @@ -42,6 +42,8 @@ public: void setPoint2Id(const quint32 &value); void setPoint3Id(const quint32 &value); void setLength(const QString &expression); + virtual int type() const {return Type;} + enum { Type = UserType + static_cast(Vis::ToolBisector)}; private: Q_DISABLE_COPY(VisToolBisector) quint32 point2Id; diff --git a/src/app/visualization/vistoolcutarc.h b/src/app/visualization/vistoolcutarc.h index a97b7d5bb..84aa695be 100644 --- a/src/app/visualization/vistoolcutarc.h +++ b/src/app/visualization/vistoolcutarc.h @@ -40,6 +40,8 @@ public: virtual void RefreshGeometry(); void setLength(const QString &expression); + virtual int type() const {return Type;} + enum { Type = UserType + static_cast(Vis::ToolCutArc)}; protected: Q_DISABLE_COPY(VisToolCutArc) QGraphicsEllipseItem *point; diff --git a/src/app/visualization/vistoolcutspline.cpp b/src/app/visualization/vistoolcutspline.cpp new file mode 100644 index 000000000..6d41865fa --- /dev/null +++ b/src/app/visualization/vistoolcutspline.cpp @@ -0,0 +1,76 @@ +/************************************************************************ + ** + ** @file vistoolcutspline.cpp + ** @author Roman Telezhynskyi + ** @date 6 9, 2014 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2014 Valentina project + ** All Rights Reserved. + ** + ** Valentina 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. + ** + ** Valentina 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 for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with Valentina. If not, see . + ** + *************************************************************************/ + +#include "vistoolcutspline.h" +#include "../geometry/vspline.h" +#include "../container/vcontainer.h" + +//--------------------------------------------------------------------------------------------------------------------- +VisToolCutSpline::VisToolCutSpline(const VContainer *data, QGraphicsItem *parent) + :VisPath(data, parent), point(nullptr), spl1(nullptr), spl2(nullptr), length(0) +{ + spl1 = InitItem(Qt::darkGreen, this); + spl1->setFlag(QGraphicsItem::ItemStacksBehindParent, false); + spl2 = InitItem(Qt::darkRed, this); + spl2->setFlag(QGraphicsItem::ItemStacksBehindParent, false); + + point = InitPoint(mainColor, this); + point->setZValue(2); + point->setFlag(QGraphicsItem::ItemStacksBehindParent, false); +} + +//--------------------------------------------------------------------------------------------------------------------- +VisToolCutSpline::~VisToolCutSpline() +{} + +//--------------------------------------------------------------------------------------------------------------------- +void VisToolCutSpline::RefreshGeometry() +{ + if (point1Id > 0) + { + const QSharedPointer spl = Visualization::data->GeometricObject(point1Id); + DrawPath(this, spl->GetPath(PathDirection::Show), supportColor, Qt::SolidLine, Qt::RoundCap); + + if (qFuzzyCompare(1 + length, 1 + 0) == false) + { + VSpline sp1; + VSpline sp2; + QPointF p = spl->CutSpline(length, sp1, sp2); + DrawPoint(point, p, mainColor); + + DrawPath(spl1, sp1.GetPath(PathDirection::Show), Qt::darkGreen, Qt::SolidLine, Qt::RoundCap); + DrawPath(spl2, sp2.GetPath(PathDirection::Show), Qt::darkRed, Qt::SolidLine, Qt::RoundCap); + } + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VisToolCutSpline::setLength(const QString &expression) +{ + length = FindLength(expression); +} diff --git a/src/app/visualization/vsimplesplinepath.h b/src/app/visualization/vistoolcutspline.h similarity index 54% rename from src/app/visualization/vsimplesplinepath.h rename to src/app/visualization/vistoolcutspline.h index 50fe8ec67..5967f3ba5 100644 --- a/src/app/visualization/vsimplesplinepath.h +++ b/src/app/visualization/vistoolcutspline.h @@ -1,14 +1,14 @@ /************************************************************************ ** - ** @file vsimplesplinepath.h + ** @file vistoolcutspline.h ** @author Roman Telezhynskyi - ** @date 17 12, 2013 + ** @date 6 9, 2014 ** ** @brief ** @copyright ** This source code is part of the Valentine project, a pattern making ** program, whose allow create and modeling patterns of clothing. - ** Copyright (C) 2013 Valentina project + ** Copyright (C) 2014 Valentina project ** All Rights Reserved. ** ** Valentina is free software: you can redistribute it and/or modify @@ -26,30 +26,28 @@ ** *************************************************************************/ -#ifndef VSIMPLESPLINEPATH_H -#define VSIMPLESPLINEPATH_H +#ifndef VISTOOLCUTSPLINE_H +#define VISTOOLCUTSPLINE_H -#include -#include "../tools/vabstracttool.h" +#include "vispath.h" -/** - * @brief The VSimpleSplinePath class for simple spline path. This object used when we cut spline path and want show - * peaces. - */ -class VSimpleSplinePath : public VAbstractTool, public QGraphicsPathItem +class VisToolCutSpline : public VisPath { Q_OBJECT public: - VSimpleSplinePath(VPattern *doc, VContainer *data, quint32 id, qreal *factor); - virtual void paint(QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget = 0); + VisToolCutSpline(const VContainer *data, QGraphicsItem *parent = 0); + virtual ~VisToolCutSpline(); + + virtual void RefreshGeometry(); + void setLength(const QString &expression); + virtual int type() const {return Type;} + enum { Type = UserType + static_cast(Vis::ToolCutSpline)}; protected: - virtual void mouseReleaseEvent ( QGraphicsSceneMouseEvent * event ); - virtual void hoverMoveEvent ( QGraphicsSceneHoverEvent * event ); - virtual void hoverLeaveEvent ( QGraphicsSceneHoverEvent * event ); -private: - Q_DISABLE_COPY(VSimpleSplinePath) - /** @brief factor scale factor. */ - qreal *factor; + Q_DISABLE_COPY(VisToolCutSpline) + QGraphicsEllipseItem *point; + QGraphicsPathItem *spl1; + QGraphicsPathItem *spl2; + qreal length; }; -#endif // VSIMPLESPLINEPATH_H +#endif // VISTOOLCUTSPLINE_H diff --git a/src/app/visualization/vistoolcutsplinepath.cpp b/src/app/visualization/vistoolcutsplinepath.cpp new file mode 100644 index 000000000..9bf157428 --- /dev/null +++ b/src/app/visualization/vistoolcutsplinepath.cpp @@ -0,0 +1,118 @@ +/************************************************************************ + ** + ** @file vistoolcutsplinepath.cpp + ** @author Roman Telezhynskyi + ** @date 7 9, 2014 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2014 Valentina project + ** All Rights Reserved. + ** + ** Valentina 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. + ** + ** Valentina 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 for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with Valentina. If not, see . + ** + *************************************************************************/ + +#include "vistoolcutsplinepath.h" +#include "../container/vcontainer.h" +#include "../geometry/vsplinepath.h" + +//--------------------------------------------------------------------------------------------------------------------- +VisToolCutSplinePath::VisToolCutSplinePath(const VContainer *data, QGraphicsItem *parent) + :VisPath(data, parent), point(nullptr), splPath1(nullptr), splPath2(nullptr), length(0) +{ + splPath1 = InitItem(Qt::darkGreen, this); + splPath1->setFlag(QGraphicsItem::ItemStacksBehindParent, false); + splPath2 = InitItem(Qt::darkRed, this); + splPath2->setFlag(QGraphicsItem::ItemStacksBehindParent, false); + + point = InitPoint(mainColor, this); + point->setZValue(2); + point->setFlag(QGraphicsItem::ItemStacksBehindParent, false); +} + +//--------------------------------------------------------------------------------------------------------------------- +VisToolCutSplinePath::~VisToolCutSplinePath() +{} + +//--------------------------------------------------------------------------------------------------------------------- +void VisToolCutSplinePath::RefreshGeometry() +{ + if (point1Id > 0) + { + const QSharedPointer splPath = Visualization::data->GeometricObject(point1Id); + DrawPath(this, splPath->GetPath(PathDirection::Show), supportColor, Qt::SolidLine, Qt::RoundCap); + + if (qFuzzyCompare(1 + length, 1 + 0) == false) + { + QPointF spl1p2, spl1p3, spl2p2, spl2p3; + qint32 p1 = 0, p2 = 0; + + const QPointF cutPoint = splPath->CutSplinePath(length, p1, p2, spl1p2, spl1p3, spl2p2, spl2p3); + VPointF p = VPointF(cutPoint); + + VSplinePoint splP1 = splPath->at(p1); + VSplinePoint splP2 = splPath->at(p2); + const VSpline spl1 = VSpline(splP1.P(), spl1p2, spl1p3, p, splPath->getKCurve()); + const VSpline spl2 = VSpline(p, spl2p2, spl2p3, splP2.P(), splPath->getKCurve()); + + VSplinePath spPath1 = VSplinePath(); + VSplinePath spPath2 = VSplinePath(); + + for (qint32 i = 0; i < splPath->CountPoint(); i++) + { + if (i <= p1 && i < p2) + { + if (i == p1) + { + spPath1.append(VSplinePoint(splP1.P(), splP1.KAsm1(), spl1.GetAngle1()+180, spl1.GetKasm1(), + spl1.GetAngle1())); + VSplinePoint cutPoint; + cutPoint = VSplinePoint(p, spl1.GetKasm2(), spl1.GetAngle2(), spl2.GetKasm1(), + spl1.GetAngle2()+180); + spPath1.append(cutPoint); + continue; + } + spPath1.append(splPath->at(i)); + } + else + { + if (i == p2) + { + const VSplinePoint cutPoint = VSplinePoint(p, spl1.GetKasm2(), spl2.GetAngle1()+180, + spl2.GetKasm1(), spl2.GetAngle1()); + spPath2.append(cutPoint); + spPath2.append(VSplinePoint(splP2.P(), spl2.GetKasm2(), spl2.GetAngle2(), splP2.KAsm2(), + spl2.GetAngle2()+180)); + continue; + } + spPath2.append(splPath->at(i)); + } + } + + DrawPoint(point, cutPoint, mainColor); + + DrawPath(splPath1, spPath1.GetPath(PathDirection::Show), Qt::darkGreen, Qt::SolidLine, Qt::RoundCap); + DrawPath(splPath2, spPath2.GetPath(PathDirection::Show), Qt::darkRed, Qt::SolidLine, Qt::RoundCap); + } + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VisToolCutSplinePath::setLength(const QString &expression) +{ + length = FindLength(expression); +} diff --git a/src/app/visualization/vistoolcutsplinepath.h b/src/app/visualization/vistoolcutsplinepath.h new file mode 100644 index 000000000..6dd4bdfcb --- /dev/null +++ b/src/app/visualization/vistoolcutsplinepath.h @@ -0,0 +1,53 @@ +/************************************************************************ + ** + ** @file vistoolcutsplinepath.h + ** @author Roman Telezhynskyi + ** @date 7 9, 2014 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2014 Valentina project + ** All Rights Reserved. + ** + ** Valentina 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. + ** + ** Valentina 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 for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with Valentina. If not, see . + ** + *************************************************************************/ + +#ifndef VISTOOLCUTSPLINEPATH_H +#define VISTOOLCUTSPLINEPATH_H + +#include "vispath.h" + +class VisToolCutSplinePath : public VisPath +{ + Q_OBJECT +public: + VisToolCutSplinePath(const VContainer *data, QGraphicsItem *parent = 0); + virtual ~VisToolCutSplinePath(); + + virtual void RefreshGeometry(); + void setLength(const QString &expression); + virtual int type() const {return Type;} + enum { Type = UserType + static_cast(Vis::ToolCutSpline)}; +protected: + Q_DISABLE_COPY(VisToolCutSplinePath) + QGraphicsEllipseItem *point; + QGraphicsPathItem *splPath1; + QGraphicsPathItem *splPath2; + qreal length; +}; + +#endif // VISTOOLCUTSPLINEPATH_H diff --git a/src/app/visualization/vistoolendline.h b/src/app/visualization/vistoolendline.h index 288dbde67..7b44f697f 100644 --- a/src/app/visualization/vistoolendline.h +++ b/src/app/visualization/vistoolendline.h @@ -44,6 +44,8 @@ public: QString Angle() const; void setAngle(const QString &expression); void setLength(const QString &expression); + virtual int type() const {return Type;} + enum { Type = UserType + static_cast(Vis::ToolEndLine)}; private: Q_DISABLE_COPY(VisToolEndLine) qreal length; diff --git a/src/app/visualization/vistoolheight.h b/src/app/visualization/vistoolheight.h index 07b0bcd28..0b17b78bb 100644 --- a/src/app/visualization/vistoolheight.h +++ b/src/app/visualization/vistoolheight.h @@ -42,6 +42,8 @@ public: void setLineP1Id(const quint32 &value); void setLineP2Id(const quint32 &value); + virtual int type() const {return Type;} + enum { Type = UserType + static_cast(Vis::ToolHeight)}; private: Q_DISABLE_COPY(VisToolHeight) //base point in parent class diff --git a/src/app/visualization/vistoolline.h b/src/app/visualization/vistoolline.h index d28e6be49..48347dbe7 100644 --- a/src/app/visualization/vistoolline.h +++ b/src/app/visualization/vistoolline.h @@ -40,6 +40,8 @@ public: virtual void RefreshGeometry(); void setPoint2Id(const quint32 &value); + virtual int type() const {return Type;} + enum { Type = UserType + static_cast(Vis::ToolLine)}; private: Q_DISABLE_COPY(VisToolLine) quint32 point2Id; diff --git a/src/app/visualization/vistoollineintersect.h b/src/app/visualization/vistoollineintersect.h index 568c4c242..b69d03ff7 100644 --- a/src/app/visualization/vistoollineintersect.h +++ b/src/app/visualization/vistoollineintersect.h @@ -43,6 +43,8 @@ public: void setLine1P2Id(const quint32 &value); void setLine2P1Id(const quint32 &value); void setLine2P2Id(const quint32 &value); + virtual int type() const {return Type;} + enum { Type = UserType + static_cast(Vis::ToolLineIntersect)}; private: Q_DISABLE_COPY(VisToolLineIntersect) quint32 line1P2Id; diff --git a/src/app/visualization/vistoolnormal.h b/src/app/visualization/vistoolnormal.h index 649164851..1593d03f5 100644 --- a/src/app/visualization/vistoolnormal.h +++ b/src/app/visualization/vistoolnormal.h @@ -44,6 +44,8 @@ public: void setLength(const QString &expression); qreal getAngle() const; void setAngle(const qreal &value); + virtual int type() const {return Type;} + enum { Type = UserType + static_cast(Vis::ToolNormal)}; private: Q_DISABLE_COPY(VisToolNormal) quint32 point2Id; diff --git a/src/app/visualization/vistoolpointofcontact.h b/src/app/visualization/vistoolpointofcontact.h index bb638790d..4edc79ea0 100644 --- a/src/app/visualization/vistoolpointofcontact.h +++ b/src/app/visualization/vistoolpointofcontact.h @@ -42,6 +42,8 @@ public: void setLineP2Id(const quint32 &value); void setRadiusId(const quint32 &value); void setRadius(const QString &expression); + virtual int type() const {return Type;} + enum { Type = UserType + static_cast(Vis::ToolPointOfContact)}; private: Q_DISABLE_COPY(VisToolPointOfContact) quint32 lineP2Id; diff --git a/src/app/visualization/vistoolpointofintersection.h b/src/app/visualization/vistoolpointofintersection.h index e17c1ee05..a2c594f75 100644 --- a/src/app/visualization/vistoolpointofintersection.h +++ b/src/app/visualization/vistoolpointofintersection.h @@ -41,6 +41,8 @@ public: virtual void RefreshGeometry(); void setPoint2Id(const quint32 &value); + virtual int type() const {return Type;} + enum { Type = UserType + static_cast(Vis::ToolPointOfIntersection)}; private: Q_DISABLE_COPY(VisToolPointOfIntersection) quint32 point2Id; diff --git a/src/app/visualization/vistoolshoulderpoint.h b/src/app/visualization/vistoolshoulderpoint.h index 6511f253b..bfda38bc5 100644 --- a/src/app/visualization/vistoolshoulderpoint.h +++ b/src/app/visualization/vistoolshoulderpoint.h @@ -42,6 +42,8 @@ public: void setLineP1Id(const quint32 &value); void setLineP2Id(const quint32 &value); void setLength(const QString &expression); + virtual int type() const {return Type;} + enum { Type = UserType + static_cast(Vis::ToolShoulderPoint)}; private: Q_DISABLE_COPY(VisToolShoulderPoint) quint32 lineP1Id; diff --git a/src/app/visualization/vistoolspline.h b/src/app/visualization/vistoolspline.h index 1a2c9f9f9..56c12d021 100644 --- a/src/app/visualization/vistoolspline.h +++ b/src/app/visualization/vistoolspline.h @@ -46,6 +46,9 @@ public: void setKAsm1(const qreal &value); void setKAsm2(const qreal &value); void setKCurve(const qreal &value); + + virtual int type() const {return Type;} + enum { Type = UserType + static_cast(Vis::ToolSpline)}; protected: Q_DISABLE_COPY(VisToolSpline) quint32 point4Id; diff --git a/src/app/visualization/vistoolsplinepath.cpp b/src/app/visualization/vistoolsplinepath.cpp new file mode 100644 index 000000000..b4698e350 --- /dev/null +++ b/src/app/visualization/vistoolsplinepath.cpp @@ -0,0 +1,127 @@ +/************************************************************************ + ** + ** @file vistoolsplinepath.cpp + ** @author Roman Telezhynskyi + ** @date 7 9, 2014 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2014 Valentina project + ** All Rights Reserved. + ** + ** Valentina 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. + ** + ** Valentina 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 for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with Valentina. If not, see . + ** + *************************************************************************/ + +#include "vistoolsplinepath.h" + +//--------------------------------------------------------------------------------------------------------------------- +VisToolSplinePath::VisToolSplinePath(const VContainer *data, QGraphicsItem *parent) + : VisPath(data, parent), points(QVector()), line(nullptr), path(VSplinePath()), + mode(Mode::Creation) +{ + line = InitItem(mainColor, this); +} + +//--------------------------------------------------------------------------------------------------------------------- +VisToolSplinePath::~VisToolSplinePath() +{ + qDeleteAll(points.begin(), points.end()); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VisToolSplinePath::RefreshGeometry() +{ + if (path.CountPoint() > 0) + { + QVector pathPoints = path.GetSplinePath(); + if (path.CountPoint() == 1) + { + QGraphicsEllipseItem *point = this->getPoint(0); + DrawPoint(point, pathPoints.at(0).P().toQPointF(), supportColor); + + if (mode == Mode::Creation) + { + QLineF sceneLine = QLineF(pathPoints.at(0).P().toQPointF(), Visualization::scenePos); + DrawLine(line, sceneLine, mainColor, lineStyle); + + path[0].SetAngle2(sceneLine.angle()); + emit PathChanged(path); + } + } + else + { + for (int i = 0; i < pathPoints.size(); ++i) + { + QGraphicsEllipseItem *point = this->getPoint(i); + DrawPoint(point, pathPoints.at(i).P().toQPointF(), supportColor); + } + + if (mode == Mode::Creation) + { + QLineF sceneLine = QLineF(pathPoints.at(pathPoints.size() - 1).P().toQPointF(), + Visualization::scenePos); + DrawLine(line, sceneLine, mainColor, lineStyle); + + path[pathPoints.size() - 1].SetAngle2(sceneLine.angle()); + emit PathChanged(path); + } + + DrawPath(this, path.GetPath(PathDirection::Show), mainColor, Qt::SolidLine, Qt::RoundCap); + } + Visualization::toolTip = QString(tr("Curve path: Enter - finish creation")); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VisToolSplinePath::setPath(const VSplinePath &value) +{ + path = value; +} + +//--------------------------------------------------------------------------------------------------------------------- +VSplinePath VisToolSplinePath::getPath() +{ + return path; +} + +//--------------------------------------------------------------------------------------------------------------------- +Mode VisToolSplinePath::getMode() const +{ + return mode; +} + +//--------------------------------------------------------------------------------------------------------------------- +void VisToolSplinePath::setMode(const Mode &value) +{ + mode = value; +} + +//--------------------------------------------------------------------------------------------------------------------- +QGraphicsEllipseItem *VisToolSplinePath::getPoint(unsigned int i) +{ + if (points.size() - 1 >= i && points.isEmpty() == false) + { + return points.at(i); + } + else + { + QGraphicsEllipseItem * point = InitPoint(supportColor, this); + points.append(point); + return point; + } + return nullptr; +} diff --git a/src/app/visualization/vistoolsplinepath.h b/src/app/visualization/vistoolsplinepath.h new file mode 100644 index 000000000..be9dc2b3c --- /dev/null +++ b/src/app/visualization/vistoolsplinepath.h @@ -0,0 +1,67 @@ +/************************************************************************ + ** + ** @file vistoolsplinepath.h + ** @author Roman Telezhynskyi + ** @date 7 9, 2014 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2014 Valentina project + ** All Rights Reserved. + ** + ** Valentina 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. + ** + ** Valentina 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 for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with Valentina. If not, see . + ** + *************************************************************************/ + +#ifndef VISTOOLSPLINEPATH_H +#define VISTOOLSPLINEPATH_H + +#include "vispath.h" +#include "../geometry/vsplinepath.h" + +enum class Mode : char {Creation, Show}; + +class VisToolSplinePath : public VisPath +{ + Q_OBJECT +public: + VisToolSplinePath(const VContainer *data, QGraphicsItem *parent = 0); + virtual ~VisToolSplinePath(); + + virtual void RefreshGeometry(); + + void setPath(const VSplinePath &value); + VSplinePath getPath(); + + virtual int type() const {return Type;} + enum { Type = UserType + static_cast(Vis::ToolSplinePath)}; + + Mode getMode() const; + void setMode(const Mode &value); +signals: + void PathChanged(const VSplinePath &path); + +protected: + Q_DISABLE_COPY(VisToolSplinePath) + QVector points; + QGraphicsLineItem *line; + VSplinePath path; + Mode mode; + + QGraphicsEllipseItem * getPoint(unsigned int i); +}; + +#endif // VISTOOLSPLINEPATH_H diff --git a/src/app/visualization/vistooltriangle.h b/src/app/visualization/vistooltriangle.h index b34b5cd0e..a15defaf7 100644 --- a/src/app/visualization/vistooltriangle.h +++ b/src/app/visualization/vistooltriangle.h @@ -43,6 +43,9 @@ public: void setPoint2Id(const quint32 &value); void setHypotenuseP1Id(const quint32 &value); void setHypotenuseP2Id(const quint32 &value); + + virtual int type() const {return Type;} + enum { Type = UserType + static_cast(Vis::ToolTriangle)}; private: Q_DISABLE_COPY(VisToolTriangle) quint32 point2Id;//axis second point diff --git a/src/app/visualization/visualization.pri b/src/app/visualization/visualization.pri index b3397108a..abd4a6ea3 100644 --- a/src/app/visualization/visualization.pri +++ b/src/app/visualization/visualization.pri @@ -1,7 +1,6 @@ HEADERS += \ visualization/vgraphicssimpletextitem.h \ visualization/vcontrolpointspline.h \ - visualization/vsimplesplinepath.h \ visualization/vsimplecurve.h \ visualization/visline.h \ visualization/vistoolline.h \ @@ -19,12 +18,14 @@ HEADERS += \ visualization/vistoolarc.h \ visualization/vispath.h \ visualization/vistoolcutarc.h \ - visualization/vistoolspline.h + visualization/vistoolspline.h \ + visualization/vistoolcutspline.h \ + visualization/vistoolsplinepath.h \ + visualization/vistoolcutsplinepath.h SOURCES += \ visualization/vgraphicssimpletextitem.cpp \ visualization/vcontrolpointspline.cpp \ - visualization/vsimplesplinepath.cpp \ visualization/vsimplecurve.cpp \ visualization/visline.cpp \ visualization/vistoolline.cpp \ @@ -42,4 +43,7 @@ SOURCES += \ visualization/vistoolarc.cpp \ visualization/vispath.cpp \ visualization/vistoolcutarc.cpp \ - visualization/vistoolspline.cpp + visualization/vistoolspline.cpp \ + visualization/vistoolcutspline.cpp \ + visualization/vistoolsplinepath.cpp \ + visualization/vistoolcutsplinepath.cpp diff --git a/src/app/visualization/vsimplecurve.h b/src/app/visualization/vsimplecurve.h index 4fb9a8704..d33afb269 100644 --- a/src/app/visualization/vsimplecurve.h +++ b/src/app/visualization/vsimplecurve.h @@ -45,6 +45,9 @@ public: qreal *factor = nullptr, QObject *parent = 0); void ChangedActivDraw(const bool &flag); virtual void paint(QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget = 0); + + virtual int type() const {return Type;} + enum { Type = UserType + static_cast(Vis::SimpleSplinePath)}; signals: /** * @brief Choosed send id when clicked. diff --git a/src/app/visualization/vsimplesplinepath.cpp b/src/app/visualization/vsimplesplinepath.cpp deleted file mode 100644 index 68ca539be..000000000 --- a/src/app/visualization/vsimplesplinepath.cpp +++ /dev/null @@ -1,94 +0,0 @@ -/************************************************************************ - ** - ** @file vsimplesplinepath.cpp - ** @author Roman Telezhynskyi - ** @date 17 12, 2013 - ** - ** @brief - ** @copyright - ** This source code is part of the Valentine project, a pattern making - ** program, whose allow create and modeling patterns of clothing. - ** Copyright (C) 2013 Valentina project - ** All Rights Reserved. - ** - ** Valentina 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. - ** - ** Valentina 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 for more details. - ** - ** You should have received a copy of the GNU General Public License - ** along with Valentina. If not, see . - ** - *************************************************************************/ - -#include "vsimplesplinepath.h" -#include "../widgets/vapplication.h" -#include -#include -#include - -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief VSimpleSplinePath constructor. - * @param doc dom document container. - * @param data container with variables. - * @param id spline path id. - * @param factor scale factor. - */ -VSimpleSplinePath::VSimpleSplinePath(VPattern *doc, VContainer *data, quint32 id, qreal *factor) - :VAbstractTool(doc, data, id), QGraphicsPathItem(), factor(factor) -{} - -//--------------------------------------------------------------------------------------------------------------------- -void VSimpleSplinePath::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) -{ - /* From question on StackOverflow - * https://stackoverflow.com/questions/10985028/how-to-remove-border-around-qgraphicsitem-when-selected - * - * There's no interface to disable the drawing of the selection border for the build-in QGraphicsItems. The only way - * I can think of is derive your own items from the build-in ones and override the paint() function:*/ - QStyleOptionGraphicsItem myOption(*option); - myOption.state &= ~QStyle::State_Selected; - QGraphicsPathItem::paint(painter, &myOption, widget); -} - -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief mouseReleaseEvent handle mouse release events. - * @param event mouse release event. - */ -void VSimpleSplinePath::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) -{ - if (event->button() == Qt::LeftButton) - { - emit ChoosedTool(id, SceneObject::SplinePath); - } - QGraphicsPathItem::mouseReleaseEvent(event); -} - -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief hoverMoveEvent handle hover move events. - * @param event hover move event. - */ -void VSimpleSplinePath::hoverMoveEvent(QGraphicsSceneHoverEvent *event) -{ - Q_UNUSED(event); - this->setPen(QPen(currentColor, qApp->toPixel(qApp->widthMainLine())/ *factor)); -} - -//--------------------------------------------------------------------------------------------------------------------- -/** - * @brief hoverLeaveEvent handle hover leave events. - * @param event hover leave event. - */ -void VSimpleSplinePath::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) -{ - Q_UNUSED(event); - this->setPen(QPen(currentColor, qApp->toPixel(qApp->widthHairLine())/ *factor)); -} diff --git a/src/app/widgets/vapplication.cpp b/src/app/widgets/vapplication.cpp index ecd8e5c0f..f7399e2d8 100644 --- a/src/app/widgets/vapplication.cpp +++ b/src/app/widgets/vapplication.cpp @@ -58,7 +58,7 @@ VApplication::VApplication(int &argc, char **argv) guiTexts(QMap()), descriptions(QMap()), variables(QMap()), functions(QMap()), postfixOperators(QMap()), undoStack(nullptr), sceneView(nullptr), currentScene(nullptr), - autoSaveTimer(nullptr), mainWindow(nullptr), openingPattern(false), settings(nullptr) + autoSaveTimer(nullptr), mainWindow(nullptr), openingPattern(false), settings(nullptr), doc(nullptr) { undoStack = new QUndoStack(this); diff --git a/src/app/widgets/vapplication.h b/src/app/widgets/vapplication.h index 8cdbb5e11..a80b72fe5 100644 --- a/src/app/widgets/vapplication.h +++ b/src/app/widgets/vapplication.h @@ -38,6 +38,7 @@ class VApplication;// used in define class QUndoStack; class VMainGraphicsView; class VMainGraphicsScene; +class VPattern; #if defined(qApp) #undef qApp @@ -91,6 +92,9 @@ public: QSettings *getSettings(); VMainGraphicsScene *getCurrentScene() const; void setCurrentScene(VMainGraphicsScene *value); + + void setCurrentDocument(VPattern *doc); + VPattern *getCurrentDocument()const; private: Q_DISABLE_COPY(VApplication) Unit _patternUnit; @@ -121,6 +125,8 @@ private: * @brief settings pointer to settings. Help hide constructor creation settings. Make make code more readable. */ QSettings *settings; + + VPattern *doc; void InitLineWidth(); void InitMeasurements(); void InitVariables(); @@ -197,4 +203,17 @@ inline void VApplication::setAutoSaveTimer(QTimer *value) autoSaveTimer = value; } +//--------------------------------------------------------------------------------------------------------------------- +inline void VApplication::setCurrentDocument(VPattern *doc) +{ + this->doc = doc; +} + +//--------------------------------------------------------------------------------------------------------------------- +inline VPattern *VApplication::getCurrentDocument() const +{ + SCASSERT(doc != nullptr) + return doc; +} + #endif // VAPPLICATION_H diff --git a/src/app/widgets/vformulaproperty.cpp b/src/app/widgets/vformulaproperty.cpp new file mode 100644 index 000000000..d01a91621 --- /dev/null +++ b/src/app/widgets/vformulaproperty.cpp @@ -0,0 +1,207 @@ +/************************************************************************ + ** + ** @file vformulaproperty.cpp + ** @author Roman Telezhynskyi + ** @date 28 8, 2014 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2014 Valentina project + ** All Rights Reserved. + ** + ** Valentina 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. + ** + ** Valentina 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 for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with Valentina. If not, see . + ** + *************************************************************************/ + +#include "vformulaproperty.h" +#include "vformulapropertyeditor.h" + +#include "../libs/vpropertyexplorer/vproperty_p.h" +#include "vformulapropertyeditor.h" +#include "../libs/vpropertyexplorer/vproperties.h" +#include "../container/vformula.h" + +enum class ChildType : char {Invalid = 0, Value = 1, Formula = 2}; + +using namespace VPE; + +//--------------------------------------------------------------------------------------------------------------------- +VFormulaProperty::VFormulaProperty(const QString &name) : + VProperty(name, static_cast(VFormula::FormulaTypeId())) +{ + d_ptr->type = Property::Complex; + + VStringProperty* tmpValue = new VStringProperty(QStringLiteral("Value")); + addChild(tmpValue); + tmpValue->setUpdateBehaviour(true, false); + tmpValue->setReadOnly(true); + tmpValue->setTypeForParent(static_cast(ChildType::Value)); + + VStringProperty* tmpFormula = new VStringProperty(QStringLiteral("Formula")); + addChild(tmpFormula); + tmpFormula->setUpdateBehaviour(true, false); + tmpFormula->setTypeForParent(static_cast(ChildType::Formula)); + + setValue(0); +} + +//--------------------------------------------------------------------------------------------------------------------- +//! Get the data how it should be displayed +QVariant VFormulaProperty::data (int column, int role) const +{ + if(column == DPC_Data && (Qt::DisplayRole == role || Qt::EditRole == role)) + return getValue(); + else + return VProperty::data(column, role); +} + +Qt::ItemFlags VFormulaProperty::flags(int column) const +{ + if(column == DPC_Name || column == DPC_Data) + return Qt::ItemIsEnabled | Qt::ItemIsSelectable; + else + return Qt::NoItemFlags; +} + +//--------------------------------------------------------------------------------------------------------------------- +//! Returns an editor widget, or NULL if it doesn't supply one +QWidget* VFormulaProperty::createEditor(QWidget* parent, const QStyleOptionViewItem& options, + const QAbstractItemDelegate* delegate) +{ + Q_UNUSED(options); + Q_UNUSED(delegate); + + VFormula formula = VProperty::d_ptr->VariantValue.value(); + VFormulaPropertyEditor* tmpEditor = new VFormulaPropertyEditor(parent); + + tmpEditor->setFormula(formula); + VProperty::d_ptr->editor = tmpEditor; + return VProperty::d_ptr->editor; +} + +//--------------------------------------------------------------------------------------------------------------------- +//! Sets the property's data to the editor (returns false, if the standard delegate should do that) +bool VFormulaProperty::setEditorData(QWidget* editor) +{ + VFormulaPropertyEditor* tmpWidget = qobject_cast(editor); + if(tmpWidget) + { + VFormula formula = VProperty::d_ptr->VariantValue.value(); + tmpWidget->setFormula(formula); + } + else + return false; + + return true; +} + +//--------------------------------------------------------------------------------------------------------------------- +//! Gets the data from the widget +QVariant VFormulaProperty::getEditorData(QWidget* editor) const +{ + VFormulaPropertyEditor* tmpWidget = qobject_cast(editor); + if(tmpWidget) + { + QVariant value; + value.setValue(tmpWidget->getFormula()); + return value; + } + + return QVariant(); +} + +//--------------------------------------------------------------------------------------------------------------------- +QString VFormulaProperty::type() const +{ + return "formula"; +} + +//--------------------------------------------------------------------------------------------------------------------- +VProperty *VFormulaProperty::clone(bool include_children, VProperty *container) const +{ + if(!container) { + container = new VFormulaProperty(getName()); + + if(!include_children) { + QList tmpChildren = container->getChildren(); + foreach(VProperty* tmpChild, tmpChildren) { + container->removeChild(tmpChild); + delete tmpChild; + } + } + } + + return VProperty::clone(false, container); // Child + +} + +//--------------------------------------------------------------------------------------------------------------------- +void VFormulaProperty::setValue(const QVariant &value) +{ + VFormula tmpFormula = value.value(); + setFormula(tmpFormula); +} + +//--------------------------------------------------------------------------------------------------------------------- +QVariant VFormulaProperty::getValue() const +{ + VFormula tmpFormula = getFormula(); + QVariant value; + value.setValue(tmpFormula); + return value; +} + +//--------------------------------------------------------------------------------------------------------------------- +VFormula VFormulaProperty::getFormula() const +{ + return VProperty::d_ptr->VariantValue.value(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VFormulaProperty::setFormula(const VFormula &formula) +{ + if(d_ptr->Children.count() < 2) + return; + + QVariant value; + value.setValue(formula); + value.convert(VFormula::FormulaTypeId()); + VProperty::d_ptr->VariantValue = value; + + QVariant tmpValue(formula.getStringValue()); + tmpValue.convert(QVariant::String); + + QVariant tmpFormula(formula.getFormula()); + tmpFormula.convert(QVariant::String); + + VProperty::d_ptr->Children.at(0)->setValue(tmpValue); + VProperty::d_ptr->Children.at(1)->setValue(tmpFormula); + + if (VProperty::d_ptr->editor != nullptr) + { + setEditorData(VProperty::d_ptr->editor); + } +} + +void VFormulaProperty::ValueChildChanged(const QVariant &value, int typeForParent) +{ + if (typeForParent == static_cast(ChildType::Formula)) + { + VFormula newFormula = getFormula(); + newFormula.setFormula(value.toString()); + setFormula(newFormula); + } +} diff --git a/src/app/widgets/vformulaproperty.h b/src/app/widgets/vformulaproperty.h new file mode 100644 index 000000000..848e698b8 --- /dev/null +++ b/src/app/widgets/vformulaproperty.h @@ -0,0 +1,88 @@ +/************************************************************************ + ** + ** @file vformulaproperty.h + ** @author Roman Telezhynskyi + ** @date 28 8, 2014 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2014 Valentina project + ** All Rights Reserved. + ** + ** Valentina 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. + ** + ** Valentina 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 for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with Valentina. If not, see . + ** + *************************************************************************/ + +#ifndef VFORMULAPROPERTY_H +#define VFORMULAPROPERTY_H + +#include "../libs/vpropertyexplorer/vproperty.h" + +class VFormula; + +using namespace VPE; + +class VFormulaProperty : public VProperty +{ + +public: + VFormulaProperty(const QString &name); + + //! Get the data how it should be displayed + virtual QVariant data (int column = DPC_Name, int role = Qt::DisplayRole) const; + + //! Returns item flags + Qt::ItemFlags flags(int column = DPC_Name) const; + + //! Returns an editor widget, or NULL if it doesn't supply one + //! \param parent The widget to which the editor will be added as a child + //! \options Render options + //! \delegate A pointer to the QAbstractItemDelegate requesting the editor. This can be used to connect signals and slots. + virtual QWidget* createEditor(QWidget* parent, const QStyleOptionViewItem& options, const QAbstractItemDelegate* delegate); + + //! Sets the property's data to the editor (returns false, if the standard delegate should do that) + virtual bool setEditorData(QWidget* editor); + + //! Gets the data from the widget + virtual QVariant getEditorData(QWidget* editor) const; + + //! Returns a string containing the type of the property + virtual QString type() const; + + //! Clones this property + //! \param include_children Indicates whether to also clone the children + //! \param container If a property is being passed here, no new VProperty is being created but instead it is tried to fill all the data into container. This can also be used when subclassing this function. + //! \return Returns the newly created property (or container, if it was not NULL) + virtual VProperty* clone(bool include_children = true, VProperty* container = NULL) const; + + //! Sets the value of the property + virtual void setValue(const QVariant& value); + + //! Returns the value of the property as a QVariant + virtual QVariant getValue() const; + + //! Returns the formula + virtual VFormula getFormula() const; + + //! Sets the formula + virtual void setFormula(const VFormula &formula); + +public slots: + virtual void ValueChildChanged(const QVariant &value, int typeForParent); + +}; + +#endif // VFORMULAPROPERTY_H diff --git a/src/app/widgets/vformulapropertyeditor.cpp b/src/app/widgets/vformulapropertyeditor.cpp new file mode 100644 index 000000000..b445e9715 --- /dev/null +++ b/src/app/widgets/vformulapropertyeditor.cpp @@ -0,0 +1,128 @@ +/************************************************************************ + ** + ** @file vformulapropertyeditor.cpp + ** @author Roman Telezhynskyi + ** @date 28 8, 2014 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2014 Valentina project + ** All Rights Reserved. + ** + ** Valentina 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. + ** + ** Valentina 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 for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with Valentina. If not, see . + ** + *************************************************************************/ + +#include "vformulapropertyeditor.h" + +#include +#include +#include +#include +#include + +#include "../libs/vpropertyexplorer/vproperty.h" +#include "../dialogs/tools/dialogeditwrongformula.h" + +using namespace VPE; + +// VFormulaPropertyEditor +//--------------------------------------------------------------------------------------------------------------------- +VFormulaPropertyEditor::VFormulaPropertyEditor(QWidget *parent) : + QWidget(parent) +{ + setAutoFillBackground(true); + + // Create the tool button + ToolButton = new QToolButton(this); + ToolButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Minimum); + ToolButton->setText(tr("...")); + ToolButton->setFixedWidth(20); + ToolButton->installEventFilter(this); + setFocusProxy(ToolButton); // Make the ToolButton the focus proxy + setFocusPolicy(ToolButton->focusPolicy()); + connect(ToolButton, SIGNAL(clicked()), this, SLOT(onToolButtonClicked())); + + // Create the text label + TextLabel = new QLabel(this); + TextLabel->setText(formula.getStringValue()); + + // Spacer (this is needed for proper display of the label and button) + Spacer = new QSpacerItem(1, 0, QSizePolicy::Expanding, QSizePolicy::Ignored); + + // The layout (a horizontal layout) + QHBoxLayout* layout = new QHBoxLayout(this); + layout->setSpacing(3); + layout->setMargin(0); + layout->addWidget(TextLabel); + layout->addItem(Spacer); + layout->addWidget(ToolButton); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VFormulaPropertyEditor::setFormula(const VFormula& formula) +{ + if (this->formula != formula) + { + this->formula = formula; + TextLabel->setText(this->formula.getStringValue()); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VFormulaPropertyEditor::onToolButtonClicked() +{ + DialogEditWrongFormula* tmpWidget = new DialogEditWrongFormula(formula.getData(), formula.getToolId(), + qApp->getMainWindow()); + tmpWidget->setCheckZero(formula.getCheckZero()); + tmpWidget->setPostfix(formula.getPostfix()); + tmpWidget->setFormula(formula.getFormula(FormulaType::FromUser)); + + if (tmpWidget->exec() == QDialog::Accepted) + { + formula.setFormula(tmpWidget->getFormula(), FormulaType::ToUser); + TextLabel->setText(formula.getStringValue()); + delete tmpWidget; + emit dataChangedByUser(formula, this); + UserChangeEvent *event = new UserChangeEvent(); + QCoreApplication::postEvent ( this, event ); + } +} + +//--------------------------------------------------------------------------------------------------------------------- +bool VFormulaPropertyEditor::eventFilter(QObject *obj, QEvent *ev) +{ + if(obj == ToolButton && (ev->type() == QEvent::KeyPress || ev->type() == QEvent::KeyPress)) + { + // Ignore the event, so that eventually the delegate gets the event. + ev->ignore(); + return true; + } + + return QWidget::eventFilter(obj, ev); +} + +//--------------------------------------------------------------------------------------------------------------------- +VFormulaPropertyEditor::~VFormulaPropertyEditor() +{ + // +} + +//--------------------------------------------------------------------------------------------------------------------- +VFormula VFormulaPropertyEditor::getFormula() +{ + return formula; +} diff --git a/src/app/widgets/vformulapropertyeditor.h b/src/app/widgets/vformulapropertyeditor.h new file mode 100644 index 000000000..622facc76 --- /dev/null +++ b/src/app/widgets/vformulapropertyeditor.h @@ -0,0 +1,78 @@ +/************************************************************************ + ** + ** @file vformulapropertyeditor.h + ** @author Roman Telezhynskyi + ** @date 28 8, 2014 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2014 Valentina project + ** All Rights Reserved. + ** + ** Valentina 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. + ** + ** Valentina 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 for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with Valentina. If not, see . + ** + *************************************************************************/ + +#ifndef VFORMULAPROPERTYEDITOR_H +#define VFORMULAPROPERTYEDITOR_H + +#include +#include +#include +#include +#include + +#include "../container/vformula.h" + +class VFormulaPropertyEditor : public QWidget +{ + Q_OBJECT + +public: + //! Constructor taking a widget as parent + VFormulaPropertyEditor(QWidget *parent); + + //! Destructor + virtual ~VFormulaPropertyEditor(); + + //! Returns the formula currently set + VFormula getFormula(); + + //! Needed for proper event handling + bool eventFilter(QObject *obj, QEvent *ev); + +signals: + //! This is emitted, when the user changes the color + void dataChangedByUser(const VFormula &getFormula, VFormulaPropertyEditor* editor); + + void dataChanged(); + +public slots: + //! Sets the color of the widget + void setFormula(const VFormula &formula); + +private slots: + void onToolButtonClicked(); + +private: + VFormula formula; + QToolButton* ToolButton; + QLabel* TextLabel; + QSpacerItem* Spacer; +}; + + +#endif // VFORMULAPROPERTYEDITOR_H diff --git a/src/app/widgets/vmaingraphicsview.cpp b/src/app/widgets/vmaingraphicsview.cpp index 46ad814ac..07c61aaa5 100644 --- a/src/app/widgets/vmaingraphicsview.cpp +++ b/src/app/widgets/vmaingraphicsview.cpp @@ -33,7 +33,9 @@ #include #include #include "../tools/vabstracttool.h" +#include "../visualization/vsimplecurve.h" +#include #include #include @@ -157,7 +159,7 @@ bool GraphicsViewZoom::eventFilter(QObject *object, QEvent *event) * @param parent parent object. */ VMainGraphicsView::VMainGraphicsView(QWidget *parent) - :QGraphicsView(parent), zoom(nullptr) + :QGraphicsView(parent), zoom(nullptr), showToolOptions(true) { zoom = new GraphicsViewZoom(this); this->setResizeAnchor(QGraphicsView::AnchorUnderMouse); @@ -220,6 +222,24 @@ void VMainGraphicsView::mousePressEvent(QMouseEvent *mousePress) case Qt::ControlModifier: QGraphicsView::setDragMode(QGraphicsView::ScrollHandDrag); break; + case Qt::NoModifier: + if (showToolOptions) + { + QList list = items(mousePress->pos()); + if (list.size() == 0) + { + emit itemClicked(nullptr); + break; + } + for (int i = 0; i < list.size(); ++i) + { + if (list.at(i)->type() <= VSimpleCurve::Type && list.at(i)->type() > QGraphicsItem::UserType) + { + emit itemClicked(list.at(i)); + } + } + } + break; default: break; } @@ -241,3 +261,10 @@ void VMainGraphicsView::mouseReleaseEvent(QMouseEvent *event) emit MouseRelease(); } } + +//--------------------------------------------------------------------------------------------------------------------- +void VMainGraphicsView::setShowToolOptions(bool value) +{ + showToolOptions = value; +} + diff --git a/src/app/widgets/vmaingraphicsview.h b/src/app/widgets/vmaingraphicsview.h index e34baf781..810b83427 100644 --- a/src/app/widgets/vmaingraphicsview.h +++ b/src/app/widgets/vmaingraphicsview.h @@ -84,6 +84,7 @@ private: bool eventFilter(QObject* object, QEvent* event); private: + Q_DISABLE_COPY(GraphicsViewZoom) /** @brief _numScheduledScalings keep number scheduled scalings. */ qint32 _numScheduledScalings; }; @@ -97,6 +98,8 @@ class VMainGraphicsView : public QGraphicsView public: explicit VMainGraphicsView(QWidget *parent = nullptr); + void setShowToolOptions(bool value); + signals: /** * @brief NewFactor send new scale factor. @@ -108,7 +111,8 @@ signals: * * Usefull when you need show dialog after working with tool visualization. */ - void MouseRelease(); + void MouseRelease(); + void itemClicked(QGraphicsItem *item); public slots: void ZoomIn(); void ZoomOut(); @@ -118,7 +122,9 @@ protected: void mousePressEvent(QMouseEvent *mousePress); void mouseReleaseEvent(QMouseEvent *event); private: + Q_DISABLE_COPY(VMainGraphicsView) GraphicsViewZoom* zoom; + bool showToolOptions; }; #endif // VMAINGRAPHICSVIEW_H diff --git a/src/app/widgets/vtooloptionspropertybrowser.cpp b/src/app/widgets/vtooloptionspropertybrowser.cpp new file mode 100644 index 000000000..e55e5bd51 --- /dev/null +++ b/src/app/widgets/vtooloptionspropertybrowser.cpp @@ -0,0 +1,1317 @@ +/************************************************************************ + ** + ** @file vtooloptionspropertybrowser.cpp + ** @author Roman Telezhynskyi + ** @date 22 8, 2014 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2014 Valentina project + ** All Rights Reserved. + ** + ** Valentina 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. + ** + ** Valentina 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 for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with Valentina. If not, see . + ** + *************************************************************************/ + +#include "vtooloptionspropertybrowser.h" +#include "tools/drawTools/drawtools.h" +#include "widgets/vapplication.h" +#include "widgets/vmaingraphicsview.h" +#include "visualization/vgraphicssimpletextitem.h" +#include "visualization/vcontrolpointspline.h" +#include "../libs/vpropertyexplorer/vproperties.h" +#include "vformulaproperty.h" +#include "../container/vformula.h" + +#include +#include + +using namespace VPE; + +//--------------------------------------------------------------------------------------------------------------------- +VToolOptionsPropertyBrowser::VToolOptionsPropertyBrowser(QDockWidget *parent) + :QObject(parent), + currentItem(nullptr), + propertyToId(QMap()), + idToProperty(QMap()) +{ + PropertyModel = new VPropertyModel(this); + formView = new VPropertyFormView(PropertyModel, parent); + formView->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); + + QScrollArea *scroll = new QScrollArea(parent); + scroll->setWidgetResizable(true); + scroll->setWidget(formView); + + parent->setWidget(scroll); + + connect(PropertyModel, SIGNAL(onDataChangedByEditor(VProperty*)), this, SLOT(userChangedData(VProperty*))); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolOptionsPropertyBrowser::ShowItemOptions(QGraphicsItem *item) +{ + switch (item->type()) + { + case VToolSinglePoint::Type: + ShowOptionsToolSinglePoint(item); + break; + case VToolEndLine::Type: + ShowOptionsToolEndLine(item); + break; + case VToolAlongLine::Type: + ShowOptionsToolAlongLine(item); + break; + case VToolArc::Type: + ShowOptionsToolArc(item); + break; + case VToolBisector::Type: + ShowOptionsToolBisector(item); + break; + case VToolCutArc::Type: + ShowOptionsToolCutArc(item); + break; + case VToolCutSpline::Type: + ShowOptionsToolCutSpline(item); + break; + case VToolCutSplinePath::Type: + ShowOptionsToolCutSplinePath(item); + break; + case VToolHeight::Type: + ShowOptionsToolHeight(item); + break; + case VToolLine::Type: + ShowOptionsToolLine(item); + break; + case VToolLineIntersect::Type: + ShowOptionsToolLineIntersect(item); + break; + case VToolNormal::Type: + ShowOptionsToolNormal(item); + break; + case VToolPointOfContact::Type: + ShowOptionsToolPointOfContact(item); + break; + case VToolPointOfIntersection::Type: + ShowOptionsToolPointOfIntersection(item); + break; + case VToolShoulderPoint::Type: + ShowOptionsToolShoulderPoint(item); + break; + case VToolSpline::Type: + ShowOptionsToolSpline(item); + break; + case VToolSplinePath::Type: + ShowOptionsToolSplinePath(item); + break; + case VToolTriangle::Type: + ShowOptionsToolTriangle(item); + break; + case VGraphicsSimpleTextItem::Type: + currentItem = item->parentItem(); + ShowItemOptions(currentItem); + break; + case VControlPointSpline::Type: + currentItem = item->parentItem(); + ShowItemOptions(currentItem); + break; + case VSimpleCurve::Type: + currentItem = item->parentItem(); + ShowItemOptions(currentItem); + break; + default: + break; + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolOptionsPropertyBrowser::UpdateOptions() +{ + if (currentItem == nullptr) + { + return; + } + + switch (currentItem->type()) + { + case VToolSinglePoint::Type: + UpdateOptionsToolSinglePoint(); + break; + case VToolEndLine::Type: + UpdateOptionsToolEndLine(); + break; + case VToolAlongLine::Type: + UpdateOptionsToolAlongLine(); + break; + case VToolArc::Type: + UpdateOptionsToolArc(); + break; + case VToolBisector::Type: + UpdateOptionsToolBisector(); + break; + case VToolCutArc::Type: + UpdateOptionsToolCutArc(); + break; + case VToolCutSpline::Type: + UpdateOptionsToolCutSpline(); + break; + case VToolCutSplinePath::Type: + UpdateOptionsToolCutSplinePath(); + break; + case VToolHeight::Type: + UpdateOptionsToolHeight(); + break; + case VToolLine::Type: + UpdateOptionsToolLine(); + break; + case VToolLineIntersect::Type: + UpdateOptionsToolLineIntersect(); + break; + case VToolNormal::Type: + UpdateOptionsToolNormal(); + break; + case VToolPointOfContact::Type: + UpdateOptionsToolPointOfContact(); + break; + case VToolPointOfIntersection::Type: + UpdateOptionsToolPointOfIntersection(); + break; + case VToolShoulderPoint::Type: + UpdateOptionsToolShoulderPoint(); + break; + case VToolSpline::Type: + UpdateOptionsToolSpline(); + break; + case VToolSplinePath::Type: + UpdateOptionsToolSplinePath(); + break; + case VToolTriangle::Type: + UpdateOptionsToolTriangle(); + break; + case VGraphicsSimpleTextItem::Type: + ShowItemOptions(currentItem->parentItem()); + break; + case VControlPointSpline::Type: + ShowItemOptions(currentItem->parentItem()); + break; + default: + break; + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolOptionsPropertyBrowser::userChangedData(VProperty *property) +{ + VProperty *prop = property; + if (!propertyToId.contains(prop)) + { + if (!propertyToId.contains(prop->getParent()))// Maybe we know parent + { + return; + } + else + { + prop = prop->getParent(); + } + } + + if (!currentItem) + { + return; + } + + switch (currentItem->type()) + { + case VToolSinglePoint::Type: + ChangeDataToolSinglePoint(prop); + break; + case VToolEndLine::Type: + ChangeDataToolEndLine(prop); + break; + case VToolAlongLine::Type: + ChangeDataToolAlongLine(prop); + break; + case VToolArc::Type: + ChangeDataToolArc(prop); + break; + case VToolBisector::Type: + ChangeDataToolBisector(prop); + break; + case VToolCutArc::Type: + ChangeDataToolCutArc(prop); + break; + case VToolCutSpline::Type: + ChangeDataToolCutSpline(prop); + break; + case VToolCutSplinePath::Type: + ChangeDataToolCutSplinePath(prop); + break; + case VToolHeight::Type: + ChangeDataToolHeight(prop); + break; + case VToolLine::Type: + ChangeDataToolLine(prop); + break; + case VToolLineIntersect::Type: + ChangeDataToolLineIntersect(prop); + break; + case VToolNormal::Type: + ChangeDataToolNormal(prop); + break; + case VToolPointOfContact::Type: + ChangeDataToolPointOfContact(prop); + break; + case VToolPointOfIntersection::Type: + ChangeDataToolPointOfIntersection(prop); + break; + case VToolShoulderPoint::Type: + ChangeDataToolShoulderPoint(prop); + break; + case VToolSpline::Type: + ChangeDataToolSpline(prop); + break; + case VToolSplinePath::Type: + ChangeDataToolSplinePath(prop); + break; + case VToolTriangle::Type: + ChangeDataToolTriangle(prop); + break; + default: + break; + } + qApp->getSceneView()->update(); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolOptionsPropertyBrowser::itemClicked(QGraphicsItem *item) +{ + if (currentItem == item) + { + UpdateOptions(); + return; + } + + PropertyModel->clear(); + propertyToId.clear(); + idToProperty.clear(); + + VAbstractTool *previousTool = dynamic_cast(currentItem); + if (previousTool != nullptr) + { + previousTool->ShowVisualization(false); // hide for previous tool + } + + currentItem = item; + if (currentItem == nullptr) + { + formView->setTitle(""); + return; + } + + ShowItemOptions(currentItem); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolOptionsPropertyBrowser::AddPropertyFormula(const QString &propertyName, const VFormula &formula, + const QString &attrName) +{ + VFormulaProperty* itemLength = new VFormulaProperty(propertyName); + itemLength->setFormula(formula); + AddProperty(itemLength, attrName); +} + +//--------------------------------------------------------------------------------------------------------------------- +template +void VToolOptionsPropertyBrowser::AddPropertyPointName(Tool *i, const QString &propertyName) +{ + VProperty* itemName = new VProperty(propertyName); + itemName->setValue(i->name()); + AddProperty(itemName, VAbstractTool::AttrName); +} + +//--------------------------------------------------------------------------------------------------------------------- +template +void VToolOptionsPropertyBrowser::AddPropertyLineType(Tool *i, const QString &propertyName) +{ + VEnumProperty *lineTypeProperty = new VEnumProperty(propertyName); + QStringList styles = VAbstractTool::Styles(); + lineTypeProperty->setLiterals(styles); + qint32 index = styles.indexOf(i->getLineType()); + if (index == -1) + { + qWarning()<<"Can't find line style" << i->getLineType()<<"in list"; + } + lineTypeProperty->setValue(index); + AddProperty(lineTypeProperty, VAbstractTool::AttrTypeLine); +} + +//--------------------------------------------------------------------------------------------------------------------- +template +void VToolOptionsPropertyBrowser::SetPointName(const QString &name) +{ + if (Tool *i = qgraphicsitem_cast(currentItem)) + { + if (name == i->name()) + { + return; + } + + QRegExp rx(nameRegExp); + if (name.isEmpty() || VContainer::IsUnique(name) == false || rx.exactMatch(name) == false) + { + idToProperty[VAbstractTool::AttrName]->setValue(i->name()); + } + else + { + i->setName(name); + } + } + else + { + qWarning()<<"Can't cast item"; + } +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolOptionsPropertyBrowser::AddProperty(VProperty *property, const QString &id) +{ + propertyToId[property] = id; + idToProperty[id] = property; + PropertyModel->addProperty(property, id); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolOptionsPropertyBrowser::ChangeDataToolSinglePoint(VProperty *property) +{ + SCASSERT(property != nullptr) + + QVariant value = property->data(VProperty::DPC_Data, Qt::DisplayRole); + const QString id = propertyToId[property]; + + switch (PropertiesList().indexOf(id)) + { + case 0: // VAbstractTool::AttrName + SetPointName(value.toString()); + break; + case 1: // QLatin1String("position") + currentItem->setPos(value.toPointF()); + break; + default: + qWarning()<<"Unknown property type. id = "<data(VProperty::DPC_Data, Qt::DisplayRole); + const QString id = propertyToId[property]; + + VToolEndLine *i = qgraphicsitem_cast(currentItem); + SCASSERT(i != nullptr); + switch (PropertiesList().indexOf(id)) + { + case 0: // VAbstractTool::AttrName + SetPointName(value.toString()); + break; + case 3: // VAbstractTool::AttrTypeLine + i->setTypeLine(value.toString()); + break; + case 4: // VAbstractTool::AttrLength + i->setFormulaLength(value.value()); + break; + case 5: // VAbstractTool::AttrAngle + i->setFormulaAngle(value.value()); + break; + default: + qWarning()<<"Unknown property type. id = "<data(VProperty::DPC_Data, Qt::DisplayRole); + const QString id = propertyToId[property]; + + VToolAlongLine *i = qgraphicsitem_cast(currentItem); + SCASSERT(i != nullptr); + switch (PropertiesList().indexOf(id)) + { + case 0: // VAbstractTool::AttrName + SetPointName(value.toString()); + break; + case 3: // VAbstractTool::AttrTypeLine + i->setTypeLine(value.toString()); + break; + case 4: // VAbstractTool::AttrLength + i->setFormulaLength(value.value()); + break; + default: + qWarning()<<"Unknown property type. id = "<data(VProperty::DPC_Data, Qt::DisplayRole); + const QString id = propertyToId[property]; + + VToolArc *i = qgraphicsitem_cast(currentItem); + SCASSERT(i != nullptr); + switch (PropertiesList().indexOf(id)) + { + case 8: // VAbstractTool::AttrRadius + i->setFormulaRadius(value.value()); + break; + case 9: // VAbstractTool::AttrAngle1 + i->setFormulaF1(value.value()); + break; + case 10: // VAbstractTool::AttrAngle2 + i->setFormulaF2(value.value()); + break; + default: + qWarning()<<"Unknown property type. id = "<data(VProperty::DPC_Data, Qt::DisplayRole); + const QString id = propertyToId[property]; + + VToolBisector *i = qgraphicsitem_cast(currentItem); + SCASSERT(i != nullptr); + switch (PropertiesList().indexOf(id)) + { + case 0: // VAbstractTool::AttrName + SetPointName(value.toString()); + break; + case 4: // VAbstractTool::AttrLength + i->setFormulaLength(value.value()); + break; + case 3: // VAbstractTool::AttrTypeLine + i->setTypeLine(value.toString()); + break; + default: + qWarning()<<"Unknown property type. id = "<data(VProperty::DPC_Data, Qt::DisplayRole); + const QString id = propertyToId[property]; + + VToolCutArc *i = qgraphicsitem_cast(currentItem); + SCASSERT(i != nullptr); + switch (PropertiesList().indexOf(id)) + { + case 0: // VAbstractTool::AttrName + SetPointName(value.toString()); + break; + case 4: // VAbstractTool::AttrLength + i->setFormula(value.value()); + break; + default: + qWarning()<<"Unknown property type. id = "<data(VProperty::DPC_Data, Qt::DisplayRole); + const QString id = propertyToId[property]; + + VToolCutSpline *i = qgraphicsitem_cast(currentItem); + SCASSERT(i != nullptr); + switch (PropertiesList().indexOf(id)) + { + case 0: // VAbstractTool::AttrName + SetPointName(value.toString()); + break; + case 4: // VAbstractTool::AttrLength + i->setFormula(value.value()); + break; + default: + qWarning()<<"Unknown property type. id = "<data(VProperty::DPC_Data, Qt::DisplayRole); + const QString id = propertyToId[property]; + + VToolCutSplinePath *i = qgraphicsitem_cast(currentItem); + SCASSERT(i != nullptr); + switch (PropertiesList().indexOf(id)) + { + case 0: // VAbstractTool::AttrName + SetPointName(value.toString()); + break; + case 4: // VAbstractTool::AttrLength + i->setFormula(value.value()); + break; + default: + qWarning()<<"Unknown property type. id = "<data(VProperty::DPC_Data, Qt::DisplayRole); + const QString id = propertyToId[property]; + + VToolHeight *i = qgraphicsitem_cast(currentItem); + SCASSERT(i != nullptr); + switch (PropertiesList().indexOf(id)) + { + case 0: // VAbstractTool::AttrName + SetPointName(value.toString()); + break; + case 3: // VAbstractTool::AttrTypeLine + i->setTypeLine(value.toString()); + break; + default: + qWarning()<<"Unknown property type. id = "<data(VProperty::DPC_Data, Qt::DisplayRole); + const QString id = propertyToId[property]; + + VToolLine *i = qgraphicsitem_cast(currentItem); + SCASSERT(i != nullptr); + switch (PropertiesList().indexOf(id)) + { + case 3: // VAbstractTool::AttrTypeLine + i->setTypeLine(value.toString()); + break; + default: + qWarning()<<"Unknown property type. id = "<data(VProperty::DPC_Data, Qt::DisplayRole); + const QString id = propertyToId[property]; + + VToolLineIntersect *i = qgraphicsitem_cast(currentItem); + SCASSERT(i != nullptr); + switch (PropertiesList().indexOf(id)) + { + case 0: // VAbstractTool::AttrName + SetPointName(value.toString()); + break; + default: + qWarning()<<"Unknown property type. id = "<data(VProperty::DPC_Data, Qt::DisplayRole); + const QString id = propertyToId[property]; + + VToolNormal *i = qgraphicsitem_cast(currentItem); + SCASSERT(i != nullptr); + switch (PropertiesList().indexOf(id)) + { + case 4: // VAbstractTool::AttrLength + i->setFormulaLength(value.value()); + break; + case 0: // VAbstractTool::AttrName + SetPointName(value.toString()); + break; + case 22: // VAbstractTool::AttrAngle + i->setAngle(value.toDouble()); + break; + case 3: // VAbstractTool::AttrTypeLine + i->setTypeLine(value.toString()); + break; + default: + qWarning()<<"Unknown property type. id = "<data(VProperty::DPC_Data, Qt::DisplayRole); + const QString id = propertyToId[property]; + + VToolPointOfContact *i = qgraphicsitem_cast(currentItem); + SCASSERT(i != nullptr); + switch (PropertiesList().indexOf(id)) + { + case 8: // VAbstractTool::AttrRadius + i->setArcRadius(value.value()); + break; + case 0: // VAbstractTool::AttrName + SetPointName(value.toString()); + break; + default: + qWarning()<<"Unknown property type. id = "<data(VProperty::DPC_Data, Qt::DisplayRole); + const QString id = propertyToId[property]; + + VToolPointOfIntersection *i = qgraphicsitem_cast(currentItem); + SCASSERT(i != nullptr); + switch (PropertiesList().indexOf(id)) + { + case 0: // VAbstractTool::AttrName + SetPointName(value.toString()); + break; + default: + qWarning()<<"Unknown property type. id = "<data(VProperty::DPC_Data, Qt::DisplayRole); + const QString id = propertyToId[property]; + + VToolShoulderPoint *i = qgraphicsitem_cast(currentItem); + SCASSERT(i != nullptr); + switch (PropertiesList().indexOf(id)) + { + case 4: // VAbstractTool::AttrLength + i->setFormulaLength(value.value()); + break; + case 0: // VAbstractTool::AttrName + SetPointName(value.toString()); + break; + case 3: // VAbstractTool::AttrTypeLine + i->setTypeLine(value.toString()); + break; + default: + qWarning()<<"Unknown property type. id = "<data(VProperty::DPC_Data, Qt::DisplayRole); + const QString id = propertyToId[property]; + + VToolSpline *i = qgraphicsitem_cast(currentItem); + SCASSERT(i != nullptr); + switch (PropertiesList().indexOf(id)) + { + case 26: // VAbstractTool::AttrKCurve + { + VSpline spl = i->getSpline(); + spl.SetKcurve(value.toDouble()); + i->setSpline(spl); + break; + } + default: + qWarning()<<"Unknown property type. id = "<data(VProperty::DPC_Data, Qt::DisplayRole); + const QString id = propertyToId[property]; + + VToolSplinePath *i = qgraphicsitem_cast(currentItem); + SCASSERT(i != nullptr); + switch (PropertiesList().indexOf(id)) + { + case 26: // VAbstractTool::AttrKCurve + { + VSplinePath splPath = i->getSplinePath(); + splPath.setKCurve(value.toDouble()); + i->setSplinePath(splPath); + break; + } + default: + qWarning()<<"Unknown property type. id = "<data(VProperty::DPC_Data, Qt::DisplayRole); + const QString id = propertyToId[property]; + + VToolTriangle *i = qgraphicsitem_cast(currentItem); + SCASSERT(i != nullptr); + switch (PropertiesList().indexOf(id)) + { + case 0: // VAbstractTool::AttrName + SetPointName(value.toString()); + break; + default: + qWarning()<<"Unknown property type. id = "<(item); + i->ShowVisualization(true); + formView->setTitle(tr("Base point")); + + AddPropertyPointName(i, tr("Point label")); + + VPointFProperty* itemPosition = new VPointFProperty(tr("Position")); + itemPosition->setValue(i->pos()); + AddProperty(itemPosition, QLatin1String("position")); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolOptionsPropertyBrowser::ShowOptionsToolEndLine(QGraphicsItem *item) +{ + VToolEndLine *i = qgraphicsitem_cast(item); + i->ShowVisualization(true); + formView->setTitle(tr("Point at distance and angle")); + + AddPropertyPointName(i, tr("Point label")); + AddPropertyLineType(i, tr("Line type")); + AddPropertyFormula(tr("Length"), i->getFormulaLength(), VAbstractTool::AttrLength); + AddPropertyFormula(tr("Angle"), i->getFormulaAngle(), VAbstractTool::AttrAngle); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolOptionsPropertyBrowser::ShowOptionsToolAlongLine(QGraphicsItem *item) +{ + VToolAlongLine *i = qgraphicsitem_cast(item); + i->ShowVisualization(true); + formView->setTitle(tr("Point at distance along line")); + + AddPropertyPointName(i, tr("Point label")); + AddPropertyLineType(i, tr("Line type")); + AddPropertyFormula(tr("Length"), i->getFormulaLength(), VAbstractTool::AttrLength); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolOptionsPropertyBrowser::ShowOptionsToolArc(QGraphicsItem *item) +{ + VToolArc *i = qgraphicsitem_cast(item); + i->ShowVisualization(true); + formView->setTitle(tr("Arc")); + + AddPropertyFormula(tr("Radius"), i->getFormulaRadius(), VAbstractTool::AttrRadius); + AddPropertyFormula(tr("First angle"), i->getFormulaF1(), VAbstractTool::AttrAngle1); + AddPropertyFormula(tr("Second angle"), i->getFormulaF2(), VAbstractTool::AttrAngle2); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolOptionsPropertyBrowser::ShowOptionsToolBisector(QGraphicsItem *item) +{ + VToolBisector *i = qgraphicsitem_cast(item); + i->ShowVisualization(true); + formView->setTitle(tr("Point along bisector")); + + AddPropertyPointName(i, tr("Point label")); + AddPropertyLineType(i, tr("Line type")); + AddPropertyFormula(tr("Length"), i->getFormulaLength(), VAbstractTool::AttrLength); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolOptionsPropertyBrowser::ShowOptionsToolCutArc(QGraphicsItem *item) +{ + VToolCutArc *i = qgraphicsitem_cast(item); + i->ShowVisualization(true); + formView->setTitle(tr("Cut arc tool")); + + AddPropertyPointName(i, tr("Point label")); + AddPropertyFormula(tr("Length"), i->getFormula(), VAbstractTool::AttrLength); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolOptionsPropertyBrowser::ShowOptionsToolCutSpline(QGraphicsItem *item) +{ + VToolCutSpline *i = qgraphicsitem_cast(item); + i->ShowVisualization(true); + formView->setTitle(tr("Tool for segmenting a curve")); + + AddPropertyPointName(i, tr("Point label")); + AddPropertyFormula(tr("Length"), i->getFormula(), VAbstractTool::AttrLength); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolOptionsPropertyBrowser::ShowOptionsToolCutSplinePath(QGraphicsItem *item) +{ + VToolCutSplinePath *i = qgraphicsitem_cast(item); + i->ShowVisualization(true); + formView->setTitle(tr("Tool segment a pathed curve")); + + AddPropertyPointName(i, tr("Point label")); + AddPropertyFormula(tr("Length"), i->getFormula(), VAbstractTool::AttrLength); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolOptionsPropertyBrowser::ShowOptionsToolHeight(QGraphicsItem *item) +{ + VToolHeight *i = qgraphicsitem_cast(item); + i->ShowVisualization(true); + formView->setTitle(tr("Perpendicular point along line")); + + AddPropertyPointName(i, tr("Point label")); + AddPropertyLineType(i, tr("Line type")); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolOptionsPropertyBrowser::ShowOptionsToolLine(QGraphicsItem *item) +{ + VToolLine *i = qgraphicsitem_cast(item); + i->ShowVisualization(true); + formView->setTitle(tr("Line between points")); + + AddPropertyLineType(i, tr("Line type")); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolOptionsPropertyBrowser::ShowOptionsToolLineIntersect(QGraphicsItem *item) +{ + VToolLineIntersect *i = qgraphicsitem_cast(item); + i->ShowVisualization(true); + formView->setTitle(tr("Point at line intersection")); + + AddPropertyPointName(i, tr("Point label")); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolOptionsPropertyBrowser::ShowOptionsToolNormal(QGraphicsItem *item) +{ + VToolNormal *i = qgraphicsitem_cast(item); + i->ShowVisualization(true); + formView->setTitle(tr("Point along perpendicular")); + + AddPropertyFormula(tr("Length"), i->getFormulaLength(), VAbstractTool::AttrLength); + AddPropertyPointName(i, tr("Point label")); + AddPropertyLineType(i, tr("Line type")); + + VDoubleProperty* itemAngle = new VDoubleProperty(tr("Additional angle degrees")); + itemAngle->setValue(i->getAngle()); + itemAngle->setSetting("Min", 0); + itemAngle->setSetting("Max", 360); + itemAngle->setSetting("Precision", 3); + AddProperty(itemAngle, VAbstractTool::AttrAngle); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolOptionsPropertyBrowser::ShowOptionsToolPointOfContact(QGraphicsItem *item) +{ + VToolPointOfContact *i = qgraphicsitem_cast(item); + i->ShowVisualization(true); + formView->setTitle(tr("Point at intersection of arc and line")); + + AddPropertyPointName(i, tr("Point label")); + AddPropertyFormula(tr("Radius"), i->getArcRadius(), VAbstractTool::AttrRadius); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolOptionsPropertyBrowser::ShowOptionsToolPointOfIntersection(QGraphicsItem *item) +{ + VToolPointOfIntersection *i = qgraphicsitem_cast(item); + i->ShowVisualization(true); + formView->setTitle(tr("Tool to make point from x & y of two other points")); + + AddPropertyPointName(i, tr("Point label")); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolOptionsPropertyBrowser::ShowOptionsToolShoulderPoint(QGraphicsItem *item) +{ + VToolShoulderPoint *i = qgraphicsitem_cast(item); + i->ShowVisualization(true); + formView->setTitle(tr("Special point on shoulder")); + + AddPropertyPointName(i, tr("Point label")); + AddPropertyLineType(i, tr("Line type")); + AddPropertyFormula(tr("Length"), i->getFormulaLength(), VAbstractTool::AttrLength); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolOptionsPropertyBrowser::ShowOptionsToolSpline(QGraphicsItem *item) +{ + VToolSpline *i = qgraphicsitem_cast(item); + i->ShowVisualization(true); + formView->setTitle(tr("Curve tool")); + + VDoubleProperty* itemFactor = new VDoubleProperty(tr("Curve factor")); + VSpline spl = i->getSpline(); + itemFactor->setSetting("Min", 0.1); + itemFactor->setSetting("Max", 1000); + itemFactor->setSetting("Step", 0.01); + itemFactor->setSetting("Precision", 3); + itemFactor->setValue(spl.GetKcurve()); + AddProperty(itemFactor, VAbstractTool::AttrKCurve); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolOptionsPropertyBrowser::ShowOptionsToolSplinePath(QGraphicsItem *item) +{ + VToolSplinePath *i = qgraphicsitem_cast(item); + i->ShowVisualization(true); + formView->setTitle(tr("Tool for path curve")); + + VDoubleProperty* itemFactor = new VDoubleProperty(tr("Curve factor")); + VSplinePath splPath = i->getSplinePath(); + itemFactor->setSetting("Min", 0.1); + itemFactor->setSetting("Max", 1000); + itemFactor->setSetting("Step", 0.01); + itemFactor->setSetting("Precision", 3); + itemFactor->setValue(splPath.getKCurve()); + AddProperty(itemFactor, VAbstractTool::AttrKCurve); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolOptionsPropertyBrowser::ShowOptionsToolTriangle(QGraphicsItem *item) +{ + VToolTriangle *i = qgraphicsitem_cast(item); + i->ShowVisualization(true); + formView->setTitle(tr("Tool triangle")); + + AddPropertyPointName(i, tr("Point label")); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolOptionsPropertyBrowser::UpdateOptionsToolSinglePoint() +{ + VToolSinglePoint *i = qgraphicsitem_cast(currentItem); + idToProperty[VAbstractTool::AttrName]->setValue(i->name()); + idToProperty[QLatin1String("position")]->setValue(i->pos()); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolOptionsPropertyBrowser::UpdateOptionsToolEndLine() +{ + VToolEndLine *i = qgraphicsitem_cast(currentItem); + idToProperty[VAbstractTool::AttrName]->setValue(i->name()); + + QStringList styles = VAbstractTool::Styles(); + qint32 index = styles.indexOf(i->getLineType()); + idToProperty[VAbstractTool::AttrTypeLine]->setValue(index); + + QVariant valueFormula; + valueFormula.setValue(i->getFormulaLength()); + idToProperty[VAbstractTool::AttrLength]->setValue(valueFormula); + + QVariant valueAngle; + valueAngle.setValue(i->getFormulaAngle()); + idToProperty[VAbstractTool::AttrAngle]->setValue(valueAngle); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolOptionsPropertyBrowser::UpdateOptionsToolAlongLine() +{ + VToolAlongLine *i = qgraphicsitem_cast(currentItem); + idToProperty[VAbstractTool::AttrName]->setValue(i->name()); + + QStringList styles = VAbstractTool::Styles(); + qint32 index = styles.indexOf(i->getLineType()); + idToProperty[VAbstractTool::AttrTypeLine]->setValue(index); + + QVariant valueFormula; + valueFormula.setValue(i->getFormulaLength()); + idToProperty[VAbstractTool::AttrLength]->setValue(valueFormula); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolOptionsPropertyBrowser::UpdateOptionsToolArc() +{ + VToolArc *i = qgraphicsitem_cast(currentItem); + + + QVariant valueRadius; + valueRadius.setValue(i->getFormulaRadius()); + idToProperty[VAbstractTool::AttrRadius]->setValue(valueRadius); + + QVariant valueFirstAngle; + valueFirstAngle.setValue(i->getFormulaF1()); + idToProperty[VAbstractTool::AttrAngle1]->setValue(valueFirstAngle); + + QVariant valueSecondAngle; + valueSecondAngle.setValue(i->getFormulaF2()); + idToProperty[VAbstractTool::AttrAngle2]->setValue(valueSecondAngle); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolOptionsPropertyBrowser::UpdateOptionsToolBisector() +{ + VToolBisector *i = qgraphicsitem_cast(currentItem); + + idToProperty[VAbstractTool::AttrName]->setValue(i->name()); + + QVariant valueFormula; + valueFormula.setValue(i->getFormulaLength()); + idToProperty[VAbstractTool::AttrLength]->setValue(valueFormula); + + QStringList styles = VAbstractTool::Styles(); + qint32 index = styles.indexOf(i->getLineType()); + idToProperty[VAbstractTool::AttrTypeLine]->setValue(index); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolOptionsPropertyBrowser::UpdateOptionsToolCutArc() +{ + VToolCutArc *i = qgraphicsitem_cast(currentItem); + + idToProperty[VAbstractTool::AttrName]->setValue(i->name()); + + QVariant valueFormula; + valueFormula.setValue(i->getFormula()); + idToProperty[VAbstractTool::AttrLength]->setValue(valueFormula); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolOptionsPropertyBrowser::UpdateOptionsToolCutSpline() +{ + VToolCutSpline *i = qgraphicsitem_cast(currentItem); + + idToProperty[VAbstractTool::AttrName]->setValue(i->name()); + + QVariant valueFormula; + valueFormula.setValue(i->getFormula()); + idToProperty[VAbstractTool::AttrLength]->setValue(valueFormula); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolOptionsPropertyBrowser::UpdateOptionsToolCutSplinePath() +{ + VToolCutSplinePath *i = qgraphicsitem_cast(currentItem); + + idToProperty[VAbstractTool::AttrName]->setValue(i->name()); + + QVariant valueFormula; + valueFormula.setValue(i->getFormula()); + idToProperty[VAbstractTool::AttrLength]->setValue(valueFormula); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolOptionsPropertyBrowser::UpdateOptionsToolHeight() +{ + VToolHeight *i = qgraphicsitem_cast(currentItem); + + idToProperty[VAbstractTool::AttrName]->setValue(i->name()); + + QStringList styles = VAbstractTool::Styles(); + qint32 index = styles.indexOf(i->getLineType()); + idToProperty[VAbstractTool::AttrTypeLine]->setValue(index); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolOptionsPropertyBrowser::UpdateOptionsToolLine() +{ + VToolLine *i = qgraphicsitem_cast(currentItem); + + QStringList styles = VAbstractTool::Styles(); + qint32 index = styles.indexOf(i->getLineType()); + idToProperty[VAbstractTool::AttrTypeLine]->setValue(index); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolOptionsPropertyBrowser::UpdateOptionsToolLineIntersect() +{ + VToolLineIntersect *i = qgraphicsitem_cast(currentItem); + + idToProperty[VAbstractTool::AttrName]->setValue(i->name()); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolOptionsPropertyBrowser::UpdateOptionsToolNormal() +{ + VToolNormal *i = qgraphicsitem_cast(currentItem); + + QVariant valueFormula; + valueFormula.setValue(i->getFormulaLength()); + idToProperty[VAbstractTool::AttrLength]->setValue(valueFormula); + + idToProperty[VAbstractTool::AttrName]->setValue(i->name()); + + idToProperty[VAbstractTool::AttrAngle]->setValue( i->getAngle()); + + QStringList styles = VAbstractTool::Styles(); + qint32 index = styles.indexOf(i->getLineType()); + idToProperty[VAbstractTool::AttrTypeLine]->setValue(index); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolOptionsPropertyBrowser::UpdateOptionsToolPointOfContact() +{ + VToolPointOfContact *i = qgraphicsitem_cast(currentItem); + + QVariant valueFormula; + valueFormula.setValue(i->getArcRadius()); + idToProperty[VAbstractTool::AttrRadius]->setValue(valueFormula); + + idToProperty[VAbstractTool::AttrName]->setValue(i->name()); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolOptionsPropertyBrowser::UpdateOptionsToolPointOfIntersection() +{ + VToolPointOfIntersection *i = qgraphicsitem_cast(currentItem); + + idToProperty[VAbstractTool::AttrName]->setValue(i->name()); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolOptionsPropertyBrowser::UpdateOptionsToolShoulderPoint() +{ + VToolShoulderPoint *i = qgraphicsitem_cast(currentItem); + + QVariant valueFormula; + valueFormula.setValue(i->getFormulaLength()); + idToProperty[VAbstractTool::AttrLength]->setValue(valueFormula); + + idToProperty[VAbstractTool::AttrName]->setValue(i->name()); + + QStringList styles = VAbstractTool::Styles(); + qint32 index = styles.indexOf(i->getLineType()); + idToProperty[VAbstractTool::AttrTypeLine]->setValue(index); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolOptionsPropertyBrowser::UpdateOptionsToolSpline() +{ + VToolSpline *i = qgraphicsitem_cast(currentItem); + + VSpline spl = i->getSpline(); + idToProperty[VAbstractTool::AttrKCurve]->setValue(spl.GetKcurve()); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolOptionsPropertyBrowser::UpdateOptionsToolSplinePath() +{ + VToolSplinePath *i = qgraphicsitem_cast(currentItem); + + VSplinePath splPath = i->getSplinePath(); + idToProperty[VAbstractTool::AttrKCurve]->setValue(splPath.getKCurve()); +} + +//--------------------------------------------------------------------------------------------------------------------- +void VToolOptionsPropertyBrowser::UpdateOptionsToolTriangle() +{ + VToolTriangle *i = qgraphicsitem_cast(currentItem); + + idToProperty[VAbstractTool::AttrName]->setValue(i->name()); +} + +//--------------------------------------------------------------------------------------------------------------------- +QStringList VToolOptionsPropertyBrowser::PropertiesList() const +{ + QStringList attr{VAbstractTool::AttrName, /* 0 */ + QLatin1String("position"), /* 1 */ + VAbstractTool::AttrBasePoint, /* 2 */ + VAbstractTool::AttrTypeLine, /* 3 */ + VAbstractTool::AttrLength, /* 4 */ + VAbstractTool::AttrAngle, /* 5 */ + VAbstractTool::AttrFirstPoint, /* 6 */ + VAbstractTool::AttrSecondPoint, /* 7 */ + VAbstractTool::AttrRadius, /* 8 */ + VAbstractTool::AttrAngle1, /* 9 */ + VAbstractTool::AttrAngle2, /* 10 */ + VAbstractTool::AttrCenter, /* 11 */ + VAbstractTool::AttrThirdPoint, /* 12 */ + VToolCutArc::AttrArc, /* 13 */ + VToolCutSpline::AttrSpline, /* 14 */ + VToolCutSplinePath::AttrSplinePath, /* 15 */ + VAbstractTool::AttrP1Line, /* 16 */ + VAbstractTool::AttrP2Line, /* 17 */ + VAbstractTool::AttrP1Line1, /* 18 */ + VAbstractTool::AttrP2Line1, /* 19 */ + VAbstractTool::AttrP1Line2, /* 20 */ + VAbstractTool::AttrP2Line2, /* 21 */ + VAbstractTool::AttrAngle, /* 22 */ + VAbstractTool::AttrPShoulder, /* 23 */ + VAbstractTool::AttrAxisP1, /* 24 */ + VAbstractTool::AttrAxisP2, /* 25 */ + VAbstractTool::AttrKCurve}; /* 26 */ + return attr; +} diff --git a/src/app/widgets/vtooloptionspropertybrowser.h b/src/app/widgets/vtooloptionspropertybrowser.h new file mode 100644 index 000000000..fd7ad093d --- /dev/null +++ b/src/app/widgets/vtooloptionspropertybrowser.h @@ -0,0 +1,139 @@ +/************************************************************************ + ** + ** @file vtooloptionspropertybrowser.h + ** @author Roman Telezhynskyi + ** @date 22 8, 2014 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2014 Valentina project + ** All Rights Reserved. + ** + ** Valentina 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. + ** + ** Valentina 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 for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with Valentina. If not, see . + ** + *************************************************************************/ + +#ifndef VTOOLOPTIONSPROPERTYBROWSER_H +#define VTOOLOPTIONSPROPERTYBROWSER_H + +#include +#include + +#include "../libs/vpropertyexplorer/vproperty.h" +#include "../libs/vpropertyexplorer/vpropertymodel.h" +#include "../libs/vpropertyexplorer/vpropertyformview.h" + +class QDockWidget; +class QGraphicsItem; +class QScrollArea; +class VFormula; + +using namespace VPE; + +class VToolOptionsPropertyBrowser : public QObject +{ + Q_OBJECT +public: + VToolOptionsPropertyBrowser(QDockWidget *parent); +public slots: + void itemClicked(QGraphicsItem *item); + void userChangedData(VProperty* property); + void UpdateOptions(); +private: + Q_DISABLE_COPY(VToolOptionsPropertyBrowser) + + VPropertyModel* PropertyModel; + VPropertyFormView* formView; + + QGraphicsItem *currentItem; + QMap propertyToId; + QMap idToProperty; + + void AddProperty(VProperty *property, const QString &id); + void ShowItemOptions(QGraphicsItem *item); + + template + void SetPointName(const QString &name); + + template + void AddPropertyPointName(Tool *i, const QString &propertyName); + + template + void AddPropertyLineType(Tool *i, const QString &propertyName); + + void AddPropertyFormula(const QString &propertyName, const VFormula &formula, const QString &attrName); + + QStringList PropertiesList() const; + + void ChangeDataToolSinglePoint(VProperty *property); + void ChangeDataToolEndLine(VProperty *property); + void ChangeDataToolAlongLine(VProperty *property); + void ChangeDataToolArc(VProperty *property); + void ChangeDataToolBisector(VProperty *property); + void ChangeDataToolCutArc(VProperty *property); + void ChangeDataToolCutSpline(VProperty *property); + void ChangeDataToolCutSplinePath(VProperty *property); + void ChangeDataToolHeight(VProperty *property); + void ChangeDataToolLine(VProperty *property); + void ChangeDataToolLineIntersect(VProperty *property); + void ChangeDataToolNormal(VProperty *property); + void ChangeDataToolPointOfContact(VProperty *property); + void ChangeDataToolPointOfIntersection(VProperty *property); + void ChangeDataToolShoulderPoint(VProperty *property); + void ChangeDataToolSpline(VProperty *property); + void ChangeDataToolSplinePath(VProperty *property); + void ChangeDataToolTriangle(VProperty *property); + + void ShowOptionsToolSinglePoint(QGraphicsItem *item); + void ShowOptionsToolEndLine(QGraphicsItem *item); + void ShowOptionsToolAlongLine(QGraphicsItem *item); + void ShowOptionsToolArc(QGraphicsItem *item); + void ShowOptionsToolBisector(QGraphicsItem *item); + void ShowOptionsToolCutArc(QGraphicsItem *item); + void ShowOptionsToolCutSpline(QGraphicsItem *item); + void ShowOptionsToolCutSplinePath(QGraphicsItem *item); + void ShowOptionsToolHeight(QGraphicsItem *item); + void ShowOptionsToolLine(QGraphicsItem *item); + void ShowOptionsToolLineIntersect(QGraphicsItem *item); + void ShowOptionsToolNormal(QGraphicsItem *item); + void ShowOptionsToolPointOfContact(QGraphicsItem *item); + void ShowOptionsToolPointOfIntersection(QGraphicsItem *item); + void ShowOptionsToolShoulderPoint(QGraphicsItem *item); + void ShowOptionsToolSpline(QGraphicsItem *item); + void ShowOptionsToolSplinePath(QGraphicsItem *item); + void ShowOptionsToolTriangle(QGraphicsItem *item); + + void UpdateOptionsToolSinglePoint(); + void UpdateOptionsToolEndLine(); + void UpdateOptionsToolAlongLine(); + void UpdateOptionsToolArc(); + void UpdateOptionsToolBisector(); + void UpdateOptionsToolCutArc(); + void UpdateOptionsToolCutSpline(); + void UpdateOptionsToolCutSplinePath(); + void UpdateOptionsToolHeight(); + void UpdateOptionsToolLine(); + void UpdateOptionsToolLineIntersect(); + void UpdateOptionsToolNormal(); + void UpdateOptionsToolPointOfContact(); + void UpdateOptionsToolPointOfIntersection(); + void UpdateOptionsToolShoulderPoint(); + void UpdateOptionsToolSpline(); + void UpdateOptionsToolSplinePath(); + void UpdateOptionsToolTriangle(); +}; + +#endif // VTOOLOPTIONSPROPERTYBROWSER_H diff --git a/src/app/widgets/widgets.pri b/src/app/widgets/widgets.pri index 9f100cc0d..4c2ac1298 100644 --- a/src/app/widgets/widgets.pri +++ b/src/app/widgets/widgets.pri @@ -7,7 +7,10 @@ HEADERS += \ widgets/doubledelegate.h \ widgets/textdelegate.h \ widgets/vtranslation.h \ - widgets/undoevent.h + widgets/undoevent.h \ + widgets/vtooloptionspropertybrowser.h \ + widgets/vformulapropertyeditor.h \ + widgets/vformulaproperty.h SOURCES += \ widgets/vtablegraphicsview.cpp \ @@ -18,4 +21,7 @@ SOURCES += \ widgets/doubledelegate.cpp \ widgets/textdelegate.cpp \ widgets/vtranslation.cpp \ - widgets/undoevent.cpp + widgets/undoevent.cpp \ + widgets/vtooloptionspropertybrowser.cpp \ + widgets/vformulapropertyeditor.cpp \ + widgets/vformulaproperty.cpp diff --git a/src/app/xml/vpattern.cpp b/src/app/xml/vpattern.cpp index 33edc92a2..4d575376b 100644 --- a/src/app/xml/vpattern.cpp +++ b/src/app/xml/vpattern.cpp @@ -45,6 +45,7 @@ #include #include +#include const QString VPattern::TagPattern = QStringLiteral("pattern"); const QString VPattern::TagCalculation = QStringLiteral("calculation"); @@ -1095,7 +1096,7 @@ void VPattern::ParsePointElement(VMainGraphicsScene *scene, QDomElement &domElem const qreal y = qApp->toPixel(GetParametrDouble(domElement, VAbstractTool::AttrY, "10.0")); data->UpdateGObject(id, new VPointF(x, y, name, mx, my)); - VDrawTool::AddRecord(id, Tool::SinglePointTool, this); + VDrawTool::AddRecord(id, Tool::SinglePoint, this); if (parse != Document::FullParse) { UpdateToolData(id, data); @@ -1138,7 +1139,7 @@ void VPattern::ParsePointElement(VMainGraphicsScene *scene, QDomElement &domElem //Rewrite attribute formula. Need for situation when we have wrong formula. if (f != formula || angleFix != angle) { - SetAttribute(domElement, VAbstractTool::AttrRadius, f); + SetAttribute(domElement, VAbstractTool::AttrLength, f); SetAttribute(domElement, VAbstractTool::AttrAngle, angleFix); haveLiteChange(); } @@ -1619,6 +1620,68 @@ void VPattern::CheckTagExists(const QString &tag) } } +//--------------------------------------------------------------------------------------------------------------------- +QString VPattern::GetLabelBase(unsigned int index) const +{ + QString defaultLocale = QLocale::system().name(); // e.g. "de_DE" + defaultLocale.truncate(defaultLocale.lastIndexOf('_')); // e.g. "de" + QString checkedLocale = qApp->getSettings()->value("configuration/label_language", defaultLocale).toString(); + + QStringList list{"de", "en" , "fr" , "ru" , "uk"}; + + QStringList alphabet; + switch(list.indexOf(checkedLocale)) + { + case 0: // de + { + QString al = QStringLiteral("A,Ä,B,C,D,E,F,G,H,I,J,K,L,M,N,O,Ö,P,Q,R,S,ß,T,U,Ü,V,W,X,Y,Z"); + alphabet = al.split(","); + break; + } + case 1: // en + { + QString al = QStringLiteral("A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z"); + alphabet = al.split(","); + break; + } + case 2: // fr + { + QString al = QStringLiteral("A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z"); + alphabet = al.split(","); + break; + } + case 3: // ru + { + QString al = QStringLiteral("А,Б,В,Г,Д,Е,Ж,З,И,К,Л,М,Н,О,П,Р,С,Т,У,Ф,Х,Ц,Ч,Ш,Щ,Э,Ю,Я"); + alphabet = al.split(","); + break; + } + case 4: // uk + { + QString al = QStringLiteral("А,Б,В,Г,Д,Е,Ж,З,І,Ї,Й,К,Л,М,Н,О,П,Р,С,Т,У,Ф,Х,Ц,Ч,Ш,Щ,Є,Ю,Я"); + alphabet = al.split(","); + break; + } + default: // en + { + QString al = QStringLiteral("A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z"); + alphabet = al.split(","); + break; + } + } + + QString base; + int count = qFloor(index/alphabet.size()); + int number = index - alphabet.size() * count; + int i = 0; + do + { + base.append(alphabet.at(number)); + ++i; + } while (i < count); + return base; +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief ParseSplineElement parse spline tag. @@ -2280,6 +2343,66 @@ void VPattern::SetVersion() emit patternChanged(false); } +//--------------------------------------------------------------------------------------------------------------------- +QString VPattern::GenerateLabel(const LabelType &type) const +{ + QDomNodeList drawList = elementsByTagName(TagDraw); + + if (type == LabelType::NewPatternPiece) + { + QString name; + int i = 0; + for(;;) + { + name = GetLabelBase(drawList.size() + i); + if (data->IsUnique(name)) + { + return name; + } + if (i == INT_MAX) + { + break; + } + ++i; + } + return name; + } + else if (type == LabelType::NewLabel) + { + if (drawList.isEmpty()) + { + return GetLabelBase(0); + } + + int index = 0; + for (int i = 0; i < drawList.size(); ++i) + { + QDomElement node = drawList.at(i).toElement(); + if (node.attribute(AttrName) == nameActivPP) + { + index = i; + break; + } + } + + QString labelBase = GetLabelBase(index); + + qint32 num = 1; + QString name; + do + { + name = QString("%1%2").arg(labelBase).arg(num); + num++; + if (num == INT_MAX) + { + break; + } + } while (data->IsUnique(name) == false); + return name; + } + return QString(); +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief CollectId recursive function, try find id attribute in file. Throw exclusion if find not unique. @@ -2326,6 +2449,14 @@ void VPattern::PrepareForParse(const Document &parse) cursor = 0; history.clear(); } + else if (parse == Document::LiteParse) + { + data->ClearUniqueNames(); + data->ClearVariables(VarType::ArcLength); + data->ClearVariables(VarType::LineAngle); + data->ClearVariables(VarType::LineLength); + data->ClearVariables(VarType::SplineLength); + } } //--------------------------------------------------------------------------------------------------------------------- @@ -2424,40 +2555,40 @@ QRectF VPattern::ActiveDrawBoundingRect() const { switch ( tool.getTypeTool() ) { - case Tool::ArrowTool: + case Tool::Arrow: Q_UNREACHABLE(); break; - case Tool::SinglePointTool: + case Tool::SinglePoint: rec = ToolBoundingRect(rec, tool.getId()); break; - case Tool::EndLineTool: + case Tool::EndLine: rec = ToolBoundingRect(rec, tool.getId()); break; - case Tool::LineTool: + case Tool::Line: rec = ToolBoundingRect(rec, tool.getId()); break; - case Tool::AlongLineTool: + case Tool::AlongLine: rec = ToolBoundingRect(rec, tool.getId()); break; - case Tool::ShoulderPointTool: + case Tool::ShoulderPoint: rec = ToolBoundingRect(rec, tool.getId()); break; - case Tool::NormalTool: + case Tool::Normal: rec = ToolBoundingRect(rec, tool.getId()); break; - case Tool::BisectorTool: + case Tool::Bisector: rec = ToolBoundingRect(rec, tool.getId()); break; - case Tool::LineIntersectTool: + case Tool::LineIntersect: rec = ToolBoundingRect(rec, tool.getId()); break; - case Tool::SplineTool: + case Tool::Spline: rec = ToolBoundingRect(rec, tool.getId()); break; - case Tool::ArcTool: + case Tool::Arc: rec = ToolBoundingRect(rec, tool.getId()); break; - case Tool::SplinePathTool: + case Tool::SplinePath: rec = ToolBoundingRect(rec, tool.getId()); break; case Tool::PointOfContact: @@ -2472,18 +2603,18 @@ QRectF VPattern::ActiveDrawBoundingRect() const case Tool::PointOfIntersection: rec = ToolBoundingRect(rec, tool.getId()); break; - case Tool::CutArcTool: + case Tool::CutArc: rec = ToolBoundingRect(rec, tool.getId()); break; - case Tool::CutSplineTool: + case Tool::CutSpline: rec = ToolBoundingRect(rec, tool.getId()); break; - case Tool::CutSplinePathTool: + case Tool::CutSplinePath: rec = ToolBoundingRect(rec, tool.getId()); break; //Because "history" not only show history of pattern, but help restore current data for each pattern's //piece, we need add record about details and nodes, but don't show them. - case Tool::DetailTool: + case Tool::Detail: break; case Tool::UnionDetails: break; diff --git a/src/app/xml/vpattern.h b/src/app/xml/vpattern.h index 1a264244c..d2e76a447 100644 --- a/src/app/xml/vpattern.h +++ b/src/app/xml/vpattern.h @@ -36,6 +36,7 @@ class VDataTool; class VMainGraphicsScene; enum class Document : char { LiteParse, LitePPParse, FullParse }; +enum class LabelType : char {NewPatternPiece, NewLabel}; /* VAL_VERSION is (major << 16) + (minor << 8) + patch. @@ -179,6 +180,8 @@ public: QString GetVersion() const; void SetVersion(); + + QString GenerateLabel(const LabelType &type)const; signals: /** * @brief ChangedActivDraw change active pattern peace. @@ -280,6 +283,7 @@ private: QRectF ToolBoundingRect(const QRectF &rec, const quint32 &id) const; void ParseCurrentPP(); void CheckTagExists(const QString &tag); + QString GetLabelBase(unsigned int index)const; }; //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/app/xml/vtoolrecord.cpp b/src/app/xml/vtoolrecord.cpp index 1b6fcbd19..046334f14 100644 --- a/src/app/xml/vtoolrecord.cpp +++ b/src/app/xml/vtoolrecord.cpp @@ -33,7 +33,7 @@ * @brief VToolRecord default constructor. */ VToolRecord::VToolRecord() - :id(NULL_ID), typeTool(Tool::ArrowTool), nameDraw(QString()) + :id(NULL_ID), typeTool(Tool::Arrow), nameDraw(QString()) {} //--------------------------------------------------------------------------------------------------------------------- diff --git a/src/libs/libs.pro b/src/libs/libs.pro index 5d08776e9..bd493ca45 100644 --- a/src/libs/libs.pro +++ b/src/libs/libs.pro @@ -1,3 +1,4 @@ TEMPLATE = subdirs CONFIG += ordered -SUBDIRS = qmuparser +SUBDIRS = qmuparser \ + vpropertyexplorer diff --git a/src/libs/qmuparser/qmuparserbase.cpp b/src/libs/qmuparser/qmuparserbase.cpp index 3bf001f68..c4c30f0ee 100644 --- a/src/libs/qmuparser/qmuparserbase.cpp +++ b/src/libs/qmuparser/qmuparserbase.cpp @@ -65,7 +65,7 @@ QmuParserBase::QmuParserBase() :m_pParseFormula(&QmuParserBase::ParseString), m_vRPN(), m_vStringBuf(), m_vStringVarBuf(), m_pTokenReader(), m_FunDef(), m_PostOprtDef(), m_InfixOprtDef(), m_OprtDef(), m_ConstDef(), m_StrVarDef(), m_VarDef(), m_bBuiltInOp(true), m_sNameChars(), m_sOprtChars(), m_sInfixOprtChars(), m_nIfElseCounter(0), m_vStackBuffer(), - m_nFinalResultIdx(0), m_Tokens(QMap()), m_Numbers(QMap()) + m_nFinalResultIdx(0), m_Tokens(QMap()), m_Numbers(QMap()), allowSubexpressions(true) { InitTokenReader(); } @@ -80,7 +80,7 @@ QmuParserBase::QmuParserBase(const QmuParserBase &a_Parser) :m_pParseFormula(&QmuParserBase::ParseString), m_vRPN(), m_vStringBuf(), m_vStringVarBuf(), m_pTokenReader(), m_FunDef(), m_PostOprtDef(), m_InfixOprtDef(), m_OprtDef(), m_ConstDef(), m_StrVarDef(), m_VarDef(), m_bBuiltInOp(true), m_sNameChars(), m_sOprtChars(), m_sInfixOprtChars(), m_nIfElseCounter(0), m_vStackBuffer(), - m_nFinalResultIdx(0), m_Tokens(QMap()), m_Numbers(QMap()) + m_nFinalResultIdx(0), m_Tokens(QMap()), m_Numbers(QMap()), allowSubexpressions(true) { m_pTokenReader.reset(new token_reader_type(this)); Assign(a_Parser); @@ -219,6 +219,12 @@ void QmuParserBase::OnDetectVar(const QString &pExpr, int &nStart, int &nEnd) Q_UNUSED(nEnd); } +//--------------------------------------------------------------------------------------------------------------------- +void QmuParserBase::setAllowSubexpressions(bool value) +{ + allowSubexpressions = value; +} + //--------------------------------------------------------------------------------------------------------------------- /** * @brief Returns the version of muparser. @@ -1323,6 +1329,10 @@ void QmuParserBase::CreateRPN() const { Error(ecUNEXPECTED_ARG_SEP, m_pTokenReader->GetPos()); } + if (stOpt.empty() && allowSubexpressions == false) + { + Error(ecUNEXPECTED_ARG_SEP, m_pTokenReader->GetPos()); + } ++stArgCount.top(); // fallthrough intentional (no break!) case cmEND: diff --git a/src/libs/qmuparser/qmuparserbase.h b/src/libs/qmuparser/qmuparserbase.h index d7d92c090..59d8b7c59 100644 --- a/src/libs/qmuparser/qmuparserbase.h +++ b/src/libs/qmuparser/qmuparserbase.h @@ -120,6 +120,8 @@ public: { AddCallback( a_strName, QmuParserCallback(a_pFun, a_bAllowOpt), m_FunDef, ValidNameChars() ); } + void setAllowSubexpressions(bool value); + protected: static const QStringList c_DefaultOprt; static std::locale s_locale; ///< The locale used by the parser @@ -235,6 +237,8 @@ private: mutable QMap m_Tokens;///< Keep all tokens that we can translate mutable QMap m_Numbers;///< Keep all numbers what exist in formula + bool allowSubexpressions; + void Assign(const QmuParserBase &a_Parser); void InitTokenReader(); void ReInit() const; diff --git a/src/libs/vpropertyexplorer/LICENSE.txt b/src/libs/vpropertyexplorer/LICENSE.txt new file mode 100644 index 000000000..65c5ca88a --- /dev/null +++ b/src/libs/vpropertyexplorer/LICENSE.txt @@ -0,0 +1,165 @@ + GNU LESSER GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + + This version of the GNU Lesser General Public License incorporates +the terms and conditions of version 3 of the GNU General Public +License, supplemented by the additional permissions listed below. + + 0. Additional Definitions. + + As used herein, "this License" refers to version 3 of the GNU Lesser +General Public License, and the "GNU GPL" refers to version 3 of the GNU +General Public License. + + "The Library" refers to a covered work governed by this License, +other than an Application or a Combined Work as defined below. + + An "Application" is any work that makes use of an interface provided +by the Library, but which is not otherwise based on the Library. +Defining a subclass of a class defined by the Library is deemed a mode +of using an interface provided by the Library. + + A "Combined Work" is a work produced by combining or linking an +Application with the Library. The particular version of the Library +with which the Combined Work was made is also called the "Linked +Version". + + The "Minimal Corresponding Source" for a Combined Work means the +Corresponding Source for the Combined Work, excluding any source code +for portions of the Combined Work that, considered in isolation, are +based on the Application, and not on the Linked Version. + + The "Corresponding Application Code" for a Combined Work means the +object code and/or source code for the Application, including any data +and utility programs needed for reproducing the Combined Work from the +Application, but excluding the System Libraries of the Combined Work. + + 1. Exception to Section 3 of the GNU GPL. + + You may convey a covered work under sections 3 and 4 of this License +without being bound by section 3 of the GNU GPL. + + 2. Conveying Modified Versions. + + If you modify a copy of the Library, and, in your modifications, a +facility refers to a function or data to be supplied by an Application +that uses the facility (other than as an argument passed when the +facility is invoked), then you may convey a copy of the modified +version: + + a) under this License, provided that you make a good faith effort to + ensure that, in the event an Application does not supply the + function or data, the facility still operates, and performs + whatever part of its purpose remains meaningful, or + + b) under the GNU GPL, with none of the additional permissions of + this License applicable to that copy. + + 3. Object Code Incorporating Material from Library Header Files. + + The object code form of an Application may incorporate material from +a header file that is part of the Library. You may convey such object +code under terms of your choice, provided that, if the incorporated +material is not limited to numerical parameters, data structure +layouts and accessors, or small macros, inline functions and templates +(ten or fewer lines in length), you do both of the following: + + a) Give prominent notice with each copy of the object code that the + Library is used in it and that the Library and its use are + covered by this License. + + b) Accompany the object code with a copy of the GNU GPL and this license + document. + + 4. Combined Works. + + You may convey a Combined Work under terms of your choice that, +taken together, effectively do not restrict modification of the +portions of the Library contained in the Combined Work and reverse +engineering for debugging such modifications, if you also do each of +the following: + + a) Give prominent notice with each copy of the Combined Work that + the Library is used in it and that the Library and its use are + covered by this License. + + b) Accompany the Combined Work with a copy of the GNU GPL and this license + document. + + c) For a Combined Work that displays copyright notices during + execution, include the copyright notice for the Library among + these notices, as well as a reference directing the user to the + copies of the GNU GPL and this license document. + + d) Do one of the following: + + 0) Convey the Minimal Corresponding Source under the terms of this + License, and the Corresponding Application Code in a form + suitable for, and under terms that permit, the user to + recombine or relink the Application with a modified version of + the Linked Version to produce a modified Combined Work, in the + manner specified by section 6 of the GNU GPL for conveying + Corresponding Source. + + 1) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (a) uses at run time + a copy of the Library already present on the user's computer + system, and (b) will operate properly with a modified version + of the Library that is interface-compatible with the Linked + Version. + + e) Provide Installation Information, but only if you would otherwise + be required to provide such information under section 6 of the + GNU GPL, and only to the extent that such information is + necessary to install and execute a modified version of the + Combined Work produced by recombining or relinking the + Application with a modified version of the Linked Version. (If + you use option 4d0, the Installation Information must accompany + the Minimal Corresponding Source and Corresponding Application + Code. If you use option 4d1, you must provide the Installation + Information in the manner specified by section 6 of the GNU GPL + for conveying Corresponding Source.) + + 5. Combined Libraries. + + You may place library facilities that are a work based on the +Library side by side in a single library together with other library +facilities that are not Applications and are not covered by this +License, and convey such a combined library under terms of your +choice, if you do both of the following: + + a) Accompany the combined library with a copy of the same work based + on the Library, uncombined with any other library facilities, + conveyed under the terms of this License. + + b) Give prominent notice with the combined library that part of it + is a work based on the Library, and explaining where to find the + accompanying uncombined form of the same work. + + 6. Revised Versions of the GNU Lesser General Public License. + + The Free Software Foundation may publish revised and/or new versions +of the GNU Lesser General Public License from time to time. Such new +versions will be similar in spirit to the present version, but may +differ in detail to address new problems or concerns. + + Each version is given a distinguishing version number. If the +Library as you received it specifies that a certain numbered version +of the GNU Lesser General Public License "or any later version" +applies to it, you have the option of following the terms and +conditions either of that published version or of any later version +published by the Free Software Foundation. If the Library as you +received it does not specify a version number of the GNU Lesser +General Public License, you may choose any version of the GNU Lesser +General Public License ever published by the Free Software Foundation. + + If the Library as you received it specifies that a proxy can decide +whether future versions of the GNU Lesser General Public License shall +apply, that proxy's public statement of acceptance of any version is +permanent authorization for you to choose that version for the +Library. diff --git a/src/libs/vpropertyexplorer/plugins/Vector3d/vvector3dproperty.cpp b/src/libs/vpropertyexplorer/plugins/Vector3d/vvector3dproperty.cpp new file mode 100644 index 000000000..2873d4c2a --- /dev/null +++ b/src/libs/vpropertyexplorer/plugins/Vector3d/vvector3dproperty.cpp @@ -0,0 +1,113 @@ +#include "vvector3dproperty.h" + +using namespace VPE; + +#include "vproperty_p.h" +#include "../vnumberproperty.h" +#include + +QVector3DProperty::QVector3DProperty(const QString& name) + : VProperty(name, QVariant::String) // todo: QVariant::Vector3D?? +{ + QVariant tmpFloat(0); tmpFloat.convert(QVariant::Double); + VDoubleProperty* tmpX = new VDoubleProperty("X"); addChild(tmpX); tmpX->setUpdateBehaviour(true, false); + VDoubleProperty* tmpY = new VDoubleProperty("Y"); addChild(tmpY); tmpY->setUpdateBehaviour(true, false); + VDoubleProperty* tmpZ = new VDoubleProperty("Z"); addChild(tmpZ); tmpZ->setUpdateBehaviour(true, false); + setVector(Vector3D()); +} + + +//! Get the data how it should be displayed +QVariant QVector3DProperty::data (int column, int role) const +{ + if(column == DPC_Data && Qt::DisplayRole == role) + { + Vector3D tmpVect = getVector(); + return QString("(%1, %2, %3)").arg(QString::number(tmpVect.X), + QString::number(tmpVect.Y), + QString::number(tmpVect.Z)); + } + else + return VProperty::data(column, role); +} + +//! Returns item flags +Qt::ItemFlags QVector3DProperty::flags(int column) const +{ + if(column == DPC_Name || column == DPC_Data) + return Qt::ItemIsEnabled | Qt::ItemIsSelectable; + else + return Qt::NoItemFlags; +} + + +//! Returns the Vector3d +Vector3D QVector3DProperty::getVector() const +{ + Vector3D tmpVect; + + if(d_ptr->Children.count() < 3) + return tmpVect; + + tmpVect.X = d_ptr->Children.at(0)->getValue().toFloat(); + tmpVect.Y = d_ptr->Children.at(1)->getValue().toFloat(); + tmpVect.Z = d_ptr->Children.at(2)->getValue().toFloat(); + + return tmpVect; +} + +//! Sets the Vector3d +void QVector3DProperty::setVector(const Vector3D &vect) +{ + setVector(vect.X, vect.Y, vect.Z); +} + +void QVector3DProperty::setVector(float x, float y, float z) +{ + if(d_ptr->Children.count() < 3) + return; + + QVariant tmpX(x); tmpX.convert(QVariant::Double); + QVariant tmpY(y); tmpY.convert(QVariant::Double); + QVariant tmpZ(z); tmpZ.convert(QVariant::Double); + d_ptr->Children.at(0)->setValue(tmpX); + d_ptr->Children.at(1)->setValue(tmpY); + d_ptr->Children.at(2)->setValue(tmpZ); +} + +QString QVector3DProperty::type() const +{ + return "vector3d"; +} + +VProperty* QVector3DProperty::clone(bool include_children, VProperty* container) const +{ + if(!container) { + container = new QVector3DProperty(getName()); + + if(!include_children) { + QList tmpChildren = container->getChildren(); + foreach(VProperty* tmpChild, tmpChildren) { + container->removeChild(tmpChild); + delete tmpChild; + } + } + } + + return VProperty::clone(false, container); // Child +} + +void QVector3DProperty::setValue(const QVariant &value) +{ + QStringList tmpStrings = value.toString().split(","); + if(tmpStrings.count() == 3) { + setVector(tmpStrings[0].toDouble(), tmpStrings[1].toDouble(), tmpStrings[2].toDouble()); + } + +} + +QVariant QVector3DProperty::getValue() const +{ + Vector3D tmpVect = getVector(); + return QString("%1,%2,%3").arg(QString::number(tmpVect.X), QString::number(tmpVect.Y), QString::number(tmpVect.Z)); +} diff --git a/src/libs/vpropertyexplorer/plugins/Vector3d/vvector3dproperty.h b/src/libs/vpropertyexplorer/plugins/Vector3d/vvector3dproperty.h new file mode 100644 index 000000000..56f343639 --- /dev/null +++ b/src/libs/vpropertyexplorer/plugins/Vector3d/vvector3dproperty.h @@ -0,0 +1,77 @@ +#ifndef VVECTOR3DPROPERTY_H +#define VVECTOR3DPROPERTY_H + +#include "vpropertyexplorer_global.h" + +#include "vproperty.h" + +namespace VPE{ + +struct VPROPERTYEXPLORERSHARED_EXPORT Vector3D +{ +public: + Vector3D() + { + X = Y = Z = 0; + } + + Vector3D(const Vector3D& other) + { + X = other.X; + Y = other.Y; + Z = other.Z; + } + + ~Vector3D() {} + + float X, Y, Z; +}; +/* +} + +Q_DECLARE_METATYPE(QPE::Vector3D) // todo + +*/ + +class VPROPERTYEXPLORERSHARED_EXPORT QVector3DProperty : public VProperty +{ +public: + QVector3DProperty(const QString& name); + + virtual ~QVector3DProperty() {} + + //! Get the data how it should be displayed + virtual QVariant data (int column = DPC_Name, int role = Qt::DisplayRole) const; + + //! Returns item flags + Qt::ItemFlags flags(int column = DPC_Name) const; + + //! Returns the Vector3d + virtual Vector3D getVector() const; + + //! Sets the Vector3d + virtual void setVector(const Vector3D& vect); + + //! Sets the Vector3d + virtual void setVector(float x, float y, float z); + + //! Returns a string containing the type of the property + virtual QString type() const; + + //! Clones this property + //! \param include_children Indicates whether to also clone the children + //! \param container If a property is being passed here, no new VProperty is being created but instead it is tried to fill all the data into container. This can also be used when subclassing this function. + //! \return Returns the newly created property (or container, if it was not NULL) + virtual VProperty* clone(bool include_children = true, VProperty* container = NULL) const; + + //! Sets the value of the property + virtual void setValue(const QVariant& value); + + //! Returns the value of the property as a QVariant + virtual QVariant getValue() const; + +}; + +} + +#endif // VVECTOR3DPROPERTY_H diff --git a/src/libs/vpropertyexplorer/plugins/vboolproperty.cpp b/src/libs/vpropertyexplorer/plugins/vboolproperty.cpp new file mode 100644 index 000000000..8b894d503 --- /dev/null +++ b/src/libs/vpropertyexplorer/plugins/vboolproperty.cpp @@ -0,0 +1,67 @@ +#include "vboolproperty.h" + +#include +#include +#include +#include +#include +#include + +#include "vproperty_p.h" + +using namespace VPE; + +QVariant VBoolProperty::TrueText; +QVariant VBoolProperty::FalseText; + +VBoolProperty::VBoolProperty(const QString& name) : + VProperty(name, QVariant::Bool) +{ + d_ptr->VariantValue.setValue(false); + d_ptr->VariantValue.convert(QVariant::Bool); + + // I'm not sure, how Qt handles the translations... + if(TrueText.isNull()) TrueText = QObject::tr("True"); + if(TrueText.isNull()) FalseText = QObject::tr("False"); +} + + +//! Get the data how it should be displayed +QVariant VBoolProperty::data (int column, int role) const +{ + if(column == DPC_Data && (Qt::DisplayRole == role || Qt::EditRole == role)) + return d_ptr->VariantValue.toBool() ? TrueText : FalseText; + if(column == DPC_Data && Qt::CheckStateRole == role) + return d_ptr->VariantValue.toBool() ? Qt::Checked : Qt::Unchecked; + else + return VProperty::data(column, role); +} + +bool VBoolProperty::setData(const QVariant &data, int role) +{ + if(Qt::CheckStateRole == role) + { + d_ptr->VariantValue = (Qt::Checked == static_cast(data.toInt())); return true; + } + + return false; +} + +//! Returns item flags +Qt::ItemFlags VBoolProperty::flags(int column) const +{ + if(column == DPC_Data) + return Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsUserCheckable; + else + return VProperty::flags(column); +} + +QString VBoolProperty::type() const +{ + return "bool"; +} + +VProperty *VBoolProperty::clone(bool include_children, VProperty *container) const +{ + return VProperty::clone(include_children, container ? container : new VBoolProperty(getName())); +} diff --git a/src/libs/vpropertyexplorer/plugins/vboolproperty.h b/src/libs/vpropertyexplorer/plugins/vboolproperty.h new file mode 100644 index 000000000..62fb3d9b3 --- /dev/null +++ b/src/libs/vpropertyexplorer/plugins/vboolproperty.h @@ -0,0 +1,49 @@ +#ifndef VBOOLPROPERTY_H +#define VBOOLPROPERTY_H + +#include "vproperty.h" + +namespace VPE{ + +//! The VBoolProperty can take two states: True or False. +class VPROPERTYEXPLORERSHARED_EXPORT VBoolProperty : public VProperty +{ +public: + //! Default constructor + VBoolProperty(const QString& name); + + //! Destructor + ~VBoolProperty() {} + + //! Get the data how it should be displayed + virtual QVariant data (int column = DPC_Name, int role = Qt::DisplayRole) const; + + //! This is used by the model to set the data + //! \param data The data to set + //! \param role The role. Default is Qt::EditRole + //! \return Returns true, if the data was changed, false if not. + virtual bool setData (const QVariant& data, int role = Qt::EditRole); + + //! Returns item flags + virtual Qt::ItemFlags flags(int column = DPC_Name) const; + + //! Returns a string containing the type of the property + virtual QString type() const; + + //! Clones this property + //! \param include_children Indicates whether to also clone the children + //! \param container If a property is being passed here, no new VProperty is being created but instead it is tried to fill all the data into container. This can also be used when subclassing this function. + //! \return Returns the newly created property (or container, if it was not NULL) + virtual VProperty* clone(bool include_children = true, VProperty* container = NULL) const; + +protected: + //! The (translatable) text displayed when the property is set to true (default: "True") + static QVariant TrueText; + + //! The (translatable) text displayed when the property is set to false (default: "False") + static QVariant FalseText; +}; + +} + +#endif // VBOOLPROPERTY_H diff --git a/src/libs/vpropertyexplorer/plugins/vcolorproperty.cpp b/src/libs/vpropertyexplorer/plugins/vcolorproperty.cpp new file mode 100644 index 000000000..dbf2a1838 --- /dev/null +++ b/src/libs/vpropertyexplorer/plugins/vcolorproperty.cpp @@ -0,0 +1,68 @@ +#include "vcolorproperty.h" +#include "vcolorpropertyeditor.h" + +#include "vproperty_p.h" + +using namespace VPE; + +VColorProperty::VColorProperty(const QString &name) : + VProperty(name, QVariant::Color) +{ +} + + +//! Get the data how it should be displayed +QVariant VColorProperty::data (int column, int role) const +{ + if(column == DPC_Data && (Qt::DisplayRole == role)) + return VColorPropertyEditor::getColorString(d_ptr->VariantValue.value()); + else if(Qt::EditRole == role) + return QVariant(); + else if(column == DPC_Data && (Qt::DecorationRole == role)) + return VColorPropertyEditor::getColorPixmap(d_ptr->VariantValue.value()); + else + return VProperty::data(column, role); +} + +//! Returns an editor widget, or NULL if it doesn't supply one +QWidget* VColorProperty::createEditor(QWidget* parent, const QStyleOptionViewItem& options, const QAbstractItemDelegate* delegate) +{ + Q_UNUSED(options); + Q_UNUSED(delegate); + + VColorPropertyEditor* tmpWidget = new VColorPropertyEditor(parent); + tmpWidget->setColor(d_ptr->VariantValue.value()); + return tmpWidget; +} + +//! Sets the property's data to the editor (returns false, if the standard delegate should do that) +bool VColorProperty::setEditorData(QWidget* editor) +{ + VColorPropertyEditor* tmpWidget = qobject_cast(editor); + if(tmpWidget) + tmpWidget->setColor(d_ptr->VariantValue.value()); + else + return false; + + return true; +} + +//! Gets the data from the widget +QVariant VColorProperty::getEditorData(QWidget* editor) const +{ + VColorPropertyEditor* tmpWidget = qobject_cast(editor); + if(tmpWidget) + return tmpWidget->getColor(); + + return QVariant(); +} + +QString VColorProperty::type() const +{ + return "color"; +} + +VProperty *VColorProperty::clone(bool include_children, VProperty *container) const +{ + return VProperty::clone(include_children, container ? container : new VColorProperty(getName())); +} diff --git a/src/libs/vpropertyexplorer/plugins/vcolorproperty.h b/src/libs/vpropertyexplorer/plugins/vcolorproperty.h new file mode 100644 index 000000000..cad37a0e7 --- /dev/null +++ b/src/libs/vpropertyexplorer/plugins/vcolorproperty.h @@ -0,0 +1,44 @@ +#ifndef VCOLORPROPERTY_H +#define VCOLORPROPERTY_H + +#include "vpropertyexplorer_global.h" + +#include "vproperty.h" + +namespace VPE { + +class VPROPERTYEXPLORERSHARED_EXPORT VColorProperty : public VProperty +{ + +public: + VColorProperty(const QString &name); + + //! Get the data how it should be displayed + virtual QVariant data (int column = DPC_Name, int role = Qt::DisplayRole) const; + + //! Returns an editor widget, or NULL if it doesn't supply one + //! \param parent The widget to which the editor will be added as a child + //! \options Render options + //! \delegate A pointer to the QAbstractItemDelegate requesting the editor. This can be used to connect signals and slots. + virtual QWidget* createEditor(QWidget* parent, const QStyleOptionViewItem& options, const QAbstractItemDelegate* delegate); + + //! Sets the property's data to the editor (returns false, if the standard delegate should do that) + virtual bool setEditorData(QWidget* editor); + + //! Gets the data from the widget + virtual QVariant getEditorData(QWidget* editor) const; + + //! Returns a string containing the type of the property + virtual QString type() const; + + //! Clones this property + //! \param include_children Indicates whether to also clone the children + //! \param container If a property is being passed here, no new VProperty is being created but instead it is tried to fill all the data into container. This can also be used when subclassing this function. + //! \return Returns the newly created property (or container, if it was not NULL) + virtual VProperty* clone(bool include_children = true, VProperty* container = NULL) const; + +}; + +} + +#endif // VCOLORPROPERTY_H diff --git a/src/libs/vpropertyexplorer/plugins/vcolorpropertyeditor.cpp b/src/libs/vpropertyexplorer/plugins/vcolorpropertyeditor.cpp new file mode 100644 index 000000000..f254bd3fb --- /dev/null +++ b/src/libs/vpropertyexplorer/plugins/vcolorpropertyeditor.cpp @@ -0,0 +1,115 @@ +#include "vcolorpropertyeditor.h" + +#include +#include +#include +#include +#include + +#include "vproperty.h" + +using namespace VPE; + +VColorPropertyEditor::VColorPropertyEditor(QWidget *parent) : + QWidget(parent) +{ + setAutoFillBackground(true); + + // Create the tool button + ToolButton = new QToolButton(this); + ToolButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Minimum); + ToolButton->setText(tr("...")); + ToolButton->setFixedWidth(20); + ToolButton->installEventFilter(this); + setFocusProxy(ToolButton); // Make the ToolButton the focus proxy + setFocusPolicy(ToolButton->focusPolicy()); + connect(ToolButton, SIGNAL(clicked()), this, SLOT(onToolButtonClicked())); + + // Create the text label + TextLabel = new QLabel(this); + TextLabel->setText(getColorString(Color)); + + // Create the label for the pixmap + ColorLabel = new QLabel(this); + ColorLabel->setPixmap(getColorPixmap(Color)); + + // Spacer (this is needed for proper display of the label and button) + Spacer = new QSpacerItem(1, 0, QSizePolicy::Expanding, QSizePolicy::Ignored); + + // The layout (a horizontal layout) + QHBoxLayout* layout = new QHBoxLayout(this); + layout->setSpacing(3); + layout->setMargin(0); + layout->addWidget(ColorLabel); + layout->addWidget(TextLabel); + layout->addItem(Spacer); + layout->addWidget(ToolButton); + //TextLabel->hide(); + //ColorLabel->hide(); // for now, we just use the standard display and only add the button +} + +void VColorPropertyEditor::setColor(const QColor& color_) +{ + if (Color != color_) + { + Color = color_; + ColorLabel->setPixmap(getColorPixmap(Color)); + TextLabel->setText(getColorString(Color)); + } +} + +QPixmap VColorPropertyEditor::getColorPixmap(const QColor& color, unsigned int size) +{ + QImage tmpImgage(size, size, QImage::Format_ARGB32_Premultiplied); + tmpImgage.fill(static_cast(color.rgb())); + return QPixmap::fromImage(tmpImgage); + // todo: support alpha channel +} + +QString VColorPropertyEditor::getColorString(const QColor& color) +{ + return QApplication::translate("QtPropertyExplorer", "[%1, %2, %3] (%4)", "Colors as string") + .arg(QString::number(color.red())) + .arg(QString::number(color.green())) + .arg(QString::number(color.blue())) + .arg(QString::number(color.alpha())); + +} + +void VColorPropertyEditor::onToolButtonClicked() +{ + bool ok = false; + QRgb oldRgba = Color.rgba(); + QRgb newRgba = QColorDialog::getRgba(oldRgba, &ok, this); + if (ok && newRgba != oldRgba) { + setColor(QColor::fromRgba(newRgba)); + emit dataChangedByUser(Color, this); + UserChangeEvent *event = new UserChangeEvent(); + QCoreApplication::postEvent ( this, event ); + } +} + +bool VColorPropertyEditor::eventFilter(QObject *obj, QEvent *ev) +{ + if(obj == ToolButton && (ev->type() == QEvent::KeyPress || ev->type() == QEvent::KeyPress)) + { + // Ignore the event, so that eventually the delegate gets the event. + ev->ignore(); + return true; + } + + return QWidget::eventFilter(obj, ev); +} + + +VColorPropertyEditor::~VColorPropertyEditor() +{ + // +} + + + +QColor VColorPropertyEditor::getColor() +{ + return Color; +} diff --git a/src/libs/vpropertyexplorer/plugins/vcolorpropertyeditor.h b/src/libs/vpropertyexplorer/plugins/vcolorpropertyeditor.h new file mode 100644 index 000000000..63ba6928f --- /dev/null +++ b/src/libs/vpropertyexplorer/plugins/vcolorpropertyeditor.h @@ -0,0 +1,67 @@ +#ifndef VCOLORPROPERTYEDITOR_H +#define VCOLORPROPERTYEDITOR_H + +#include "vpropertyexplorer_global.h" + +#include +#include +#include +#include +#include + +namespace VPE{ + +class VPROPERTYEXPLORERSHARED_EXPORT VColorPropertyEditor : public QWidget +{ + Q_OBJECT + +public: + //! Constructor taking a widget as parent + VColorPropertyEditor(QWidget *parent); + + //! Destructor + virtual ~VColorPropertyEditor(); + + + //! Returns the color currently set + QColor getColor(); + + //! A little helper function generating an image to represent a color + //! \param color The color to fill the image with + //! \size The size of the generated pixmap + //! \return Returns a QPixmap + static QPixmap getColorPixmap(const QColor& color, unsigned int size = 16); + + //! A helper function to convert a color into a string. + //! \param color The color to fill the image with + //! \return The color as string, usually in the format [RRR, GGG, BBB] (AAA) + static QString getColorString(const QColor& color); + + //! Needed for proper event handling + bool eventFilter(QObject *obj, QEvent *ev); + +signals: + //! This is emitted, when the user changes the color + void dataChangedByUser(const QColor &getColor, VColorPropertyEditor* editor); + + void dataChanged(); + +public slots: + //! Sets the color of the widget + void setColor(const QColor &color_); + +private slots: + void onToolButtonClicked(); + +private: + QColor Color; + QToolButton* ToolButton; + QLineEdit* Lineedit; + QLabel* TextLabel; + QLabel* ColorLabel; + QSpacerItem* Spacer; +}; + +} + +#endif // QFILEPROPERTYEDITOR_H diff --git a/src/libs/vpropertyexplorer/plugins/vemptyproperty.cpp b/src/libs/vpropertyexplorer/plugins/vemptyproperty.cpp new file mode 100644 index 000000000..50da8f390 --- /dev/null +++ b/src/libs/vpropertyexplorer/plugins/vemptyproperty.cpp @@ -0,0 +1,70 @@ +#include "vemptyproperty.h" + +using namespace VPE; + +VEmptyProperty::VEmptyProperty(const QString& name) + : VProperty(name, QVariant::Invalid) +{ +} + + +VEmptyProperty::VEmptyProperty(VPropertyPrivate *d) + : VProperty(d) +{ +} + + +VEmptyProperty::~VEmptyProperty() +{ + // +} + +//! Get the data how it should be displayed +QVariant VEmptyProperty::data (int column, int role) const +{ + if(column == DPC_Data && (Qt::DisplayRole == role || Qt::EditRole == role)) + return QVariant(); + else if(role == Qt::BackgroundRole) + return QBrush(QColor(217,217,217)); + else if(role == Qt::FontRole) + { QFont tmpFont; tmpFont.setBold(true); return tmpFont; } + else + return VProperty::data(column, role); +} + +//! Returns an editor widget, or NULL if it doesn't supply one +QWidget* VEmptyProperty::createEditor(QWidget * parent, const QStyleOptionViewItem& options, const QAbstractItemDelegate* delegate) +{ + Q_UNUSED(options); + Q_UNUSED(parent); + Q_UNUSED(delegate); + + return NULL; +} + + +//! Gets the data from the widget +QVariant VEmptyProperty::getEditorData(QWidget* editor) const +{ + Q_UNUSED(editor); + + return QVariant(); +} + +//! Returns item flags +Qt::ItemFlags VEmptyProperty::flags(int column) const +{ + Q_UNUSED(column); + + return Qt::ItemIsEnabled | Qt::ItemIsSelectable; +} + +QString VEmptyProperty::type() const +{ + return "empty"; +} + +VProperty* VEmptyProperty::clone(bool include_children, VProperty* container) const +{ + return VProperty::clone(include_children, container ? container : new VEmptyProperty(getName())); +} diff --git a/src/libs/vpropertyexplorer/plugins/vemptyproperty.h b/src/libs/vpropertyexplorer/plugins/vemptyproperty.h new file mode 100644 index 000000000..33cf02315 --- /dev/null +++ b/src/libs/vpropertyexplorer/plugins/vemptyproperty.h @@ -0,0 +1,48 @@ +#ifndef VEMPTYPROPERTY_H +#define VEMPTYPROPERTY_H + +#include "vproperty.h" + +namespace VPE { + +class VPROPERTYEXPLORERSHARED_EXPORT VEmptyProperty : public VProperty +{ +public: + //! Standard constructor, takes a name and a parent property as argument + explicit VEmptyProperty(const QString& name); + + //! Destructor + virtual ~VEmptyProperty(); + + //! Get the data how it should be displayed + virtual QVariant data (int column = DPC_Name, int role = Qt::DisplayRole) const; + + //! Returns an editor widget, or NULL if it doesn't supply one + //! \param parent The widget to which the editor will be added as a child + //! \options Render options + //! \delegate A pointer to the QAbstractItemDelegate requesting the editor. This can be used to connect signals and slots. + virtual QWidget* createEditor(QWidget* parent, const QStyleOptionViewItem& options, const QAbstractItemDelegate* delegate); + + //! Gets the data from the widget + virtual QVariant getEditorData(QWidget* editor) const; + + //! Returns item flags + virtual Qt::ItemFlags flags(int column = DPC_Name) const; + + //! Returns a string containing the type of the property + virtual QString type() const; + + //! Clones this property + //! \param include_children Indicates whether to also clone the children + //! \param container If a property is being passed here, no new VProperty is being created but instead it is tried to fill all the data into container. This can also be used when subclassing this function. + //! \return Returns the newly created property (or container, if it was not NULL) + virtual VProperty* clone(bool include_children = true, VProperty* container = NULL) const; + +protected: + //! Protected constructor + VEmptyProperty(VPropertyPrivate* d); +}; + +} + +#endif // VEMPTYPROPERTY_H diff --git a/src/libs/vpropertyexplorer/plugins/venumproperty.cpp b/src/libs/vpropertyexplorer/plugins/venumproperty.cpp new file mode 100644 index 000000000..8e8d69902 --- /dev/null +++ b/src/libs/vpropertyexplorer/plugins/venumproperty.cpp @@ -0,0 +1,126 @@ +#include "venumproperty.h" +#include "vproperty_p.h" + +#include +#include + +using namespace VPE; + +VEnumProperty::VEnumProperty(const QString& name) + : VProperty(name, QVariant::Int) +{ + VProperty::d_ptr->VariantValue = 0; + VProperty::d_ptr->VariantValue.convert(QVariant::Int); +} + + +//! Get the data how it should be displayed +QVariant VEnumProperty::data (int column, int role) const +{ + if(EnumerationLiterals.empty()) + return QVariant(); + + int tmpIndex = VProperty::d_ptr->VariantValue.toInt(); + + if(tmpIndex < 0 || tmpIndex >= EnumerationLiterals.count()) + tmpIndex = 0; + + if(column == DPC_Data && Qt::DisplayRole == role) + return EnumerationLiterals.at(tmpIndex); + else if(column == DPC_Data && Qt::EditRole == role) + return tmpIndex; + else + return VProperty::data(column, role); +} + + +//! Returns an editor widget, or NULL if it doesn't supply one +QWidget* VEnumProperty::createEditor(QWidget * parent, const QStyleOptionViewItem& options, const QAbstractItemDelegate* delegate) +{ + Q_UNUSED(options); + Q_UNUSED(delegate); + QComboBox* tmpEditor = new QComboBox(parent); + tmpEditor->clear(); + tmpEditor->addItems(EnumerationLiterals); + tmpEditor->setCurrentIndex(VProperty::d_ptr->VariantValue.toInt()); + connect(tmpEditor, static_cast(&QComboBox::currentIndexChanged), this, + &VEnumProperty::currentIndexChanged); + + VProperty::d_ptr->editor = tmpEditor; + return VProperty::d_ptr->editor; +} + +//! Gets the data from the widget +QVariant VEnumProperty::getEditorData(QWidget* editor) const +{ + QComboBox* tmpEditor = qobject_cast(editor); + if(tmpEditor) + return tmpEditor->currentIndex(); + + return QVariant(0); +} + +//! Sets the enumeration literals +void VEnumProperty::setLiterals(const QStringList& literals) +{ + EnumerationLiterals = literals; +} + +//! Get the settings. This function has to be implemented in a subclass in order to have an effect +QStringList VEnumProperty::getLiterals() const +{ + return EnumerationLiterals; +} + +//! Sets the value of the property +void VEnumProperty::setValue(const QVariant& value) +{ + int tmpIndex = value.toInt(); + + if(tmpIndex < 0 || tmpIndex >= EnumerationLiterals.count()) + tmpIndex = 0; + + VProperty::d_ptr->VariantValue = tmpIndex; + VProperty::d_ptr->VariantValue.convert(QVariant::Int); + + if (VProperty::d_ptr->editor != nullptr) + { + setEditorData(VProperty::d_ptr->editor); + } +} + +QString VEnumProperty::type() const +{ + return "enum"; +} + +VProperty* VEnumProperty::clone(bool include_children, VProperty* container) const +{ + return VProperty::clone(include_children, container ? container : new VEnumProperty(getName())); +} + +void VEnumProperty::setSetting(const QString& key, const QVariant& value) +{ + if(key == "literals") + setLiterals(value.toString().split(";;")); +} + +QVariant VEnumProperty::getSetting(const QString& key) const +{ + if(key == "literals") + return getLiterals().join(";;"); + else + return VProperty::getSetting(key); +} + +QStringList VEnumProperty::getSettingKeys() const +{ + return QStringList("literals"); +} + +void VEnumProperty::currentIndexChanged(int index) +{ + Q_UNUSED(index) + UserChangeEvent *event = new UserChangeEvent(); + QCoreApplication::postEvent ( VProperty::d_ptr->editor, event ); +} diff --git a/src/libs/vpropertyexplorer/plugins/venumproperty.h b/src/libs/vpropertyexplorer/plugins/venumproperty.h new file mode 100644 index 000000000..07be616b5 --- /dev/null +++ b/src/libs/vpropertyexplorer/plugins/venumproperty.h @@ -0,0 +1,72 @@ +#ifndef VENUMPROPERTY_H +#define VENUMPROPERTY_H + +#include "vproperty.h" + +#include + +namespace VPE{ + +class VPROPERTYEXPLORERSHARED_EXPORT VEnumProperty : public VProperty +{ + Q_OBJECT +public: + //! Constructor + VEnumProperty(const QString& name); + + //! Destructor + ~VEnumProperty() {} + + //! Get the data how it should be displayed + virtual QVariant data (int column = DPC_Name, int role = Qt::DisplayRole) const; + + //! Returns an editor widget, or NULL if it doesn't supply one + //! \param parent The widget to which the editor will be added as a child + //! \options Render options + //! \delegate A pointer to the QAbstractItemDelegate requesting the editor. This can be used to connect signals and slots. + virtual QWidget* createEditor(QWidget* parent, const QStyleOptionViewItem& options, const QAbstractItemDelegate* delegate); + + //! Gets the data from the widget + virtual QVariant getEditorData(QWidget* editor) const; + + //! Sets the enumeration literals + virtual void setLiterals(const QStringList &literals); + + //! Get the settings. This function has to be implemented in a subclass in order to have an effect + virtual QStringList getLiterals() const; + + //! Sets the value of the property + virtual void setValue(const QVariant& value); + + //! Returns a string containing the type of the property + virtual QString type() const; + + //! Clones this property + //! \param include_children Indicates whether to also clone the children + //! \param container If a property is being passed here, no new VProperty is being created but instead it is tried to fill all the data into container. This can also be used when subclassing this function. + //! \return Returns the newly created property (or container, if it was not NULL) + virtual VProperty* clone(bool include_children = true, VProperty* container = nullptr) const; + + //! Sets the settings. Available settings: + //! + //! key: "literals" - value: "item1;;item2;;item3" + virtual void setSetting(const QString& key, const QVariant& value); + + //! Get the settings. This function has to be implemented in a subclass in order to have an effect + virtual QVariant getSetting(const QString& key) const; + + //! Returns the list of keys of the property's settings + virtual QStringList getSettingKeys() const; + +public slots: + void currentIndexChanged(int index); + +protected: + //! The list of possible options to choose frome + QStringList EnumerationLiterals; + // No use of d-pointer in this case, because it is unlikely this will change. If it does, we can still add other members by reimplementing the VPropertyPrivate class without touching this header file. +}; + +} + +#endif // VENUMPROPERTY_H diff --git a/src/libs/vpropertyexplorer/plugins/vfileproperty.cpp b/src/libs/vpropertyexplorer/plugins/vfileproperty.cpp new file mode 100644 index 000000000..583d71d3f --- /dev/null +++ b/src/libs/vpropertyexplorer/plugins/vfileproperty.cpp @@ -0,0 +1,136 @@ +#include "vfileproperty.h" +#include +#include + +#include "vfilepropertyeditor.h" + +#include "vfileproperty_p.h" + +using namespace VPE; + +VFileProperty::VFileProperty(const QString& name) + : VProperty(new VFilePropertyPrivate(name, QVariant::String)) +{ + +} + +VFileProperty::~VFileProperty() +{ + // +} + + +void VFileProperty::setFileFilters(const QString& filefilters) +{ + static_cast(d_ptr)->FileFilters = filefilters; +} + + +QString VFileProperty::getFileFilters() const +{ + return static_cast(d_ptr)->FileFilters; +} + + +void VFileProperty::setFile(const QString& file) +{ + d_ptr->VariantValue.setValue(file); +} + + +QString VFileProperty::getFile() const +{ + return d_ptr->VariantValue.toString(); +} + + +QVariant VFileProperty::data (int column, int role) const +{ + if(column == DPC_Data && (Qt::DisplayRole == role || Qt::EditRole == role)) + { + QFileInfo tmpFile(d_ptr->VariantValue.toString()); + return tmpFile.fileName(); + } + else + return VProperty::data(column, role); +} + + +QWidget* VFileProperty::createEditor(QWidget * parent, const QStyleOptionViewItem& options, const QAbstractItemDelegate* delegate) +{ + Q_UNUSED(options); + + VFileEditWidget* tmpWidget = new VFileEditWidget(parent); + if(delegate) + VFileEditWidget::connect(tmpWidget, SIGNAL(commitData(QWidget*)), delegate, SIGNAL(commitData(QWidget*))); + tmpWidget->setFilter(static_cast(d_ptr)->FileFilters); // todo: parse this string + tmpWidget->setFile(d_ptr->VariantValue.toString()); + tmpWidget->setDirectory(static_cast(d_ptr)->Directory); + return tmpWidget; +} + + +bool VFileProperty::setEditorData(QWidget* editor) +{ + VFileEditWidget* tmpWidget = qobject_cast(editor); + if(tmpWidget) + tmpWidget->setFile(d_ptr->VariantValue.toString()); + else + return false; + + return true; +} + + +QVariant VFileProperty::getEditorData(QWidget* editor) const +{ + VFileEditWidget* tmpWidget = qobject_cast(editor); + if(tmpWidget) + return tmpWidget->getFile(); + + return QVariant(); +} + +void VFileProperty::setSetting(const QString& key, const QVariant& value) +{ + if(key == "FileFilters") + setFileFilters(value.toString()); + else if(key == "Directory") + setDirectory(value.toBool()); +} + +QVariant VFileProperty::getSetting(const QString& key) const +{ + if(key == "FileFilters") + return getFileFilters(); + else if(key == "Directory") + return isDirectory(); + else + return VProperty::getSetting(key); +} + +QStringList VFileProperty::getSettingKeys() const +{ + return QStringList("FileFilters") << "Directory"; +} + +QString VFileProperty::type() const +{ + return "file"; +} + +VProperty* VFileProperty::clone(bool include_children, VProperty* container) const +{ + return VProperty::clone(include_children, container ? container : new VFileProperty(getName())); +} + +bool VFileProperty::isDirectory() const +{ + return static_cast(d_ptr)->Directory; +} + + +void VFileProperty::setDirectory(bool is_directory) +{ + static_cast(d_ptr)->Directory = is_directory; +} diff --git a/src/libs/vpropertyexplorer/plugins/vfileproperty.h b/src/libs/vpropertyexplorer/plugins/vfileproperty.h new file mode 100644 index 000000000..dd66ec24a --- /dev/null +++ b/src/libs/vpropertyexplorer/plugins/vfileproperty.h @@ -0,0 +1,76 @@ +#ifndef VFILEPROPERTY_H +#define VFILEPROPERTY_H + +#include "vpropertyexplorer_global.h" + +#include "vproperty.h" + +#include + +namespace VPE { + +class VPROPERTYEXPLORERSHARED_EXPORT VFileProperty : public VProperty +{ +public: + VFileProperty(const QString &name); + + //! The destructor + ~VFileProperty(); + + //! Sets the file filters. The file filters have to be like the ones passed a QFileOpenDialog. + virtual void setFileFilters(const QString& filefilters); + + //! Returns the current file filters as a string + virtual QString getFileFilters() const; + + //! Set file + virtual void setFile(const QString& file); + + //! Get file + virtual QString getFile() const; + + //! Get the data how it should be displayed + virtual QVariant data (int column = DPC_Name, int role = Qt::DisplayRole) const; + + //! Returns an editor widget, or NULL if it doesn't supply one + //! \param parent The widget to which the editor will be added as a child + //! \options Render options + //! \delegate A pointer to the QAbstractItemDelegate requesting the editor. This can be used to connect signals and slots. + virtual QWidget* createEditor(QWidget* parent, const QStyleOptionViewItem& options, const QAbstractItemDelegate* delegate); + + //! Sets the property's data to the editor (returns false, if the standard delegate should do that) + virtual bool setEditorData(QWidget* editor); + + //! Gets the data from the widget + virtual QVariant getEditorData(QWidget* editor) const; + + //! Sets the settings. Available settings: + //! + //! key: "FileFilters" - value: File filters in the same format the QFileDialog expects it + virtual void setSetting(const QString& key, const QVariant& value); + + //! Get the settings. This function has to be implemented in a subclass in order to have an effect + virtual QVariant getSetting(const QString& key) const; + + //! Returns the list of keys of the property's settings + virtual QStringList getSettingKeys() const; + + //! Returns a string containing the type of the property + virtual QString type() const; + + //! Clones this property + //! \param include_children Indicates whether to also clone the children + //! \param container If a property is being passed here, no new VProperty is being created but instead it is tried to fill all the data into container. This can also be used when subclassing this function. + //! \return Returns the newly created property (or container, if it was not NULL) + virtual VProperty* clone(bool include_children = true, VProperty* container = nullptr) const; + + //! Returns whether this is a file (false) or a directory (true) + virtual bool isDirectory() const; + + //! Sets whether this is a file (false) or a directory (true) + virtual void setDirectory(bool is_directory); +}; + +} + +#endif // VFILEPROPERTY_H diff --git a/src/libs/vpropertyexplorer/plugins/vfilepropertyeditor.cpp b/src/libs/vpropertyexplorer/plugins/vfilepropertyeditor.cpp new file mode 100644 index 000000000..ddd681afc --- /dev/null +++ b/src/libs/vpropertyexplorer/plugins/vfilepropertyeditor.cpp @@ -0,0 +1,204 @@ +#include "vfilepropertyeditor.h" + +#include "vfileproperty.h" + +#include +#include +#include +#include + +using namespace VPE; + +VFileEditWidget::VFileEditWidget(QWidget *parent, bool is_directory) + : QWidget(parent), Directory(is_directory) +{ + // Create the tool button,ToolButton = new QToolButton(this); + ToolButton = new QToolButton(this); + ToolButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Ignored); + ToolButton->setText(tr("...")); + ToolButton->setFixedWidth(20); + ToolButton->installEventFilter(this); + setFocusProxy(ToolButton); // Make the ToolButton the focus proxy + setFocusPolicy(ToolButton->focusPolicy()); + connect(ToolButton, SIGNAL(clicked()), this, SLOT(onToolButtonClicked())); + + // Create the line edit widget + FileLineEdit = new QLineEdit(this); + FileLineEdit->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); + FileLineEdit->setText(CurrentFilePath); + FileLineEdit->installEventFilter(this); + + // The layout (a horizontal layout) + QHBoxLayout* layout = new QHBoxLayout(this); + layout->setSpacing(0); + layout->setMargin(0); + layout->addWidget(FileLineEdit); + layout->addWidget(ToolButton); + + // Accept drops + setAcceptDrops(true); +} + + +VFileEditWidget::~VFileEditWidget() +{ + // nothing needs to be done here +} + + +void VFileEditWidget::setFile(const QString &value, bool emit_signal) +{ + if (CurrentFilePath != value) + { + CurrentFilePath = value; + FileLineEdit->setText(CurrentFilePath); + + if(emit_signal) + { + emit dataChangedByUser(CurrentFilePath, this); + emit commitData(this); + } + } +} + + +void VFileEditWidget::setFilter(const QString &dialog_filter, const QStringList& filter_list) +{ + FileDialogFilter = dialog_filter; + FilterList = filter_list; +} + +void VFileEditWidget::setDirectory(bool dir) +{ + Directory = dir; +} + +QString VFileEditWidget::getFile() +{ + return CurrentFilePath; +} + + +void VFileEditWidget::onToolButtonClicked() +{ + QString filepath = (Directory ? QFileDialog::getExistingDirectory(0, tr("Directory"), CurrentFilePath) : QFileDialog::getOpenFileName(0, tr("Open File"), CurrentFilePath, FileDialogFilter)); + if (!filepath.isNull()) + setFile(filepath, true); +} + + +bool VFileEditWidget::eventFilter(QObject *obj, QEvent *ev) +{ + if(ev->type() == QEvent::DragEnter || ev->type() == QEvent::Drop) + { + ev->ignore(); + if(ev->type() == QEvent::DragEnter) + dragEnterEvent(static_cast(ev)); + else if(ev->type() == QEvent::Drop) + dropEvent(static_cast(ev)); + + if(ev->isAccepted()) + return true; + else + return QWidget::eventFilter(obj, ev); + } + else if(obj == ToolButton && (ev->type() == QEvent::KeyPress || ev->type() == QEvent::KeyPress)) + { + // Ignore the event, so that eventually the delegate gets the event. + ev->ignore(); + return true; + } + else if(obj == FileLineEdit) + { + if(ev->type() == QEvent::FocusOut) + { + setFile(FileLineEdit->text(), true); + // We don't return true here because we still want the line edit to catch the event as well + } + } + + // forward the signal to the parent class + return QWidget::eventFilter(obj, ev); +} + +bool VFileEditWidget::isDirectory() +{ + return Directory; +} + + +void VFileEditWidget::dragEnterEvent(QDragEnterEvent* event) +{ + QString tmpFileName; + if(checkMimeData(event->mimeData(), tmpFileName)) + { + event->accept(); + event->acceptProposedAction(); + } +} + +void VFileEditWidget::dragMoveEvent(QDragMoveEvent* event) +{ + event->acceptProposedAction(); +} + +void VFileEditWidget::dragLeaveEvent(QDragLeaveEvent* event) +{ + event->accept(); +} + +void VFileEditWidget::dropEvent(QDropEvent* event) +{ + QString tmpFileName; + if(checkMimeData(event->mimeData(), tmpFileName)) + { + setFile(tmpFileName); + emit dataChangedByUser(getFile(), this); + emit commitData(this); + event->accept(); + event->acceptProposedAction(); + } +} + + +bool VFileEditWidget::checkMimeData(const QMimeData* data, QString& file) const +{ + if (data->hasUrls()) + { + QList tmpUrlList = data->urls(); + QFileInfo tmpFileInfo; + + foreach(QUrl tmpUrl, tmpUrlList) + if(QFile::exists(tmpUrl.toLocalFile())) + { tmpFileInfo = QFileInfo(tmpUrl.toLocalFile()); break; } + + if(checkFileFilter(tmpFileInfo.fileName())) + { + file = tmpFileInfo.absoluteFilePath(); + return true; + } + } + + return false; +} + +bool VFileEditWidget::checkFileFilter(const QString& file) const +{ + if(FilterList.isEmpty()) + return true; + + QFileInfo tmpFileInfo(file); + + if((Directory && !tmpFileInfo.isDir()) || (!Directory && !tmpFileInfo.isFile())) + return false; + + foreach(QString tmpFilter, FilterList) + { + QRegExp tmpRegExpFilter(tmpFilter, Qt::CaseInsensitive, QRegExp::Wildcard); + if(tmpRegExpFilter.exactMatch(file)) + return true; + } + + return false; +} + diff --git a/src/libs/vpropertyexplorer/plugins/vfilepropertyeditor.h b/src/libs/vpropertyexplorer/plugins/vfilepropertyeditor.h new file mode 100644 index 000000000..729dbead6 --- /dev/null +++ b/src/libs/vpropertyexplorer/plugins/vfilepropertyeditor.h @@ -0,0 +1,89 @@ +#ifndef VFILEPROPERTYEDITOR_H +#define VFILEPROPERTYEDITOR_H + +#include "vpropertyexplorer_global.h" + +#include +#include +#include +#include + +namespace VPE{ + + +class VPROPERTYEXPLORERSHARED_EXPORT VFileEditWidget : public QWidget +{ + Q_OBJECT + +public: + VFileEditWidget(QWidget* parent, bool is_directory = false); + virtual ~VFileEditWidget(); + + + //! This function returns the file currently set to this editor + QString getFile(); + + //! Needed for proper event handling + bool eventFilter(QObject* obj, QEvent* ev); + + //! Returns the directory/file setting + //! \return True, if a directory dialog is being shown, false if a file dialog + bool isDirectory(); + +signals: + //! This signal is emitted when the user changed the curret file. + //! Actions triggering this signal are either using the file dialog + //! to select a new file or changing the file path in the line edit. + void dataChangedByUser(const QString &getFile, VFileEditWidget* editor); + + //! This signal is emitted whenever dataChangedByUser() gets emmitted + //! and is connected to the delegate's commitData() signal + void commitData(QWidget* editor); + + +public slots: + //! Sets the current file, does not check if it is valid + //! \param file The new filepath the widget should show + //! \emit_signal If true, this will emit the dataChangedByUser()-signal (if file differs from the current file) + void setFile(const QString &getFile, bool emit_signal = false); + + //! Sets a filter for the file field + //! \param dialog_filter The filter used for the File Dialog + //! \param filter_list The list of file endings. The filters are being checked using regular expressions + void setFilter(const QString& dialog_filter = QString(), const QStringList& filter_list = QStringList()); + + //! Sets whether the property stores a directory or a file + void setDirectory(bool dir); + +private slots: + //! This slot gets activated, when the "..." button gets clicked + void onToolButtonClicked(); + +protected: + void dragEnterEvent(QDragEnterEvent* event); + void dragMoveEvent(QDragMoveEvent* event); + void dragLeaveEvent(QDragLeaveEvent* event); + void dropEvent(QDropEvent* event); + + + + //! This function checks the mime data, if it is compatible with the filters + virtual bool checkMimeData(const QMimeData* data, QString& getFile) const; + + //! This checks, if a file is compatible with the filters + virtual bool checkFileFilter(const QString& getFile) const; + + + QString CurrentFilePath; + QToolButton* ToolButton; + QLineEdit* FileLineEdit; + QString FileDialogFilter; + QStringList FilterList; + + //! Specifies whether it is being looked for a directory (true) or a file (false, default) + bool Directory; +}; + +} + +#endif // VFILEPROPERTYEDITOR_H diff --git a/src/libs/vpropertyexplorer/plugins/vnumberproperty.cpp b/src/libs/vpropertyexplorer/plugins/vnumberproperty.cpp new file mode 100644 index 000000000..7ccae32b6 --- /dev/null +++ b/src/libs/vpropertyexplorer/plugins/vnumberproperty.cpp @@ -0,0 +1,210 @@ +#include "vnumberproperty.h" + +#include +#include +#include +#include + +#include "vproperty_p.h" + +using namespace VPE; + + +const int VIntegerProperty::StandardMin = -1000000; +const int VIntegerProperty::StandardMax = 1000000; + +VIntegerProperty::VIntegerProperty(const QString& name, const QMap& settings) + : VProperty(name, QVariant::Int), min(StandardMin), max(StandardMax), singleStep(1.0) +{ + VProperty::setSettings(settings); + VProperty::d_ptr->VariantValue.setValue(0); + VProperty::d_ptr->VariantValue.convert(QVariant::Int); +} + +VIntegerProperty::VIntegerProperty(const QString &name) + : VProperty(name), min(StandardMin), max(StandardMax) +{ + VProperty::d_ptr->VariantValue.setValue(0); + VProperty::d_ptr->VariantValue.convert(QVariant::Int); +} + +//! Returns an editor widget, or NULL if it doesn't supply one +QWidget* VIntegerProperty::createEditor(QWidget * parent, const QStyleOptionViewItem& options, const QAbstractItemDelegate* delegate) +{ + Q_UNUSED(options); + Q_UNUSED(delegate); + + QSpinBox* tmpEditor = new QSpinBox(parent); + tmpEditor->setMinimum(min); + tmpEditor->setMaximum(max); + tmpEditor->setSingleStep(singleStep); + tmpEditor->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); + tmpEditor->setValue(VProperty::d_ptr->VariantValue.toInt()); + connect(tmpEditor, static_cast(&QSpinBox::valueChanged), this, + &VIntegerProperty::valueChanged); + + VProperty::d_ptr->editor = tmpEditor; + return VProperty::d_ptr->editor; +} + +//! Gets the data from the widget +QVariant VIntegerProperty::getEditorData(QWidget* editor) const +{ + QSpinBox* tmpEditor = qobject_cast(editor); + if(tmpEditor) + return tmpEditor->value(); + + return QVariant(0); +} + +void VIntegerProperty::setSettings(int minimum, int maxiumum, int singleStep) +{ + min = minimum; + max = maxiumum; + this->singleStep = singleStep; +} + +void VIntegerProperty::setSetting(const QString& key, const QVariant& value) +{ + if(key == QLatin1String("Min")) + setSettings(value.toInt(), max); + else if(key == QLatin1String("Max")) + setSettings(min, value.toInt()); + else if(key == QLatin1String("Step")) + setSettings(singleStep, value.toInt()); +} + +QVariant VIntegerProperty::getSetting(const QString& key) const +{ + if(key == QLatin1String("Min")) + return min; + if(key == QLatin1String("Max")) + return max; + if(key == QLatin1String("Step")) + return singleStep; + else + return VProperty::getSetting(key); +} + +QStringList VIntegerProperty::getSettingKeys() const +{ + return (QStringList("Min") << "Max" << "Step"); +} + +QString VIntegerProperty::type() const +{ + return "integer"; +} + +VProperty* VIntegerProperty::clone(bool include_children, VProperty* container) const +{ + return VProperty::clone(include_children, container ? container : new VIntegerProperty(getName())); +} + +void VIntegerProperty::valueChanged(int i) +{ + Q_UNUSED(i) + UserChangeEvent *event = new UserChangeEvent(); + QCoreApplication::postEvent ( VProperty::d_ptr->editor, event ); +} + + + + + +const double VDoubleProperty::StandardPrecision = 5; + +VDoubleProperty::VDoubleProperty(const QString& name, const QMap& settings) + : VIntegerProperty(name), Precision(StandardPrecision) +{ + VProperty::setSettings(settings); + VProperty::d_ptr->VariantValue.setValue(0); + VProperty::d_ptr->VariantValue.convert(QVariant::Double); + VProperty::d_ptr->PropertyVariantType = QVariant::Double; +} + +VDoubleProperty::VDoubleProperty(const QString &name) + : VIntegerProperty(name), Precision(StandardPrecision) +{ + VProperty::d_ptr->VariantValue.setValue(0); + VProperty::d_ptr->VariantValue.convert(QVariant::Double); + VProperty::d_ptr->PropertyVariantType = QVariant::Double; +} + +//! Returns an editor widget, or NULL if it doesn't supply one +QWidget* VDoubleProperty::createEditor(QWidget * parent, const QStyleOptionViewItem& options, const QAbstractItemDelegate* delegate) +{ + Q_UNUSED(options); + Q_UNUSED(delegate); + QDoubleSpinBox* tmpEditor = new QDoubleSpinBox(parent); + tmpEditor->setMinimum(min); + tmpEditor->setMaximum(max); + tmpEditor->setDecimals(Precision); + tmpEditor->setSingleStep(singleStep); + tmpEditor->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); + tmpEditor->setValue(VProperty::d_ptr->VariantValue.toDouble()); + connect(tmpEditor, static_cast(&QDoubleSpinBox::valueChanged), this, + &VIntegerProperty::valueChanged); + + VProperty::d_ptr->editor = tmpEditor; + return VProperty::d_ptr->editor; +} + +//! Gets the data from the widget +QVariant VDoubleProperty::getEditorData(QWidget* editor) const +{ + QDoubleSpinBox* tmpEditor = qobject_cast(editor); + if(tmpEditor) + return tmpEditor->value(); + + return QVariant(0); +} + +void VDoubleProperty::setSettings(double minimum, double maxiumum, double singleStep, int precision) +{ + min = minimum; + max = maxiumum; + this->singleStep = singleStep; + Precision = precision; +} + +void VDoubleProperty::setSetting(const QString& key, const QVariant& value) +{ + if(key == QLatin1String("Min")) + setSettings(value.toDouble(), max, singleStep, Precision); + else if(key == QLatin1String("Max")) + setSettings(min, value.toDouble(), singleStep, Precision); + else if(key == QLatin1String("Step")) + setSettings(min, max, value.toDouble(), Precision); + else if(key == QLatin1String("Precision")) + setSettings(min, max, singleStep, value.toDouble()); +} + +QVariant VDoubleProperty::getSetting(const QString& key) const +{ + if(key == QLatin1String("Min")) + return min; + if(key == QLatin1String("Max")) + return max; + if(key == QLatin1String("Step")) + return singleStep; + if(key == QLatin1String("Precision")) + return Precision; + else + return VProperty::getSetting(key); +} + +QStringList VDoubleProperty::getSettingKeys() const +{ + return (QStringList("Min") << "Max" << "Step" << "Precision"); +} + +QString VDoubleProperty::type() const +{ + return "double"; +} + +VProperty* VDoubleProperty::clone(bool include_children, VProperty* container) const +{ + return VIntegerProperty::clone(include_children, container ? container : new VDoubleProperty(getName())); +} diff --git a/src/libs/vpropertyexplorer/plugins/vnumberproperty.h b/src/libs/vpropertyexplorer/plugins/vnumberproperty.h new file mode 100644 index 000000000..bef7000df --- /dev/null +++ b/src/libs/vpropertyexplorer/plugins/vnumberproperty.h @@ -0,0 +1,118 @@ +#ifndef VNUMBERPROPERTY_H +#define VNUMBERPROPERTY_H + +#include "vpropertyexplorer_global.h" +#include "vproperty.h" + +namespace VPE { + + +//! Class for holding an integer property +class VPROPERTYEXPLORERSHARED_EXPORT VIntegerProperty : public VProperty +{ + Q_OBJECT +public: + VIntegerProperty(const QString& name, const QMap& settings); + + VIntegerProperty(const QString& name); + + //! Returns an editor widget, or NULL if it doesn't supply one + //! \param parent The widget to which the editor will be added as a child + //! \options Render options + //! \delegate A pointer to the QAbstractItemDelegate requesting the editor. This can be used to connect signals and slots. + virtual QWidget* createEditor(QWidget* parent, const QStyleOptionViewItem& options, const QAbstractItemDelegate* delegate); + + //! Gets the data from the widget + virtual QVariant getEditorData(QWidget* editor) const; + + //! Sets the settings of a basic integer property + //! \param minimum The minimum value + //! \param maxiumum The maximum value + virtual void setSettings(int minimum, int maxiumum, int singleStep = 1.0); + + //! Sets the settings. Available settings: + //! + //! key: "Min" - value: Minimum number as integer + //! key: "Max" - value: Maximum number as integer + virtual void setSetting(const QString& key, const QVariant& value); + + //! Get the settings. This function has to be implemented in a subclass in order to have an effect + virtual QVariant getSetting(const QString& key) const; + + //! Returns the list of keys of the property's settings + virtual QStringList getSettingKeys() const; + + //! Returns a string containing the type of the property + virtual QString type() const; + + //! Clones this property + //! \param include_children Indicates whether to also clone the children + //! \param container If a property is being passed here, no new VProperty is being created but instead it is tried to fill all the data into container. This can also be used when subclassing this function. + //! \return Returns the newly created property (or container, if it was not NULL) + virtual VProperty* clone(bool include_children = true, VProperty* container = NULL) const; +public slots: + void valueChanged(int i); +protected: + double min, max, singleStep; + + static const int StandardMin;// = -1000000; + static const int StandardMax;// = 1000000; +}; + + +//! Class for holding a double property +class VPROPERTYEXPLORERSHARED_EXPORT VDoubleProperty : public VIntegerProperty +{ + Q_OBJECT +public: + VDoubleProperty(const QString& name, const QMap& settings); + + VDoubleProperty(const QString& name); + + //! Returns an editor widget, or NULL if it doesn't supply one + //! \param parent The widget to which the editor will be added as a child + //! \options Render options + //! \delegate A pointer to the QAbstractItemDelegate requesting the editor. This can be used to connect signals and slots. + virtual QWidget* createEditor(QWidget* parent, const QStyleOptionViewItem& options, const QAbstractItemDelegate* delegate); + + //! Gets the data from the widget + virtual QVariant getEditorData(QWidget* editor) const; + + //! Sets the settings of a double property + //! \param minimum The minimum value + //! \param maxiumum The maximum value + //! \param precision The number of decimal places + virtual void setSettings(double minimum, double maxiumum, double singleStep, int precision); + + //! Sets the settings. Available settings: + //! + //! key: "Min" - value: Minimum number as integer + //! key: "Max" - value: Maximum number as integer + virtual void setSetting(const QString& key, const QVariant& value); + + //! Get the settings. This function has to be implemented in a subclass in order to have an effect + virtual QVariant getSetting(const QString& key) const; + + //! Returns the list of keys of the property's settings + virtual QStringList getSettingKeys() const; + + //! Returns a string containing the type of the property + virtual QString type() const; + + //! Clones this property + //! \param include_children Indicates whether to also clone the children + //! \param container If a property is being passed here, no new VProperty is being created but instead it is tried to fill all the data into container. This can also be used when subclassing this function. + //! \return Returns the newly created property (or container, if it was not NULL) + virtual VProperty* clone(bool include_children = true, VProperty* container = NULL) const; + +protected: + //! Number of decimals after the decimal point + int Precision; + + const static double StandardPrecision;// = 5; +}; + + +} + +#endif // VNUMBERPROPERTY_H diff --git a/src/libs/vpropertyexplorer/plugins/vobjectproperty.cpp b/src/libs/vpropertyexplorer/plugins/vobjectproperty.cpp new file mode 100644 index 000000000..1687dc2cf --- /dev/null +++ b/src/libs/vpropertyexplorer/plugins/vobjectproperty.cpp @@ -0,0 +1,156 @@ +/************************************************************************ + ** + ** @file vobjectproperty.cpp + ** @author Roman Telezhynskyi + ** @date 28 8, 2014 + ** + ** @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 "vobjectproperty.h" +#include "vproperty_p.h" + +#include +#include +#include + +using namespace VPE; + +VObjectProperty::VObjectProperty(const QString& name) + : VProperty(name, QVariant::Int) +{ + VProperty::d_ptr->VariantValue = 0; + VProperty::d_ptr->VariantValue.convert(QVariant::UInt); +} + +//! Get the data how it should be displayed +QVariant VObjectProperty::data (int column, int role) const +{ + if(objects.empty()) + return QVariant(); + + QComboBox* tmpEditor = qobject_cast(VProperty::d_ptr->editor); + + if(column == DPC_Data && Qt::DisplayRole == role) + { + return VProperty::d_ptr->VariantValue; + } + else if(column == DPC_Data && Qt::EditRole == role) + return tmpEditor->currentIndex(); + else + return VProperty::data(column, role); +} + +//! Returns an editor widget, or NULL if it doesn't supply one +QWidget* VObjectProperty::createEditor(QWidget * parent, const QStyleOptionViewItem& options, + const QAbstractItemDelegate* delegate) +{ + Q_UNUSED(options); + Q_UNUSED(delegate); + QComboBox* tmpEditor = new QComboBox(parent); + tmpEditor->clear(); + FillList(tmpEditor, objects); + tmpEditor->setCurrentIndex(tmpEditor->findData(VProperty::d_ptr->VariantValue.toUInt())); + connect(tmpEditor, static_cast(&QComboBox::currentIndexChanged), this, + &VObjectProperty::currentIndexChanged); + + VProperty::d_ptr->editor = tmpEditor; + return VProperty::d_ptr->editor; +} + +bool VObjectProperty::setEditorData(QWidget *editor) +{ + if(!editor) + return false; + + QComboBox* tmpEditor = qobject_cast(editor); + if(tmpEditor) + { + quint32 objId = VProperty::d_ptr->VariantValue.toUInt(); + qint32 tmpIndex = tmpEditor->findData(objId); + + if (tmpIndex == -1) + { + tmpIndex = 0; + } + tmpEditor->blockSignals(true); + tmpEditor->setCurrentIndex(tmpIndex); + tmpEditor->blockSignals(false); + return true; + } + + return false; +} + +//! Gets the data from the widget +QVariant VObjectProperty::getEditorData(QWidget* editor) const +{ + QComboBox* tmpEditor = qobject_cast(editor); + if(tmpEditor) + return tmpEditor->itemData(tmpEditor->currentIndex()); + + return QVariant(0); +} + +//! Sets the objects list +void VObjectProperty::setObjectsList(const QMap &objects) +{ + this->objects = objects; +} + +//! Get the settings. This function has to be implemented in a subclass in order to have an effect +QMap VObjectProperty::getObjects() const +{ + return objects; +} + +//! Sets the value of the property +void VObjectProperty::setValue(const QVariant& value) +{ + VProperty::d_ptr->VariantValue = value; + VProperty::d_ptr->VariantValue.convert(QVariant::UInt); + + if (VProperty::d_ptr->editor != nullptr) + { + setEditorData(VProperty::d_ptr->editor); + } +} + +QString VObjectProperty::type() const +{ + return "objectList"; +} + +VProperty* VObjectProperty::clone(bool include_children, VProperty* container) const +{ + return VProperty::clone(include_children, container ? container : new VObjectProperty(getName())); +} + +void VObjectProperty::currentIndexChanged(int index) +{ + Q_UNUSED(index) + UserChangeEvent *event = new UserChangeEvent(); + QCoreApplication::postEvent ( VProperty::d_ptr->editor, event ); +} + +void VObjectProperty::FillList(QComboBox *box, const QMap &list) const +{ + box->clear(); + + QMap::const_iterator i; + for (i = list.constBegin(); i != list.constEnd(); ++i) + { + box->addItem(i.key(), i.value()); + } +} diff --git a/src/libs/vpropertyexplorer/plugins/vobjectproperty.h b/src/libs/vpropertyexplorer/plugins/vobjectproperty.h new file mode 100644 index 000000000..7ea6246bd --- /dev/null +++ b/src/libs/vpropertyexplorer/plugins/vobjectproperty.h @@ -0,0 +1,88 @@ +/************************************************************************ + ** + ** @file vobjectproperty.h + ** @author Roman Telezhynskyi + ** @date 28 8, 2014 + ** + ** @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. + ** + *************************************************************************/ + +#ifndef VOBJECTPROPERTY_H +#define VOBJECTPROPERTY_H + +#include "vproperty.h" + +#include + +class QComboBox; + +namespace VPE{ + +class VPROPERTYEXPLORERSHARED_EXPORT VObjectProperty : public VProperty +{ + Q_OBJECT +public: + //! Constructor + VObjectProperty(const QString& name); + + //! Destructor + ~VObjectProperty() {} + + //! Get the data how it should be displayed + virtual QVariant data (int column = DPC_Name, int role = Qt::DisplayRole) const; + + //! Returns an editor widget, or NULL if it doesn't supply one + //! \param parent The widget to which the editor will be added as a child + //! \options Render options + //! \delegate A pointer to the QAbstractItemDelegate requesting the editor. This can be used to connect signals and slots. + virtual QWidget* createEditor(QWidget* parent, const QStyleOptionViewItem& options, const QAbstractItemDelegate* delegate); + + //! Sets the property's data to the editor (returns false, if the standard delegate should do that) + virtual bool setEditorData(QWidget* editor); + + //! Gets the data from the widget + virtual QVariant getEditorData(QWidget* editor) const; + + //! Sets the objects list + void setObjectsList(const QMap &objects); + + //! Get the settings. This function has to be implemented in a subclass in order to have an effect + virtual QMap getObjects() const; + + //! Sets the value of the property + virtual void setValue(const QVariant& value); + + //! Returns a string containing the type of the property + virtual QString type() const; + + //! Clones this property + //! \param include_children Indicates whether to also clone the children + //! \param container If a property is being passed here, no new VProperty is being created but instead it is tried to fill all the data into container. This can also be used when subclassing this function. + //! \return Returns the newly created property (or container, if it was not NULL) + virtual VProperty* clone(bool include_children = true, VProperty* container = nullptr) const; + +public slots: + void currentIndexChanged(int index); + +protected: + //! The list of possible objects + QMap objects; + + void FillList(QComboBox *box, const QMap &list)const; + // No use of d-pointer in this case, because it is unlikely this will change. If it does, we can still add other members by reimplementing the VPropertyPrivate class without touching this header file. +}; + +} + +#endif // VOBJECTPROPERTY_H diff --git a/src/libs/vpropertyexplorer/plugins/vpointfproperty.cpp b/src/libs/vpropertyexplorer/plugins/vpointfproperty.cpp new file mode 100644 index 000000000..8d923502d --- /dev/null +++ b/src/libs/vpropertyexplorer/plugins/vpointfproperty.cpp @@ -0,0 +1,129 @@ +/************************************************************************ + ** + ** @file vpointfproperty.cpp + ** @author Roman Telezhynskyi + ** @date 27 8, 2014 + ** + ** @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 "vpointfproperty.h" + +using namespace VPE; + +#include "vproperty_p.h" +#include "vnumberproperty.h" +#include + +VPE::VPointFProperty::VPointFProperty(const QString &name) + : VProperty(name, QVariant::PointF) +{ + d_ptr->VariantValue.setValue(0); + d_ptr->VariantValue.convert(QVariant::PointF); + + VDoubleProperty* tmpX = new VDoubleProperty("X"); + addChild(tmpX); + tmpX->setUpdateBehaviour(true, false); + + VDoubleProperty* tmpY = new VDoubleProperty("Y"); + addChild(tmpY); + tmpY->setUpdateBehaviour(true, false); + + setValue(QPointF()); +} + +QVariant VPointFProperty::data(int column, int role) const +{ + if(column == DPC_Data && Qt::DisplayRole == role) + { + return getPointF(); + } + else + return VProperty::data(column, role); +} + +Qt::ItemFlags VPointFProperty::flags(int column) const +{ + if(column == DPC_Name || column == DPC_Data) + return Qt::ItemIsEnabled | Qt::ItemIsSelectable; + else + return Qt::NoItemFlags; +} + +QPointF VPointFProperty::getPointF() const +{ + QPointF tmpValue; + + if(d_ptr->Children.count() < 2) + return tmpValue; + + tmpValue.setX(d_ptr->Children.at(0)->getValue().toDouble()); + tmpValue.setY(d_ptr->Children.at(1)->getValue().toDouble()); + + return tmpValue; +} + +void VPointFProperty::setPointF(const QPointF &point) +{ + setPointF(point.x(), point.y()); +} + +void VPointFProperty::setPointF(qreal x, qreal y) +{ + if(d_ptr->Children.count() < 2) + return; + + QVariant tmpX(x); + tmpX.convert(QVariant::Double); + + QVariant tmpY(y); + tmpY.convert(QVariant::Double); + + d_ptr->Children.at(0)->setValue(tmpX); + d_ptr->Children.at(1)->setValue(tmpY); +} + +QString VPointFProperty::type() const +{ + return "pointF"; +} + +VProperty *VPointFProperty::clone(bool include_children, VProperty *container) const +{ + if(!container) { + container = new VPointFProperty(getName()); + + if(!include_children) { + QList tmpChildren = container->getChildren(); + foreach(VProperty* tmpChild, tmpChildren) { + container->removeChild(tmpChild); + delete tmpChild; + } + } + } + + return VProperty::clone(false, container); // Child +} + +void VPointFProperty::setValue(const QVariant &value) +{ + QPointF tmpPoint = value.toPointF(); + setPointF(tmpPoint); +} + +QVariant VPointFProperty::getValue() const +{ + QPointF tmpValue = getPointF(); + return QString("%1,%2").arg(QString::number(tmpValue.x()), QString::number(tmpValue.y())); +} diff --git a/src/libs/vpropertyexplorer/plugins/vpointfproperty.h b/src/libs/vpropertyexplorer/plugins/vpointfproperty.h new file mode 100644 index 000000000..2029dd304 --- /dev/null +++ b/src/libs/vpropertyexplorer/plugins/vpointfproperty.h @@ -0,0 +1,71 @@ +/************************************************************************ + ** + ** @file vpointfproperty.h + ** @author Roman Telezhynskyi + ** @date 27 8, 2014 + ** + ** @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. + ** + *************************************************************************/ + +#ifndef VPOINTFPROPERTY_H +#define VPOINTFPROPERTY_H + +#include "vpropertyexplorer_global.h" + +#include "vproperty.h" + +namespace VPE{ + +class VPROPERTYEXPLORERSHARED_EXPORT VPointFProperty : public VProperty +{ +public: + VPointFProperty(const QString& name); + + virtual ~VPointFProperty() {} + + //! Get the data how it should be displayed + virtual QVariant data (int column = DPC_Name, int role = Qt::DisplayRole) const; + + //! Returns item flags + Qt::ItemFlags flags(int column = DPC_Name) const; + + //! Returns the QPointF + virtual QPointF getPointF() const; + + //! Sets the QPointF + virtual void setPointF(const QPointF& point); + + //! Sets the QPointF + virtual void setPointF(qreal x, qreal y); + + //! Returns a string containing the type of the property + virtual QString type() const; + + //! Clones this property + //! \param include_children Indicates whether to also clone the children + //! \param container If a property is being passed here, no new VProperty is being created but instead it is tried to fill all the data into container. This can also be used when subclassing this function. + //! \return Returns the newly created property (or container, if it was not NULL) + virtual VProperty* clone(bool include_children = true, VProperty* container = NULL) const; + + //! Sets the value of the property + virtual void setValue(const QVariant& value); + + //! Returns the value of the property as a QVariant + virtual QVariant getValue() const; + +}; + +} + +#endif // VPOINTFPROPERTY_H diff --git a/src/libs/vpropertyexplorer/plugins/vshortcutproperty.cpp b/src/libs/vpropertyexplorer/plugins/vshortcutproperty.cpp new file mode 100644 index 000000000..79772108c --- /dev/null +++ b/src/libs/vpropertyexplorer/plugins/vshortcutproperty.cpp @@ -0,0 +1,84 @@ +#include "vshortcutproperty.h" +#include +#include + +#include "vshortcutpropertyeditor.h" + +#include "vproperty_p.h" + + +using namespace VPE; + +VShortcutProperty::VShortcutProperty(const QString& name) + : VProperty(name, QVariant::String) +{ + +} + +VShortcutProperty::~VShortcutProperty() +{ + // +} + +QVariant VShortcutProperty::data (int column, int role) const +{ + if(column == DPC_Data && (Qt::DisplayRole == role || Qt::EditRole == role)) + { + return d_ptr->VariantValue; + } + else + return VProperty::data(column, role); +} + + +QWidget* VShortcutProperty::createEditor(QWidget * parent, const QStyleOptionViewItem& options, + const QAbstractItemDelegate* delegate) +{ + Q_UNUSED(options); + + VShortcutEditWidget* tmpWidget = new VShortcutEditWidget(parent); + if(delegate) + VShortcutEditWidget::connect(tmpWidget, SIGNAL(commitData(QWidget*)), delegate, SIGNAL(commitData(QWidget*))); + + return tmpWidget; + return nullptr; +} + + +bool VShortcutProperty::setEditorData(QWidget* editor) +{ + VShortcutEditWidget* tmpWidget = qobject_cast(editor); + if(tmpWidget) + tmpWidget->setShortcut(d_ptr->VariantValue.toString(), false); + else + return false; + + return true; +} + + +QVariant VShortcutProperty::getEditorData(QWidget* editor) const +{ + VShortcutEditWidget* tmpWidget = qobject_cast(editor); + if(tmpWidget) + return tmpWidget->getShortcutAsString(); + + return QVariant(); +} + + +QString VShortcutProperty::type() const +{ + return "shortcut"; +} + +VProperty* VShortcutProperty::clone(bool include_children, VProperty* container) const +{ + return VProperty::clone(include_children, container ? container : new VShortcutProperty(getName())); +} + +void VShortcutProperty::setValue(const QVariant &value) +{ + VProperty::setValue(QKeySequence::fromString(value.toString()).toString()); +} + diff --git a/src/libs/vpropertyexplorer/plugins/vshortcutproperty.h b/src/libs/vpropertyexplorer/plugins/vshortcutproperty.h new file mode 100644 index 000000000..f8be59e6b --- /dev/null +++ b/src/libs/vpropertyexplorer/plugins/vshortcutproperty.h @@ -0,0 +1,49 @@ +#ifndef VSHORTCUTROPERTY_H +#define VSHORTCUTROPERTY_H + +#include "vpropertyexplorer_global.h" +#include "vproperty.h" + +namespace VPE { + +//! This property can be used to handle key shortcuts +class VPROPERTYEXPLORERSHARED_EXPORT VShortcutProperty : public VProperty +{ +public: + VShortcutProperty(const QString &name); + + //! The destructor + ~VShortcutProperty(); + + //! Get the data how it should be displayed + virtual QVariant data (int column = DPC_Name, int role = Qt::DisplayRole) const; + + //! Returns an editor widget, or NULL if it doesn't supply one + //! \param parent The widget to which the editor will be added as a child + //! \options Render options + //! \delegate A pointer to the QAbstractItemDelegate requesting the editor. This can be used to connect signals and slots. + virtual QWidget* createEditor(QWidget* parent, const QStyleOptionViewItem& options, + const QAbstractItemDelegate* delegate); + + //! Sets the property's data to the editor (returns false, if the standard delegate should do that) + virtual bool setEditorData(QWidget* editor); + + //! Gets the data from the widget + virtual QVariant getEditorData(QWidget* editor) const; + + //! Returns a string containing the type of the property + virtual QString type() const; + + //! Clones this property + //! \param include_children Indicates whether to also clone the children + //! \param container If a property is being passed here, no new VProperty is being created but instead it is tried to fill all the data into container. This can also be used when subclassing this function. + //! \return Returns the newly created property (or container, if it was not NULL) + virtual VProperty* clone(bool include_children = true, VProperty* container = NULL) const; + + //! Sets the value of the property + virtual void setValue(const QVariant& value); +}; + +} + +#endif // VFILEPROPERTY_H diff --git a/src/libs/vpropertyexplorer/plugins/vshortcutpropertyeditor.cpp b/src/libs/vpropertyexplorer/plugins/vshortcutpropertyeditor.cpp new file mode 100644 index 000000000..4defbebe9 --- /dev/null +++ b/src/libs/vpropertyexplorer/plugins/vshortcutpropertyeditor.cpp @@ -0,0 +1,86 @@ +#include "vshortcutpropertyeditor.h" + +#include +#include + +using namespace VPE; + +VShortcutEditWidget::VShortcutEditWidget(QWidget *parent) + : QWidget(parent) +{ + // Create the line edit widget + LineEdit = new QLineEdit(this); + LineEdit->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); + LineEdit->clear(); + LineEdit->installEventFilter(this); + setFocusProxy(LineEdit); + connect(LineEdit, SIGNAL(textEdited(QString)), this, SLOT(onTextEdited(QString))); + + // The layout (a horizontal layout) + QHBoxLayout* layout = new QHBoxLayout(this); + layout->setSpacing(0); + layout->setMargin(0); + layout->addWidget(LineEdit); +} + + +VShortcutEditWidget::~VShortcutEditWidget() +{ + // nothing needs to be done here +} + +bool VShortcutEditWidget::eventFilter(QObject *obj, QEvent *event) +{ + if (obj == LineEdit) { + if (event->type() == QEvent::KeyPress) { + QKeyEvent *keyEvent = static_cast(event); + + int keys = keyEvent->key(); + + if(keys != Qt::Key_Shift && + keys != Qt::Key_Control && + keys != Qt::Key_Meta && + keys != Qt::Key_AltGr && + keys != Qt::Key_Alt) + { + keys += keyEvent->modifiers(); + setShortcut(QKeySequence(keys), true); + return true; + } + } + } + + return QWidget::eventFilter(obj, event); +} + +QString VShortcutEditWidget::getShortcutAsString() +{ + return CurrentKeySequence.toString(); +} + +QKeySequence VShortcutEditWidget::getShortcut() +{ + return CurrentKeySequence; +} + + + +void VShortcutEditWidget::setShortcut(const QString &shortcut, bool emit_signal) +{ + setShortcut(QKeySequence::fromString(shortcut), emit_signal); +} + +void VShortcutEditWidget::setShortcut(const QKeySequence &shortcut, bool emit_signal) +{ + if(shortcut != CurrentKeySequence) { + CurrentKeySequence = shortcut; + LineEdit->setText(CurrentKeySequence.toString()); + if(emit_signal) + emit dataChangedByUser(CurrentKeySequence, this); + } +} + +void VShortcutEditWidget::onTextEdited(const QString &text) +{ + setShortcut(text, true); +} diff --git a/src/libs/vpropertyexplorer/plugins/vshortcutpropertyeditor.h b/src/libs/vpropertyexplorer/plugins/vshortcutpropertyeditor.h new file mode 100644 index 000000000..8e907c161 --- /dev/null +++ b/src/libs/vpropertyexplorer/plugins/vshortcutpropertyeditor.h @@ -0,0 +1,64 @@ +#ifndef VSHORTCUTPROPERTYEDITOR_H +#define VSHORTCUTPROPERTYEDITOR_H + +#include "vpropertyexplorer_global.h" + +#include +#include +#include +#include + +namespace VPE{ + + +class VPROPERTYEXPLORERSHARED_EXPORT VShortcutEditWidget : public QWidget +{ + Q_OBJECT + +public: + VShortcutEditWidget(QWidget* parent); + virtual ~VShortcutEditWidget(); + + //! Needed for proper event handling + bool eventFilter(QObject* obj, QEvent* evenvt); + + //! Returns the currently set shortcut + QString getShortcutAsString(); + + //! Returns the currently set shortcut + QKeySequence getShortcut(); + +signals: + //! This signal is emitted when the user changed the current shortcut + void dataChangedByUser(const QKeySequence& sequence, VShortcutEditWidget* editor); + + //! This signal is emitted whenever dataChangedByUser() gets emmitted + //! and is connected to the delegate's commitData() signal + void commitData(QWidget* editor); + +public slots: + //! Sets the shortcut + //! \param shortcut The new shortcut + //! \emit_signal If true, this will emit the dataChangedByUser()-signal + void setShortcut(const QString &shortcut, bool emit_signal); + + //! Sets the shortcut + //! \param shortcut The new shortcut + //! \emit_signal If true, this will emit the dataChangedByUser()-signal + void setShortcut(const QKeySequence &shortcut, bool emit_signal); + +private slots: + //! This slot is called when the user edits the line edit (e.g. by removing or pasting text using the mouse) + void onTextEdited(const QString& text); + +protected: + //! The current key sequence + QKeySequence CurrentKeySequence; + + //! The line to display and edit the key sequence + QLineEdit* LineEdit; +}; + +} + +#endif // VFILEPROPERTYEDITOR_H diff --git a/src/libs/vpropertyexplorer/plugins/vstringproperty.cpp b/src/libs/vpropertyexplorer/plugins/vstringproperty.cpp new file mode 100644 index 000000000..89ad53579 --- /dev/null +++ b/src/libs/vpropertyexplorer/plugins/vstringproperty.cpp @@ -0,0 +1,124 @@ +/************************************************************************ + ** + ** @file vstringproperty.cpp + ** @author Roman Telezhynskyi + ** @date 27 8, 2014 + ** + ** @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 "vstringproperty.h" + +#include +#include + +#include "vproperty_p.h" + +using namespace VPE; + + +VPE::VStringProperty::VStringProperty(const QString &name, const QMap &settings) + : VProperty(name, QVariant::String), readOnly(false), typeForParent(0) +{ + VProperty::setSettings(settings); + d_ptr->VariantValue.setValue(QStringLiteral("")); + d_ptr->VariantValue.convert(QVariant::String); +} + +VPE::VStringProperty::VStringProperty(const QString &name) + : VProperty(name), readOnly(false), typeForParent(0) +{ + d_ptr->VariantValue.setValue(QStringLiteral("")); + d_ptr->VariantValue.convert(QVariant::String); +} + +QWidget *VPE::VStringProperty::createEditor(QWidget *parent, const QStyleOptionViewItem &options, + const QAbstractItemDelegate *delegate) +{ + Q_UNUSED(options); + Q_UNUSED(delegate); + + QLineEdit* tmpEditor = new QLineEdit(parent); + tmpEditor->setReadOnly(readOnly); + tmpEditor->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); + tmpEditor->setText(d_ptr->VariantValue.toString()); + + d_ptr->editor = tmpEditor; + return d_ptr->editor; +} + +QVariant VPE::VStringProperty::getEditorData(QWidget *editor) const +{ + QLineEdit* tmpEditor = qobject_cast(editor); + if(tmpEditor) + return tmpEditor->text(); + + return QVariant(QStringLiteral("")); +} + +void VPE::VStringProperty::setReadOnly(bool readOnly) +{ + this->readOnly = readOnly; +} + +void VPE::VStringProperty::setSetting(const QString &key, const QVariant &value) +{ + if(key == QLatin1String("ReadOnly")) + setReadOnly(value.toBool()); + if(key == QLatin1String("TypeForParent")) + setTypeForParent(value.toInt()); +} + +QVariant VPE::VStringProperty::getSetting(const QString &key) const +{ + if(key == QLatin1String("ReadOnly")) + return readOnly; + else if (key == QLatin1String("TypeForParent")) + return typeForParent; + else + return VProperty::getSetting(key); +} + +QStringList VPE::VStringProperty::getSettingKeys() const +{ + QStringList settings; + settings << QStringLiteral("ReadOnly") << QStringLiteral("TypeForParent"); + return settings; +} + +QString VPE::VStringProperty::type() const +{ + return QStringLiteral("string"); +} + +VPE::VProperty *VPE::VStringProperty::clone(bool include_children, VPE::VProperty *container) const +{ + return VProperty::clone(include_children, container ? container : new VStringProperty(getName(), getSettings())); +} + +void VStringProperty::UpdateParent(const QVariant &value) +{ + emit childChanged(value, typeForParent); +} + +int VStringProperty::getTypeForParent() const +{ + return typeForParent; +} + +void VStringProperty::setTypeForParent(int value) +{ + typeForParent = value; +} + diff --git a/src/libs/vpropertyexplorer/plugins/vstringproperty.h b/src/libs/vpropertyexplorer/plugins/vstringproperty.h new file mode 100644 index 000000000..105fa7deb --- /dev/null +++ b/src/libs/vpropertyexplorer/plugins/vstringproperty.h @@ -0,0 +1,78 @@ +/************************************************************************ + ** + ** @file vstringproperty.h + ** @author Roman Telezhynskyi + ** @date 27 8, 2014 + ** + ** @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. + ** + *************************************************************************/ + +#ifndef VSTRINGPROPERTY_H +#define VSTRINGPROPERTY_H + +#include "vpropertyexplorer_global.h" +#include "vproperty.h" + +namespace VPE { + + +//! Class for holding a string property +class VPROPERTYEXPLORERSHARED_EXPORT VStringProperty : public VProperty +{ +public: + VStringProperty(const QString& name, const QMap& settings); + + VStringProperty(const QString& name); + + //! Returns an editor widget, or NULL if it doesn't supply one + //! \param parent The widget to which the editor will be added as a child + //! \options Render options + //! \delegate A pointer to the QAbstractItemDelegate requesting the editor. This can be used to connect signals and slots. + virtual QWidget* createEditor(QWidget* parent, const QStyleOptionViewItem& options, const QAbstractItemDelegate* delegate); + + //! Gets the data from the widget + virtual QVariant getEditorData(QWidget* editor) const; + + void setReadOnly(bool readOnly); + + //! Sets the settings. + virtual void setSetting(const QString& key, const QVariant& value); + + //! Get the settings. This function has to be implemented in a subclass in order to have an effect + virtual QVariant getSetting(const QString& key) const; + + //! Returns the list of keys of the property's settings + virtual QStringList getSettingKeys() const; + + //! Returns a string containing the type of the property + virtual QString type() const; + + //! Clones this property + //! \param include_children Indicates whether to also clone the children + //! \param container If a property is being passed here, no new VProperty is being created but instead it is tried to fill all the data into container. This can also be used when subclassing this function. + //! \return Returns the newly created property (or container, if it was not NULL) + virtual VProperty* clone(bool include_children = true, VProperty* container = nullptr) const; + + virtual void UpdateParent(const QVariant &value); + + int getTypeForParent() const; + void setTypeForParent(int value); + +protected: + bool readOnly; + int typeForParent; +}; + +} +#endif // VSTRINGPROPERTY_H diff --git a/src/libs/vpropertyexplorer/plugins/vwidgetproperty.cpp b/src/libs/vpropertyexplorer/plugins/vwidgetproperty.cpp new file mode 100644 index 000000000..2082ffdd5 --- /dev/null +++ b/src/libs/vpropertyexplorer/plugins/vwidgetproperty.cpp @@ -0,0 +1,46 @@ +#include "vwidgetproperty.h" + + +#include "vwidgetproperty_p.h" + +using namespace VPE; + + + + +VWidgetProperty::VWidgetProperty(const QString& name, QWidget* widget) + : VEmptyProperty(new VWidgetPropertyPrivate(name, QVariant::Invalid, widget)) +{ +} + +VWidgetProperty::~VWidgetProperty() +{ + // +} + +QWidget *VWidgetProperty::getWidget() const +{ + return static_cast(d_ptr)->Widget.data(); +} + +void VWidgetProperty::setWidget(QWidget* widget) +{ + VWidgetPropertyPrivate* tmpDPtr = static_cast(d_ptr); + QWidget* tmpOldWidget = tmpDPtr->Widget.data(); + if(tmpOldWidget) + tmpOldWidget->deleteLater(); + + tmpDPtr->Widget = widget; +} + + +QString VWidgetProperty::type() const +{ + return "widget"; +} + +VProperty* VWidgetProperty::clone(bool include_children, VProperty* container) const +{ + // todo: This is a tricky one to clone... don't know what would be the best way to do so... Maybe serialize the widget somehow? + return VProperty::clone(include_children, container ? container : new VWidgetProperty(getName())); +} diff --git a/src/libs/vpropertyexplorer/plugins/vwidgetproperty.h b/src/libs/vpropertyexplorer/plugins/vwidgetproperty.h new file mode 100644 index 000000000..a2de4f078 --- /dev/null +++ b/src/libs/vpropertyexplorer/plugins/vwidgetproperty.h @@ -0,0 +1,42 @@ +#ifndef VWIDGETROPERTY_H +#define VWIDGETROPERTY_H + +#include "vpropertyexplorer_global.h" + +#include "vemptyproperty.h" + +#include + +namespace VPE { + +// todo: this way, this class doesn't really make sense. What we have to do is pass a widget factory instead of the actual widget! + +//! This property holds a QWidget and displays it, if the view supports that. If not, it will behave like an empty property +class VPROPERTYEXPLORERSHARED_EXPORT VWidgetProperty : public VEmptyProperty +{ +public: + //! Constructor + VWidgetProperty(const QString &name, QWidget* widget = nullptr); + + //! The destructor + ~VWidgetProperty(); + + //! Returns the widget held by this property + QWidget* getWidget() const; + + //! Sets the widget for this property. If there is already an old one, it will be deleted. + void setWidget(QWidget* widget); + + //! Returns a string containing the type of the property + virtual QString type() const; + + //! Clones this property + //! \param include_children Indicates whether to also clone the children + //! \param container If a property is being passed here, no new VProperty is being created but instead it is tried to fill all the data into container. This can also be used when subclassing this function. + //! \return Returns the newly created property (or container, if it was not NULL) + virtual VProperty* clone(bool include_children = true, VProperty* container = nullptr) const; +}; + +} + +#endif // VWIDGETROPERTY_H diff --git a/src/libs/vpropertyexplorer/vabstractpropertyfactory.h b/src/libs/vpropertyexplorer/vabstractpropertyfactory.h new file mode 100644 index 000000000..832fd8fdd --- /dev/null +++ b/src/libs/vpropertyexplorer/vabstractpropertyfactory.h @@ -0,0 +1,26 @@ +#ifndef VABSTRACTPROPERTYFACTORY_H +#define VABSTRACTPROPERTYFACTORY_H + +#include "vpropertyexplorer_global.h" +#include + +namespace VPE { + +class VProperty; + +class VPROPERTYEXPLORERSHARED_EXPORT VAbstractPropertyFactory +{ +public: + //! Empty virtual destructor + virtual ~VAbstractPropertyFactory() {} + + //! Creates a new property of a certain type and assigns a name and description (otionally) + //! \param type The type of the property as string + //! \param name The property's name + //! \return Returns the created property or NULL if it couldn't be be created + virtual VProperty* createProperty(const QString& type, const QString &name) = 0; +}; + +} + +#endif // VABSTRACTPROPERTYFACTORY_H diff --git a/src/libs/vpropertyexplorer/vfileproperty_p.h b/src/libs/vpropertyexplorer/vfileproperty_p.h new file mode 100644 index 000000000..6e2dc8ee0 --- /dev/null +++ b/src/libs/vpropertyexplorer/vfileproperty_p.h @@ -0,0 +1,30 @@ +#ifndef VFILEPROPERTY_P_H +#define VFILEPROPERTY_P_H + +// ONLY INCLUDE THIS IN .CPP FILES + +#include "vproperty_p.h" + +namespace VPE { + +class VFilePropertyPrivate : public VPropertyPrivate { +public: + //! File filters + QString FileFilters; + + //! Determines whether the file property is a file or a directory. Default: false + bool Directory; + + + //! Constructor passing name and type + VFilePropertyPrivate(const QString& name, QVariant::Type type, bool directory = false) + : VPropertyPrivate(name, type), FileFilters(), Directory(directory) {} + + //! Constructor + VFilePropertyPrivate() + : VPropertyPrivate(), FileFilters(), Directory(false) {} +}; + +} + +#endif // VFILEPROPERTY_P_H diff --git a/src/libs/vpropertyexplorer/vproperties.h b/src/libs/vpropertyexplorer/vproperties.h new file mode 100644 index 000000000..b33eff79c --- /dev/null +++ b/src/libs/vpropertyexplorer/vproperties.h @@ -0,0 +1,46 @@ +/************************************************************************ + ** + ** @file vproperties.h + ** @author Roman Telezhynskyi + ** @date 28 8, 2014 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2014 Valentina project + ** All Rights Reserved. + ** + ** Valentina 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. + ** + ** Valentina 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 for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with Valentina. If not, see . + ** + *************************************************************************/ + +#ifndef VPROPERTIES_H +#define VPROPERTIES_H + +#include "vproperty.h" +#include "plugins/vboolproperty.h" +#include "plugins/vcolorproperty.h" +#include "plugins/Vector3d/vvector3dproperty.h" +#include "plugins/vemptyproperty.h" +#include "plugins/venumproperty.h" +#include "plugins/vfileproperty.h" +#include "plugins/vnumberproperty.h" +#include "plugins/vobjectproperty.h" +#include "plugins/vpointfproperty.h" +#include "plugins/vshortcutproperty.h" +#include "plugins/vstringproperty.h" +#include "plugins/vwidgetproperty.h" + +#endif // VPROPERTIES_H diff --git a/src/libs/vpropertyexplorer/vproperty.cpp b/src/libs/vpropertyexplorer/vproperty.cpp new file mode 100644 index 000000000..caab96b48 --- /dev/null +++ b/src/libs/vpropertyexplorer/vproperty.cpp @@ -0,0 +1,365 @@ +#include "vproperty.h" +#include +#include +#include +#include + +#include "vproperty_p.h" + +using namespace VPE; + +//! Standard constructor, takes a name and a parent property as argument +VProperty::VProperty(const QString& name, QVariant::Type type) + : QObject(), d_ptr(new VPropertyPrivate(name, type)) +{ + +} + +VProperty::VProperty(VPropertyPrivate *d) + : d_ptr(d) +{ +} + + +VProperty::~VProperty() +{ + setParent(nullptr); + + while(!d_ptr->Children.isEmpty()) + { + VProperty* tmpChild = d_ptr->Children.takeLast(); + delete tmpChild; + } + + delete d_ptr; +} + +QString VProperty::type() const +{ + return "string"; +} + +//! Get the data how it should be displayed +QVariant VProperty::data (int column, int role) const +{ + if(column == DPC_Name && Qt::DisplayRole == role) + return QVariant(d_ptr->Name); + else if(column == DPC_Data && (Qt::DisplayRole == role || Qt::EditRole == role)) + return d_ptr->VariantValue; + else if(Qt::ToolTipRole == role) + return QVariant(d_ptr->Description); + else + return QVariant(); +} + +bool VProperty::setData(const QVariant &data, int role) +{ + bool tmpResult = false; + if(Qt::EditRole == role) + { + tmpResult = (d_ptr->VariantValue != data); + setValue(data); + } + + return tmpResult; +} + +bool VProperty::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index, const QAbstractItemDelegate *delegate) const +{ + Q_UNUSED(painter); + Q_UNUSED(option); + Q_UNUSED(index); + Q_UNUSED(delegate); + + return false; +} + +//! Returns an editor widget, or NULL if it doesn't supply one +QWidget* VProperty::createEditor(QWidget * parent, const QStyleOptionViewItem& options, const QAbstractItemDelegate* delegate) +{ + Q_UNUSED(options); + Q_UNUSED(delegate); + + QItemEditorFactory *factory = new QItemEditorFactory; + QItemEditorCreatorBase *lineCreator = new QStandardItemEditorCreator(); + factory->registerEditor(QVariant::String, lineCreator); + QItemEditorFactory::setDefaultFactory(factory); + + d_ptr->editor = factory->createEditor(d_ptr->PropertyVariantType, parent); + return d_ptr->editor; +} + +bool VProperty::setEditorData(QWidget* editor) +{ + if(!editor) + return false; + + QByteArray n = editor->metaObject()->userProperty().name(); + + if (!n.isEmpty()) { + editor->blockSignals(true); + editor->setProperty(n, d_ptr->VariantValue); + editor->blockSignals(false); + return true; + } + + return false; +} + +//! Gets the data from the widget +QVariant VProperty::getEditorData(QWidget* editor) const +{ + if(!editor) + return QVariant(); + + QByteArray n = editor->metaObject()->userProperty().name(); + + if (!n.isEmpty()) + return editor->property(n); + else + return QVariant(); +} + +//! Returns item flags +Qt::ItemFlags VProperty::flags(int column) const +{ + if(column == DPC_Name) + return Qt::ItemIsEnabled | Qt::ItemIsSelectable; + else if(column == DPC_Data) + return Qt::ItemIsEnabled | Qt::ItemIsEditable | Qt::ItemIsSelectable; + else + return Qt::NoItemFlags; +} + + +void VProperty::setValue(const QVariant &value) +{ + d_ptr->VariantValue = value; + d_ptr->VariantValue.convert(d_ptr->PropertyVariantType); + if (d_ptr->editor != nullptr) + { + setEditorData(d_ptr->editor); + } +} + + +QVariant VProperty::getValue() const +{ + return d_ptr->VariantValue; +} + +QString VProperty::serialize() const +{ + return getValue().toString(); +} + +void VProperty::deserialize(const QString& value) +{ + setValue(QVariant(value)); +} + + +void VProperty::setName(const QString& name) +{ + d_ptr->Name = name; +} + + +QString VProperty::getName() const +{ + return d_ptr->Name; +} + + +void VProperty::setDescription(const QString& desc) +{ + d_ptr->Description = desc; +} + + +QString VProperty::getDescription() const +{ + return d_ptr->Description; +} + + + + +//! Returns a reference to the list of children +QList& VProperty::getChildren() +{ + return d_ptr->Children; +} + +//! Returns a reference to the list of children +const QList& VProperty::getChildren() const +{ + return d_ptr->Children; +} + +//! Returns the child at a certain row +VProperty* VProperty::getChild(int row) const +{ + if(row >= 0 && row < getRowCount()) + return d_ptr->Children.at(row); + else + return nullptr; +} + +//! Gets the number of children +int VProperty::getRowCount() const +{ + return d_ptr->Children.count(); +} + +//! Gets the parent of this property +VProperty* VProperty::getParent() const +{ + return d_ptr->Parent; +} + +//! Sets the parent of this property +void VProperty::setParent(VProperty* parent) +{ + if(d_ptr->Parent == parent) + return; + + VProperty* oldParent = d_ptr->Parent; + d_ptr->Parent = parent; + + if(oldParent) + oldParent->removeChild(this); + + if(d_ptr->Parent && d_ptr->Parent->getChildRow(this) == -1) + d_ptr->Parent->addChild(this); +} + +int VProperty::addChild(VProperty *child) +{ + if(child && child->getParent() != this) + child->setParent(this); + + if(!d_ptr->Children.contains(child) && child != nullptr) + { + d_ptr->Children.push_back(child); + return d_ptr->Children.count()-1; + } + else + { + return d_ptr->Children.indexOf(child); + } +} + +//! Removes a child from the children list +void VProperty::removeChild(VProperty* child) +{ + d_ptr->Children.removeAll(child); + + if(child && child->getParent() == this) + child->setParent(nullptr); +} + +//! Returns the row the child has +int VProperty::getChildRow(VProperty* child) const +{ + return d_ptr->Children.indexOf(child); +} + + +//! Returns whether the views have to update the parent of this property if it changes +bool VProperty::getUpdateParent() const +{ + return d_ptr->UpdateParent; +} + +//! Returns whether the views have to update the children of this property if it changes +bool VProperty::getUpdateChildren() const +{ + return d_ptr->UpdateChildren; +} + +//! Sets whether the views should update Parents or children after this property changes +void VProperty::setUpdateBehaviour(bool update_parent, bool update_children) +{ + d_ptr->UpdateParent = update_parent; + d_ptr->UpdateChildren = update_children; +} + + +void VProperty::setSettings(const QMap& settings) +{ + QMap::const_iterator tmpIterator = settings.constBegin(); + for (; tmpIterator != settings.constEnd(); ++tmpIterator) { + setSetting(tmpIterator.key(), tmpIterator.value()); + } +} + +QMap VProperty::getSettings() const +{ + QMap tmpResult; + + QStringList tmpKeyList = getSettingKeys(); + foreach(const QString& tmpKey, tmpKeyList) + tmpResult.insert(tmpKey, getSetting(tmpKey)); + + return tmpResult; +} + +void VProperty::setSetting(const QString& key, const QVariant& value) +{ + Q_UNUSED(key) + Q_UNUSED(value) + // Not needed in the Standard property +} + +QVariant VProperty::getSetting(const QString& key) const +{ + // Not needed in the Standard property + Q_UNUSED(key) + return QVariant(); +} + +QStringList VProperty::getSettingKeys() const +{ + return QStringList(); +} + +VProperty* VProperty::clone(bool include_children, VProperty* container) const +{ + if(!container) + container = new VProperty(getName(), d_ptr->PropertyVariantType); + + container->setName(getName()); + container->setDescription(getDescription()); + container->setValue(getValue()); + container->setSettings(getSettings()); + container->setUpdateBehaviour(getUpdateParent(), getUpdateChildren()); + container->setPropertyType(propertyType()); + + if(include_children) { + foreach(VProperty* tmpChild, d_ptr->Children) + container->addChild(tmpChild->clone(true)); + } + + return container; +} + +Property VProperty::propertyType() const +{ + return d_ptr->type; +} + +void VProperty::setPropertyType(const Property &type) +{ + d_ptr->type = type; +} + +void VProperty::UpdateParent(const QVariant &value) +{ + Q_UNUSED(value); +} + +void VProperty::ValueChildChanged(const QVariant &value, int typeForParent) +{ + +} diff --git a/src/libs/vpropertyexplorer/vproperty.h b/src/libs/vpropertyexplorer/vproperty.h new file mode 100644 index 000000000..b01531f86 --- /dev/null +++ b/src/libs/vpropertyexplorer/vproperty.h @@ -0,0 +1,187 @@ +#ifndef VPROPERTY_H +#define VPROPERTY_H + +#include "vpropertyexplorer_global.h" + +#include +#include +#include +#include +#include +#include + +namespace VPE { + +enum class Property : char{Simple, Complex}; + +static const int MyCustomEventType = 1099; + +class UserChangeEvent : public QEvent +{ +public: + UserChangeEvent() : QEvent((QEvent::Type)MyCustomEventType) {} +}; + +class VPropertyPrivate; + +class VPROPERTYEXPLORERSHARED_EXPORT VProperty : public QObject +{ + Q_OBJECT +public: + enum DPC_DisplayColumn { + DPC_Name = 0, + DPC_Data + }; + + //! Standard constructor, takes a name and a parent property as argument + explicit VProperty(const QString& name, QVariant::Type type = QVariant::String); + + //! Destructor + virtual ~VProperty(); + + //! Returns a string containing the type of the property + virtual QString type() const; + + //! Get the data how it should be displayed + virtual QVariant data (int column = DPC_Name, int role = Qt::DisplayRole) const; + + //! This is used by the model to set the data + //! \param data The data to set + //! \param role The role. Default is Qt::EditRole + //! \return Returns true, if the data was changed, false if not. + virtual bool setData (const QVariant& data, int role = Qt::EditRole); + + //! This is called by the delegate when the property value is being drawn. + //! The standard implementation doesn't do anything. + //! If you reimplement this in a sub property, make sure to return true or the delegate will draw the item. + virtual bool paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index, const QAbstractItemDelegate* delegate) const; + + //! Returns an editor widget, or NULL if it doesn't supply one + //! \param parent The widget to which the editor will be added as a child + //! \options Render options + //! \delegate A pointer to the QAbstractItemDelegate requesting the editor. This can be used to connect signals and slots. + virtual QWidget* createEditor(QWidget* parent, const QStyleOptionViewItem& options, const QAbstractItemDelegate* delegate); + + //! Sets the property's data to the editor (returns false, if the standard delegate should do that) + virtual bool setEditorData(QWidget* editor); + + //! Gets the data from the widget + virtual QVariant getEditorData(QWidget* editor) const; + + //! Returns item flags + virtual Qt::ItemFlags flags(int column = DPC_Name) const; + + //! Sets the value of the property + virtual void setValue(const QVariant& value); + + //! Returns the value of the property as a QVariant + virtual QVariant getValue() const; + + //! Serializes the value to a string + virtual QString serialize() const; + + //! Deserializes the value from a string + virtual void deserialize(const QString& value); + + // The following functions are experimental and not yet implemented. + /*//! Returns a pointer to the data stored and handled by this property. In most cases this function shouldn't be used. + //! \return Returns a void pointer to the data. Not all properties have to support this. By default, this implementation returns a NULL pointer. + virtual void* getDataPointer(); + + //! Sets the data. + //! \return Returns a void pointer to the data. Not all properties have to support this. By default, this implementation returns a NULL pointer. + virtual bool setDataPointer(void* pointer);*/ + + //! Sets the name of the property + virtual void setName(const QString& name); + + //! Gets the name of the property + virtual QString getName() const; + + //! Sets the name of the property + virtual void setDescription(const QString& desc); + + //! Gets the name of the property + virtual QString getDescription() const; + + //! Adds a child to this property + virtual int addChild(VProperty* child); + + //! Returns a reference to the list of children + virtual QList& getChildren(); + + //! Returns a reference to the list of children + virtual const QList& getChildren() const; + + //! Returns the child at a certain row + virtual VProperty* getChild(int row) const; + + //! Gets the number of children + virtual int getRowCount() const; + + //! Gets the parent of this property + virtual VProperty* getParent() const; + + //! Sets the parent of this property + virtual void setParent(VProperty* parent); + + //! Removes a child from the children list, doesn't delete the child! + virtual void removeChild(VProperty* child); + + //! Returns the row the child has + virtual int getChildRow(VProperty* child) const; + + //! Returns whether the views have to update the parent of this property if it changes + virtual bool getUpdateParent() const; + + //! Returns whether the views have to update the children of this property if it changes + virtual bool getUpdateChildren() const; + + //! Sets whether the views should update Parents or children after this property changes + virtual void setUpdateBehaviour(bool update_parent, bool update_children); + + //! Sets the settings by calling the overloaded setSetting(const QString& key, const QVariant& value) for each item in the map. + virtual void setSettings(const QMap& settings); + + //! Get the settings. + virtual QMap getSettings() const; + + //! Sets the settings. This function has to be implemented in a subclass in order to have an effect + virtual void setSetting(const QString& key, const QVariant& value); + + //! Get the settings. This function has to be implemented in a subclass in order to have an effect + virtual QVariant getSetting(const QString& key) const; + + //! Returns the list of keys of the property's settings + virtual QStringList getSettingKeys() const; + + //! Clones this property + //! \param include_children Indicates whether to also clone the children + //! \param container If a property is being passed here, no new VProperty is being created but instead it is tried to fill all the data into container. This can also be used when subclassing this function. + //! \return Returns the newly created property (or container, if it was not NULL) + virtual VProperty* clone(bool include_children = true, VProperty* container = nullptr) const; + + Property propertyType() const; + void setPropertyType(const Property &type); + + virtual void UpdateParent(const QVariant &value); +public slots: + virtual void ValueChildChanged(const QVariant &value, int typeForParent); +signals: + void childChanged(const QVariant &value, int typeForParent); + +protected: + //! Protected constructor + VProperty(VPropertyPrivate* d); + + //! The protected structure holding the member variables (to assure binary compatibility) + VPropertyPrivate* d_ptr; + +private: + // Provide access functions for the d_ptr + Q_DECLARE_PRIVATE(VProperty) +}; + +} + +#endif // VPROPERTY_H diff --git a/src/libs/vpropertyexplorer/vproperty_p.h b/src/libs/vpropertyexplorer/vproperty_p.h new file mode 100644 index 000000000..6937e32c7 --- /dev/null +++ b/src/libs/vpropertyexplorer/vproperty_p.h @@ -0,0 +1,63 @@ +#ifndef VPROPERTY_P_H +#define VPROPERTY_P_H + +// ONLY INCLUDE THIS IN .CPP FILES + +#include +#include +#include "vproperty.h" + +namespace VPE { + +class VPropertyPrivate { +public: + //! The property's value. + //! This does not have to be used by subclasses, but it makes sense in cases where QVariant supports + //! the data type. Also, this can be used as cache, so that when the data() function gets called by + //! the model, the data does not have to be converted in a QVariant every time. + QVariant VariantValue; + + //! Property name + QString Name; + + //! Description + QString Description; + + //! Specifies whether the property is empty or not + bool IsEmpty; + + //! Stores the property type + QVariant::Type PropertyVariantType; + + //! Stores whether the views have to update the parent of this property if it changes + bool UpdateParent; + + //! Stores whether the views have to update the children of this property if it changes + bool UpdateChildren; + + //! The parent property + VProperty* Parent; + + QWidget* editor; + + Property type; + + //! List of child properties + QList Children; + + //! Constructor passing name and type + VPropertyPrivate(const QString& name, QVariant::Type type) + : VariantValue(type), Name(name), PropertyVariantType(type), UpdateParent(false), UpdateChildren(false), + Parent(nullptr), editor(nullptr), type(Property::Simple) + {} + + //! Constructor + VPropertyPrivate() + : VariantValue(), Name(), PropertyVariantType(QVariant::Invalid), UpdateParent(false), UpdateChildren(false), + Parent(nullptr), editor(nullptr) + {} +}; + +} + +#endif // VPROPERTY_P_H diff --git a/src/libs/vpropertyexplorer/vpropertydelegate.cpp b/src/libs/vpropertyexplorer/vpropertydelegate.cpp new file mode 100644 index 000000000..091f61eb6 --- /dev/null +++ b/src/libs/vpropertyexplorer/vpropertydelegate.cpp @@ -0,0 +1,100 @@ +#include "vpropertydelegate.h" +#include "vproperty.h" + +#include +#include +#include +#include + +using namespace VPE; + +VPropertyDelegate::VPropertyDelegate(QObject *parent) : + QStyledItemDelegate(parent), RowHeight(0), AddRowHeight(false) +{ +} + +VPropertyDelegate::~VPropertyDelegate() +{ + // +} + +QWidget* VPropertyDelegate::createEditor (QWidget* parent, const QStyleOptionViewItem& option, const QModelIndex& index) const +{ + QWidget* tmpWidget = nullptr; + if(index.isValid()) + { + VProperty* tmpProperty = reinterpret_cast(index.internalPointer()); + tmpWidget = tmpProperty->createEditor(parent, option, this); + } + + return tmpWidget ? tmpWidget : QStyledItemDelegate::createEditor(parent, option, index); +} + + +//! Sets the index data to the editor +void VPropertyDelegate::setEditorData (QWidget * editor, const QModelIndex & index) const +{ + bool done = false; + if(index.isValid() && editor) + { + VProperty* tmpProperty = reinterpret_cast(index.internalPointer()); + done = tmpProperty->setEditorData(editor); + } + + if(!done) + QStyledItemDelegate::setEditorData(editor, index); +} + +//! Updates the index data +void VPropertyDelegate::setModelData (QWidget * editor, QAbstractItemModel * model, const QModelIndex & index) const +{ + QVariant tmpData; + if(index.isValid() && editor) + { + VProperty* tmpProperty = reinterpret_cast(index.internalPointer()); + tmpData = tmpProperty->getEditorData(editor); + } + + if(tmpData.isNull()) + QStyledItemDelegate::setModelData(editor, model, index); + else + model->setData(index, tmpData); +} + +QSize VPropertyDelegate::sizeHint (const QStyleOptionViewItem& option, const QModelIndex& index) const +{ + QSize tmpStandardSizeHint = QStyledItemDelegate::sizeHint(option, index); + tmpStandardSizeHint.setHeight(tmpStandardSizeHint.height() + 1); + + if(RowHeight > 0) + return QSize(tmpStandardSizeHint.width(), AddRowHeight ? tmpStandardSizeHint.height() + RowHeight : RowHeight); + else + return tmpStandardSizeHint; +} + +void VPropertyDelegate::setRowHeight(int height, bool add_to_standard) +{ + RowHeight = height; + AddRowHeight = add_to_standard; +} + +void VPropertyDelegate::paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const +{ + bool done = false; + if(index.isValid() && index.column() == 1) + done = reinterpret_cast(index.internalPointer())->paint(painter, option, index, this); + + if(!done) + QStyledItemDelegate::paint(painter, option, index); + + QColor tmpPenColor = static_cast(QApplication::style()->styleHint(QStyle::SH_Table_GridLineColor, &option)); + + QPen tmpOldPen = painter->pen(); + painter->setPen(QPen(tmpPenColor)); + painter->drawLine(option.rect.right(), option.rect.y(), option.rect.right(), option.rect.bottom()); + painter->drawLine(option.rect.x(), option.rect.bottom(), option.rect.right(), option.rect.bottom()); + painter->setPen(tmpOldPen); +} + + + diff --git a/src/libs/vpropertyexplorer/vpropertydelegate.h b/src/libs/vpropertyexplorer/vpropertydelegate.h new file mode 100644 index 000000000..ba6584db3 --- /dev/null +++ b/src/libs/vpropertyexplorer/vpropertydelegate.h @@ -0,0 +1,44 @@ +#ifndef VPROPERTYDELEGATE_H +#define VPROPERTYDELEGATE_H + +#include "vpropertyexplorer_global.h" + +#include + +namespace VPE { + +class VPROPERTYEXPLORERSHARED_EXPORT VPropertyDelegate : public QStyledItemDelegate +{ + Q_OBJECT +public: + explicit VPropertyDelegate(QObject *parent = 0); + virtual ~VPropertyDelegate(); + + //! Creates the editor widget + virtual QWidget* createEditor (QWidget* parent, const QStyleOptionViewItem& option, const QModelIndex& index) const; + + //! Sets the index data to the editor + virtual void setEditorData (QWidget * editor, const QModelIndex & index) const; + + //! Updates the index data + virtual void setModelData (QWidget * editor, QAbstractItemModel * model, const QModelIndex & index) const; + + //! Returns the size hint + virtual QSize sizeHint (const QStyleOptionViewItem& option, const QModelIndex& index) const; + + //! Sets the row height. Set this to 0 and the standard will be taken + void setRowHeight(int height = 0, bool add_to_standard = false); + + //! Renders the delegate using the given painter and style option for the item specified by index. + virtual void paint (QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index ) const; + +protected: + int RowHeight; + bool AddRowHeight; + + +}; + +} + +#endif // VPROPERTYDELEGATE_H diff --git a/src/libs/vpropertyexplorer/vpropertyexplorer.pro b/src/libs/vpropertyexplorer/vpropertyexplorer.pro new file mode 100644 index 000000000..1fc339927 --- /dev/null +++ b/src/libs/vpropertyexplorer/vpropertyexplorer.pro @@ -0,0 +1,98 @@ +#------------------------------------------------- +# +# Project created by QtCreator 2014-08-26T14:18:08 +# +#------------------------------------------------- + +QT += widgets + +QT -= gui + +TARGET = vpropertyexplorer +TEMPLATE = lib + +CONFIG += c++11 + +DEFINES += VPROPERTYEXPLORER_LIBRARY + +# directory for executable file +DESTDIR = bin + +# files created moc +MOC_DIR = moc + +# objecs files +OBJECTS_DIR = obj + +SOURCES += \ + vproperty.cpp \ + vpropertydelegate.cpp \ + vpropertyfactorymanager.cpp \ + vpropertyformview.cpp \ + vpropertyformwidget.cpp \ + vpropertymodel.cpp \ + vpropertyset.cpp \ + vpropertytreeview.cpp \ + vserializedproperty.cpp \ + plugins/vwidgetproperty.cpp \ + plugins/vemptyproperty.cpp \ + plugins/vboolproperty.cpp \ + plugins/vshortcutproperty.cpp \ + plugins/vcolorproperty.cpp \ + plugins/vshortcutpropertyeditor.cpp \ + plugins/venumproperty.cpp \ + plugins/vfileproperty.cpp \ + plugins/vcolorpropertyeditor.cpp \ + plugins/vfilepropertyeditor.cpp \ + plugins/vnumberproperty.cpp \ + plugins/Vector3d/vvector3dproperty.cpp \ + vstandardpropertyfactory.cpp \ + plugins/vstringproperty.cpp \ + plugins/vpointfproperty.cpp \ + plugins/vobjectproperty.cpp + +HEADERS +=\ + vpropertyexplorer_global.h \ + vpropertyfactorymanager_p.h \ + vpropertytreeview_p.h \ + vpropertyset_p.h \ + vabstractpropertyfactory.h \ + vfileproperty_p.h \ + vwidgetproperty_p.h \ + vpropertymodel_p.h \ + vstandardpropertyfactory.h \ + vpropertyformview_p.h \ + vpropertytreeview.h \ + vpropertyformwidget_p.h \ + vpropertydelegate.h \ + vproperty_p.h \ + vpropertyformwidget.h \ + vpropertyformview.h \ + vpropertyset.h \ + vpropertymodel.h \ + vproperty.h \ + plugins/vwidgetproperty.h \ + plugins/vcolorproperty.h \ + plugins/vboolproperty.h \ + plugins/vcolorpropertyeditor.h \ + plugins/vshortcutpropertyeditor.h \ + plugins/vemptyproperty.h \ + plugins/vshortcutproperty.h \ + plugins/venumproperty.h \ + plugins/vfilepropertyeditor.h \ + plugins/vfileproperty.h \ + plugins/vnumberproperty.h \ + plugins/Vector3d/vvector3dproperty.h \ + vpropertyfactorymanager.h \ + vserializedproperty.h \ + plugins/vstringproperty.h \ + plugins/vpointfproperty.h \ + plugins/vobjectproperty.h \ + vproperties.h + +unix { + target.path = /usr/lib + INSTALLS += target +} + +QMAKE_CXXFLAGS += -gdwarf-3 diff --git a/src/libs/vpropertyexplorer/vpropertyexplorer_global.h b/src/libs/vpropertyexplorer/vpropertyexplorer_global.h new file mode 100644 index 000000000..68c08bffb --- /dev/null +++ b/src/libs/vpropertyexplorer/vpropertyexplorer_global.h @@ -0,0 +1,40 @@ +/************************************************************************ + ** + ** @file vpropertyexplorer_global.h + ** @author Roman Telezhynskyi + ** @date 26 8, 2014 + ** + ** @brief + ** @copyright + ** This source code is part of the Valentine project, a pattern making + ** program, whose allow create and modeling patterns of clothing. + ** Copyright (C) 2014 Valentina project + ** All Rights Reserved. + ** + ** Valentina 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. + ** + ** Valentina 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 for more details. + ** + ** You should have received a copy of the GNU General Public License + ** along with Valentina. If not, see . + ** + *************************************************************************/ + +#ifndef VPROPERTYEXPLORER_GLOBAL_H +#define VPROPERTYEXPLORER_GLOBAL_H + +#include + +#if defined(VPROPERTYEXPLORER_LIBRARY) +# define VPROPERTYEXPLORERSHARED_EXPORT Q_DECL_EXPORT +#else +# define VPROPERTYEXPLORERSHARED_EXPORT Q_DECL_IMPORT +#endif + +#endif // VPROPERTYEXPLORER_GLOBAL_H diff --git a/src/libs/vpropertyexplorer/vpropertyfactorymanager.cpp b/src/libs/vpropertyexplorer/vpropertyfactorymanager.cpp new file mode 100644 index 000000000..51bcc73d8 --- /dev/null +++ b/src/libs/vpropertyexplorer/vpropertyfactorymanager.cpp @@ -0,0 +1,109 @@ +#include "vpropertyfactorymanager.h" +#include "vpropertyfactorymanager_p.h" + +#include "vstandardpropertyfactory.h" +#include "vproperty.h" + +using namespace VPE; + + +VPropertyFactoryManager* VPropertyFactoryManager::DefaultManager = NULL; + +VPropertyFactoryManager::VPropertyFactoryManager(QObject *parent) + : QObject(parent), d_ptr(new VPropertyFactoryManagerPrivate()) +{ + +} + +VPropertyFactoryManager::~VPropertyFactoryManager() +{ + // Delete all factories + QList tmpFactories = d_ptr->Factories.values(); + while(!tmpFactories.isEmpty()) { + VAbstractPropertyFactory* tmpFactory = tmpFactories.takeLast(); + tmpFactories.removeAll(tmpFactory); + delete tmpFactory; + } + + + delete d_ptr; + if(this == DefaultManager) + DefaultManager = NULL; +} + +void VPropertyFactoryManager::registerFactory(const QString& type, VAbstractPropertyFactory* factory) +{ + if(type.isEmpty()) + return; + + // Remove old factory + unregisterFactory(getFactory(type), type, true); + // Register new one + d_ptr->Factories[type] = factory; +} + +void VPropertyFactoryManager::unregisterFactory(VAbstractPropertyFactory* factory, const QString& type, bool delete_if_unused) +{ + if(!factory) + return; + + if(!type.isEmpty()) { + // Remove all occurances + QString tmpKey; + do { + tmpKey = d_ptr->Factories.key(factory, QString()); + if(!tmpKey.isEmpty()) d_ptr->Factories.remove(tmpKey); + } while(!tmpKey.isEmpty()); + } else { + // Only remove one type + if(d_ptr->Factories.value(type, NULL) == factory) + d_ptr->Factories.remove(type); + } + + if(delete_if_unused && !isRegistered(factory)) + delete factory; +} + +bool VPropertyFactoryManager::isRegistered(VAbstractPropertyFactory* factory) +{ + return (!d_ptr->Factories.key(factory, QString()).isEmpty()); +} + +VAbstractPropertyFactory* VPropertyFactoryManager::getFactory(const QString& type) +{ + return d_ptr->Factories.value(type, NULL); +} + + +VProperty* VPropertyFactoryManager::createProperty(const QString& type, const QString& name, const QString& description, const QString &default_value) +{ + VAbstractPropertyFactory* tmpFactory = getFactory(type); + VProperty* tmpResult = NULL; + if(tmpFactory) { + tmpResult = tmpFactory->createProperty(type, name); + + if(tmpResult) { + tmpResult->setDescription(description); + + if(!default_value.isEmpty()) + tmpResult->deserialize(default_value); + } + } + + return tmpResult; +} + +VPropertyFactoryManager *VPropertyFactoryManager::getDefaultManager() +{ + if(!DefaultManager) { + DefaultManager = new VPropertyFactoryManager(); + /*VStandardPropertyFactory* tmpStandardProp = */new VStandardPropertyFactory(DefaultManager); + } + + return DefaultManager; +} + +QStringList VPropertyFactoryManager::getSupportedTypes() +{ + return d_ptr->Factories.keys(); +} diff --git a/src/libs/vpropertyexplorer/vpropertyfactorymanager.h b/src/libs/vpropertyexplorer/vpropertyfactorymanager.h new file mode 100644 index 000000000..31450eb33 --- /dev/null +++ b/src/libs/vpropertyexplorer/vpropertyfactorymanager.h @@ -0,0 +1,67 @@ +#ifndef VPROPERTYFACTORYMANAGER_H +#define VPROPERTYFACTORYMANAGER_H + +#include "vpropertyexplorer_global.h" +#include + +namespace VPE { + +class VAbstractPropertyFactory; +class VPropertyFactoryManagerPrivate; +class VProperty; + +class VPROPERTYEXPLORERSHARED_EXPORT VPropertyFactoryManager : public QObject +{ + Q_OBJECT +public: + //! Constructor + VPropertyFactoryManager(QObject* parent = nullptr); + + //! Destructor + virtual ~VPropertyFactoryManager(); + + //! Register a factory to the factory manager + //! Note that the manager takes ownership of the factory, so don't delete it. + //! You can unregister a factory using unregisterFactory() + void registerFactory(const QString& type, VAbstractPropertyFactory* factory); + + //! Removes a factory from the manager. + //! \param factory The factory to unregister + //! \param type The type from which to remove the factory. If this is empty, all the types the factory is registered for are being removed + //! \param delete_if_unused Determines whether the factory should be deleted, if it not used anymore by this manager. Default: true. Otherwise, if the factory is unused by this manager, ownership is being passed on. + void unregisterFactory(VAbstractPropertyFactory* factory, const QString& type = QString(), + bool delete_if_unused = true); + + //! Returns whether a factory is registered (and thus owned) by this factory manager + bool isRegistered(VAbstractPropertyFactory* factory); + + //! Returns a pointer to a factory registered for a certain type + //! \param type The type to return the factory for + //! \return Returns NULL, if there is none registered for this type + VAbstractPropertyFactory* getFactory(const QString& type); + + //! Creates a new property of a certain type and assigns a name and description (otionally) + //! \param type The type of the property as string + //! \param name The name of the property + //! \param description The property's description. Optional. + //! \param default_value The properties initial value as string. Optional. + //! \return Returns the created property or NULL if it couldn't be be created + VProperty* createProperty(const QString& type, const QString& name, const QString& description = QString(), + const QString& default_value = QString()); + + //! Returns the default manager. + static VPropertyFactoryManager* getDefaultManager(); + + //! Returns a list of all supported property types + QStringList getSupportedTypes(); + +protected: + VPropertyFactoryManagerPrivate* d_ptr; + + //! The default manager + static VPropertyFactoryManager* DefaultManager; +}; + +} + +#endif // VPROPERTYFACTORYMANAGER_H diff --git a/src/libs/vpropertyexplorer/vpropertyfactorymanager_p.h b/src/libs/vpropertyexplorer/vpropertyfactorymanager_p.h new file mode 100644 index 000000000..ff47fa40d --- /dev/null +++ b/src/libs/vpropertyexplorer/vpropertyfactorymanager_p.h @@ -0,0 +1,21 @@ +#ifndef VPROPERTYFACTORYMANAGER_P_H +#define VPROPERTYFACTORYMANAGER_P_H + +// ONLY INCLUDE THIS IN .CPP FILES + +#include +#include + +namespace VPE { + +class VAbstractPropertyFactory; + +class VPropertyFactoryManagerPrivate { +public: + QMap Factories; + +}; + +} + +#endif // VPROPERTYFACTORYMANAGER_P_H diff --git a/src/libs/vpropertyexplorer/vpropertyformview.cpp b/src/libs/vpropertyexplorer/vpropertyformview.cpp new file mode 100644 index 000000000..2661aec7c --- /dev/null +++ b/src/libs/vpropertyexplorer/vpropertyformview.cpp @@ -0,0 +1,179 @@ +#include "vpropertyformview.h" +#include "vpropertymodel.h" +#include "vpropertyset.h" +#include +#include +#include + +#include "vpropertyformview_p.h" + +using namespace VPE; + +VPropertyFormView::VPropertyFormView(QWidget* parent) + : VPropertyFormWidget(new VPropertyFormViewPrivate(), parent) +{ + // +} + +VPropertyFormView::VPropertyFormView(VPropertyModel* model, QWidget *parent) + : VPropertyFormWidget(new VPropertyFormViewPrivate(), parent) +{ + setModel(model); +} + +VPropertyFormView::VPropertyFormView(VPropertySet* property_set, QWidget *parent) + : VPropertyFormWidget(new VPropertyFormViewPrivate(), parent) +{ + setPropertySet(property_set); +} + +VPropertyFormView::~VPropertyFormView() +{ + // Nothing to do +} + +void VPropertyFormView::build() +{ + VPropertyFormWidget::build(); + + // Go through all sub widgets and connect + connectPropertyFormWidget(this); +} + +void VPropertyFormView::setModel(VPropertyModel *model) +{ + // Remove old model or set + removeModelAndSet(); + + // Set model + static_cast(d_ptr)->Model = model; + if(model) { + // Set the property list + if(model->getPropertySet()) + d_ptr->Properties = model->getPropertySet()->getRootProperties(); + + // Connect signals // todo: more signals neccesary!!! + connect(model, SIGNAL(destroyed()), this, SLOT(modelDestroyed())); + connect(model, SIGNAL(rowsInserted(const QModelIndex&, int, int)), this, SLOT(rowsInserted(QModelIndex,int,int))); + connect(model, SIGNAL(modelReset()), this, SLOT(modelReset())); + connect(model, SIGNAL(rowsRemoved(const QModelIndex&, int, int)), this, SLOT(rowsRemoved(QModelIndex,int,int))); + } + + // Build the widget + updatePropertyList(); +} + +void VPropertyFormView::setPropertySet(VPropertySet* property_set) +{ + // Remove old model or set + removeModelAndSet(); + + // Set property set + static_cast(d_ptr)->PropertySet = property_set; + if(property_set) { + // Set the property list + d_ptr->Properties = property_set->getRootProperties(); + } + + // Build the widget + updatePropertyList(); +} + +void VPropertyFormView::rowsRemoved(const QModelIndex &parent, int start, int end) +{ + // todo: Only rebuild the neccessary parts + Q_UNUSED(parent) + Q_UNUSED(start) + Q_UNUSED(end) + updatePropertyList(); +} + +void VPropertyFormView::rowsInserted(const QModelIndex &parent, int start, int end) +{ + // todo: Only rebuild the neccessary parts + Q_UNUSED(parent) + Q_UNUSED(start) + Q_UNUSED(end) + updatePropertyList(); +} + +void VPropertyFormView::modelReset() +{ + updatePropertyList(); +} + +void VPropertyFormView::modelDestroyed() +{ + removeModelAndSet(); + updatePropertyList(); +} + +void VPropertyFormView::dataChanged(const QModelIndex &top_left, const QModelIndex &bottom_right) +{ + if(static_cast(d_ptr)->IgnoreDataChangedSignal) + return; + // todo: handle data changes +} + +void VPropertyFormView::dataSubmitted(VProperty *property) +{ + VPropertyModel* tmpModel = static_cast(d_ptr)->Model; + + if(tmpModel && d_ptr->UpdateEditors) { + static_cast(d_ptr)->IgnoreDataChangedSignal = true; + tmpModel->onDataChangedByModel(property); + static_cast(d_ptr)->IgnoreDataChangedSignal = false; + } +} + +void VPropertyFormView::showEvent(QShowEvent *event) +{ + Q_UNUSED(event) + if(static_cast(d_ptr)->NeedsRebuild) + build(); + static_cast(d_ptr)->NeedsRebuild = false; +} + +void VPropertyFormView::updatePropertyList() +{ + VPropertyModel* tmpModel = static_cast(d_ptr)->Model; + VPropertySet* tmpSet = static_cast(d_ptr)->PropertySet; + + if(tmpModel && tmpModel->getPropertySet()) + d_ptr->Properties = tmpModel->getPropertySet()->getRootProperties(); + else if(tmpSet) + d_ptr->Properties = tmpSet->getRootProperties(); + else + d_ptr->Properties.clear(); + + if(isVisible()) + build(); + else + static_cast(d_ptr)->NeedsRebuild = true; +} + +void VPropertyFormView::removeModelAndSet() +{ + if(static_cast(d_ptr)->Model) { + disconnect(static_cast(d_ptr)->Model, 0, this, 0); + static_cast(d_ptr)->Model = nullptr; + } + + static_cast(d_ptr)->NeedsRebuild = true; + d_ptr->Properties.clear(); + static_cast(d_ptr)->PropertySet = nullptr; +} + +void VPropertyFormView::connectPropertyFormWidget(VPropertyFormWidget *widget) +{ + if(!widget) + return; + + connect(widget, &VPropertyFormWidget::propertyDataSubmitted, this, &VPropertyFormView::dataSubmitted, + Qt::UniqueConnection); + QList tmpList = widget->getChildPropertyFormWidgets(); + + foreach(VPropertyFormWidget* tmpEditorWidget, tmpList) { + connectPropertyFormWidget(tmpEditorWidget); + } +} diff --git a/src/libs/vpropertyexplorer/vpropertyformview.h b/src/libs/vpropertyexplorer/vpropertyformview.h new file mode 100644 index 000000000..5e679fd39 --- /dev/null +++ b/src/libs/vpropertyexplorer/vpropertyformview.h @@ -0,0 +1,81 @@ +#ifndef VPROPERTYFORMVIEW_H +#define VPROPERTYFORMVIEW_H + +#include "vpropertyexplorer_global.h" +#include +#include "vpropertyformwidget.h" + +namespace VPE { + +class VProperty; +class VPropertyModel; +class VPropertySet; + +//! This class populates a form layout with the properties in a model +class VPROPERTYEXPLORERSHARED_EXPORT VPropertyFormView : public VPropertyFormWidget +{ + Q_OBJECT +public: + //! Constructor + explicit VPropertyFormView(QWidget *parent = 0); + + //! Constructor + explicit VPropertyFormView(VPropertyModel* model, QWidget *parent = 0); + + //! Constructor + explicit VPropertyFormView(VPropertySet* property_set, QWidget *parent = 0); + + //! Destructor + virtual ~VPropertyFormView(); + + +public slots: + //! Rebuilds the whole form + virtual void build(); + + //! Set the source model. Leads to the rebuild of the form + //! \param model The model to use + void setModel(VPropertyModel* model); + + //! Set the property set to use. Note that if using a property set directly, adding and removing properties to the property set leads to undifined behaviour for the property set misses notification signals. + //! \param model The property set to use + void setPropertySet(VPropertySet* property_set); + + //! Called when a row gets removed in the model + void rowsRemoved(const QModelIndex& parent, int start, int end); + + //! Called when a new row is being inserted into the model + void rowsInserted(const QModelIndex& parent, int start, int end); + + //! Called when the model is being reset + void modelReset(); + + +private slots: + //! Called, when the model gets destroyed + void modelDestroyed(); + + //! Called when data in the model gets changed + void dataChanged(const QModelIndex& top_left, const QModelIndex& bottom_right); + + //! Updates the model when data was submitted by the view + void dataSubmitted(VProperty* property); + +protected: + void showEvent(QShowEvent* event); + + //! Rebuilds the widegt only if it is visible + void updatePropertyList(); + + //! Removes the model and property set if they were set + void removeModelAndSet(); + + //! Function to handle newly created VPropertyWidgets + virtual void connectPropertyFormWidget(VPropertyFormWidget* widget); + + +}; + +} // Namespace VPE + +#endif // VPROPERTYFORMVIEW_H diff --git a/src/libs/vpropertyexplorer/vpropertyformview_p.h b/src/libs/vpropertyexplorer/vpropertyformview_p.h new file mode 100644 index 000000000..c34ddcba5 --- /dev/null +++ b/src/libs/vpropertyexplorer/vpropertyformview_p.h @@ -0,0 +1,40 @@ +#ifndef VPROPERTYFORMVIEW_P_H +#define VPROPERTYFORMVIEW_P_H + +// ONLY INCLUDE THIS IN .CPP FILES + +#include "vpropertyformwidget_p.h" + +namespace VPE { + +class VPropertyModel; +class VPropertySet; + +class VPropertyFormViewPrivate : public VPropertyFormWidgetPrivate +{ +public: + //! The current property model + VPropertyModel* Model; + + //! The currently used property set + VPropertySet* PropertySet; + + //! Determines whether the widget needs to be rebuild + bool NeedsRebuild; + + //! Helper variable + bool IgnoreDataChangedSignal; + + VPropertyFormViewPrivate() + : VPropertyFormWidgetPrivate(), Model(NULL), PropertySet(NULL), NeedsRebuild(false) {} + + VPropertyFormViewPrivate(VPropertyModel* prop_model) + : VPropertyFormWidgetPrivate(), Model(prop_model), PropertySet(NULL), NeedsRebuild(false) {} + + VPropertyFormViewPrivate(VPropertySet* prop_set) + : VPropertyFormWidgetPrivate(), Model(NULL), PropertySet(prop_set), NeedsRebuild(false) {} +}; + +} + +#endif // VPROPERTYFORMVIEW_P_H diff --git a/src/libs/vpropertyexplorer/vpropertyformwidget.cpp b/src/libs/vpropertyexplorer/vpropertyformwidget.cpp new file mode 100644 index 000000000..598fecdd8 --- /dev/null +++ b/src/libs/vpropertyexplorer/vpropertyformwidget.cpp @@ -0,0 +1,283 @@ +#include "vpropertyformwidget.h" + +#include +#include "vpropertyformwidget_p.h" + +#include "plugins/vwidgetproperty.h" +#include +#include +#include "vproperty.h" +#include + +using namespace VPE; + +VPropertyFormWidget::VPropertyFormWidget(const QString &title, const QString &description, const QList& properties, QWidget *parent) + : QGroupBox(title, parent), d_ptr(new VPropertyFormWidgetPrivate(properties)) +{ + build(); + setToolTip(description); + setWhatsThis(description); +} + +VPropertyFormWidget::VPropertyFormWidget(VProperty *parent_property, QWidget *parent) + : QGroupBox(parent), d_ptr(new VPropertyFormWidgetPrivate()) +{ + if(parent_property) { + d_ptr->Properties = parent_property->getChildren(); + build(); + setTitle(parent_property->getName()); + setToolTip(parent_property->getDescription()); + setWhatsThis(parent_property->getDescription()); + } +} + +VPropertyFormWidget::VPropertyFormWidget(VPropertyFormWidgetPrivate *d_pointer, QWidget *parent, const QString &title, const QString &description) + : QGroupBox(title, parent), d_ptr(d_pointer) +{ + build(); + setToolTip(description); + setWhatsThis(description); +} + +VPropertyFormWidget::~VPropertyFormWidget() +{ + delete d_ptr; +} + + +void VPropertyFormWidget::build() +{ + // Clear the old content, delete old widgets + d_ptr->EditorWidgets.clear(); + if(layout()) { + QLayoutItem *child; + while (layout()->count() > 0 && (child = layout()->takeAt(0)) != 0) { + if(child->widget()) + delete child->widget(); + delete child; + } + delete layout(); + } + + // Create new content + if(d_ptr->Properties.isEmpty()) return; //... only if there are properties + + QFormLayout* tmpFormLayout = new QFormLayout(this); + setLayout(tmpFormLayout); + + for(int i = 0; i < d_ptr->Properties.count(); ++i) { + // Get the current property + VProperty* tmpProperty = d_ptr->Properties.value(i, nullptr); + if(!tmpProperty) continue; + + if(tmpProperty->getRowCount() > 0) { + if (tmpProperty->propertyType() == Property::Complex) + { + buildEditor(tmpProperty, tmpFormLayout, Property::Complex); + QWidget *group = new QWidget(this); + tmpFormLayout->addRow(group); + + QFormLayout* subFormLayout = new QFormLayout(group); + QMargins margins = subFormLayout->contentsMargins(); + margins.setTop(0); + margins.setLeft(14); + subFormLayout->setContentsMargins(margins); + + group->setLayout(subFormLayout); + QList children = tmpProperty->getChildren(); + for (int j = 0; j < children.size(); ++j) + { + buildEditor(children[j], subFormLayout); + connect(children[j], &VProperty::childChanged, tmpProperty, &VProperty::ValueChildChanged, + Qt::UniqueConnection); + ++i; + d_ptr->Properties.insert(i, children[j]); + } + } + else + { + // Child properties, the property itself is not being added + VPropertyFormWidget* tmpNewFormWidget = new VPropertyFormWidget(tmpProperty, this); + tmpFormLayout->addRow(tmpNewFormWidget); + d_ptr->EditorWidgets.append(VPropertyFormWidgetPrivate::SEditorWidget(tmpNewFormWidget)); + tmpNewFormWidget->setCommitBehaviour(d_ptr->UpdateEditors); + } + } else if(tmpProperty->type() == "widget") { + VWidgetProperty* tmpWidgetProperty = static_cast(tmpProperty); + tmpFormLayout->addRow(tmpWidgetProperty->getWidget()); + d_ptr->EditorWidgets.append(VPropertyFormWidgetPrivate::SEditorWidget(tmpWidgetProperty->getWidget())); + } else { + buildEditor(tmpProperty, tmpFormLayout); + } + } +} + +void VPropertyFormWidget::buildEditor(VProperty* property, QFormLayout* formLayout, Property type) +{ + // Add property (no child properties) + // Create the editor (if it doesn't work, create empty widget) + QWidget* tmpEditor = property->createEditor(this, QStyleOptionViewItem(), nullptr); + if(!tmpEditor) + tmpEditor = new QWidget(this); + + // set tooltip and whats this + tmpEditor->setToolTip(property->getDescription()); + tmpEditor->setWhatsThis(property->getDescription()); + + // Install event filter + tmpEditor->installEventFilter(this); + + // Set the editor data + property->setEditorData(tmpEditor); + + // add new row + if (type == Property::Complex) + { + QString name = ""+property->getName()+""; + formLayout->addRow(name, tmpEditor); + } + else + { + formLayout->addRow(property->getName(), tmpEditor); + } + + d_ptr->EditorWidgets.append(VPropertyFormWidgetPrivate::SEditorWidget(tmpEditor)); +} + +void VPropertyFormWidget::commitData() +{ + for(int i = 0; i < d_ptr->Properties.count(); ++i) + commitData(i); +} + +void VPropertyFormWidget::loadData() +{ + for(int i = 0; i < d_ptr->Properties.count(); ++i) + loadData(i); +} + +void VPropertyFormWidget::commitData(int row) +{ + if(row < 0 || row >= d_ptr->EditorWidgets.count() || row >= d_ptr->Properties.count()) return; + + VPropertyFormWidgetPrivate::SEditorWidget& tmpEditorWidget = d_ptr->EditorWidgets[row]; + VProperty* tmpProperty = d_ptr->Properties[row]; + if(tmpEditorWidget.FormWidget) + tmpEditorWidget.FormWidget->commitData(); + else if(tmpEditorWidget.Editor && tmpProperty) + { + QVariant newValue = tmpProperty->getEditorData(tmpEditorWidget.Editor); + QVariant oldValue = tmpProperty->data(VProperty::DPC_Data, Qt::EditRole); + if (oldValue != newValue) + { + VProperty *parent = tmpProperty->getParent(); + if (parent == nullptr) + { + tmpProperty->setValue(newValue); + emit propertyDataSubmitted(tmpProperty); + } + else if (parent->propertyType() == Property::Complex) + { + tmpProperty->UpdateParent(newValue); + emit propertyDataSubmitted(parent); + } + else + { + tmpProperty->setValue(newValue); + emit propertyDataSubmitted(tmpProperty); + } + } + } +} + +void VPropertyFormWidget::loadData(int row) +{ + if(row < 0 || row >= d_ptr->EditorWidgets.count() || row >= d_ptr->Properties.count()) return; + + VPropertyFormWidgetPrivate::SEditorWidget& tmpEditorWidget = d_ptr->EditorWidgets[row]; + VProperty* tmpProperty = d_ptr->Properties[row]; + if(tmpEditorWidget.FormWidget) + tmpEditorWidget.FormWidget->loadData(); + else if(tmpEditorWidget.Editor && tmpProperty) { + tmpProperty->setEditorData(tmpEditorWidget.Editor); + } +} + +void VPropertyFormWidget::setCommitBehaviour(bool auto_commit) +{ + d_ptr->UpdateEditors = auto_commit; + + QList tmpChildFormWidgets = getChildPropertyFormWidgets(); + foreach(VPropertyFormWidget* tmpChild, tmpChildFormWidgets) { + if(tmpChild) + tmpChild->setCommitBehaviour(auto_commit); + } +} + +QList VPropertyFormWidget::getChildPropertyFormWidgets() const +{ + QList tmpResult; + foreach(const VPropertyFormWidgetPrivate::SEditorWidget& tmpEditorWidget, d_ptr->EditorWidgets) { + if(tmpEditorWidget.FormWidget) + tmpResult.append(tmpEditorWidget.FormWidget); + } + + return tmpResult; +} + +bool VPropertyFormWidget::eventFilter(QObject *object, QEvent *event) +{ + if(!d_ptr->UpdateEditors) + return false; + + QWidget* editor = qobject_cast(object); + if (!editor) + return false; + + if (event->type() == QEvent::KeyPress) { + switch (static_cast(event)->key()) { + case Qt::Key_Tab: + case Qt::Key_Backtab: + case Qt::Key_Enter: + case Qt::Key_Return: + case Qt::Key_Escape: + commitData(editor); + event->accept(); + return true; + default: + return false; + } + } else if (event->type() == QEvent::FocusOut || (event->type() == QEvent::Hide && editor->isWindow())) { + commitData(editor); + return false; + } else if (event->type() == QEvent::ShortcutOverride) { + if (static_cast(event)->key() == Qt::Key_Escape) { + commitData(editor); + event->accept(); + return true; + } + } else if (event->type() == MyCustomEventType) { + commitData(editor); + event->accept(); + return true; + } + else + { + return QGroupBox::eventFilter(object, event); + } + + // Default: + return false; +} + +void VPropertyFormWidget::commitData(QWidget *editor) +{ + if(!editor) + return; + + for(int i = 0; i < d_ptr->EditorWidgets.count(); ++i) { + VPropertyFormWidgetPrivate::SEditorWidget& tmpEditorWidget = d_ptr->EditorWidgets[i]; + if(tmpEditorWidget.Editor == editor) + commitData(i); + } +} diff --git a/src/libs/vpropertyexplorer/vpropertyformwidget.h b/src/libs/vpropertyexplorer/vpropertyformwidget.h new file mode 100644 index 000000000..c407bc603 --- /dev/null +++ b/src/libs/vpropertyexplorer/vpropertyformwidget.h @@ -0,0 +1,77 @@ +#ifndef VPROPERTYFORMWIDGET_H +#define VPROPERTYFORMWIDGET_H + +#include +#include +#include "vproperty.h" + +class QFormLayout; + +namespace VPE { + +class VPropertyFormWidgetPrivate; +class VPropertySet; + +//! Class that displays the sub properties of a property using a form layout +class VPROPERTYEXPLORERSHARED_EXPORT VPropertyFormWidget : public QGroupBox +{ + Q_OBJECT +public: + //! Constructor + VPropertyFormWidget(const QString& title, const QString& description, const QList& properties, QWidget* parent); + + //! Constructor + VPropertyFormWidget(VProperty* parent_property, QWidget* parent); + + //! Destructor + ~VPropertyFormWidget(); + + + //! Returns a list of all child property form widgets (note that indirect children will not be in the list) + QList getChildPropertyFormWidgets() const; + +public slots: + //! Rebuilds the whole form + virtual void build(); + + void buildEditor(VProperty *property, QFormLayout *formLayout, Property type = Property::Simple); + + //! Reads the data from the editors and commits it to the properties + void commitData(); + + //! Refills the editors with the propertie's data + void loadData(); + + //! Reads the data from row'th editor and commits it to the property + void commitData(int row); + + //! Reads the data from row'th property + void loadData(int row); + + //! Sets the update behaviour + //! \param auto_commit If set to true, whenever an event like focusOut is triggered on an editor, the data will be submitted to the property. + void setCommitBehaviour(bool auto_commit = true); + +signals: + //! Emitted whenever a property data changes + void propertyDataSubmitted(VProperty* property); + +protected: + //! Protected Constructor + VPropertyFormWidget(VPropertyFormWidgetPrivate* d_pointer, QWidget* parent, const QString &title = QString(), + const QString &description = QString()); + + //! The protected data + VPropertyFormWidgetPrivate* d_ptr; + + //! Event filter for the editor widgets + bool eventFilter(QObject *object, QEvent *event); + + //! Commits data of an editor + void commitData(QWidget* editor); + +}; + +} // Namespace VPE + +#endif // VPROPERTYFORMWIDGET_H diff --git a/src/libs/vpropertyexplorer/vpropertyformwidget_p.h b/src/libs/vpropertyexplorer/vpropertyformwidget_p.h new file mode 100644 index 000000000..e1cdc6589 --- /dev/null +++ b/src/libs/vpropertyexplorer/vpropertyformwidget_p.h @@ -0,0 +1,44 @@ +#ifndef VPROPERTYFORMWIDGET_P_H +#define VPROPERTYFORMWIDGET_P_H + +// ONLY INCLUDE THIS IN .CPP FILES + +#include +#include "vproperty.h" + +namespace VPE { + +class VPropertyFormWidgetPrivate { +public: + //! Stores either another VPropertyFormWidget (then Editor is null) or an editor widget (then FormWidget is null) + struct SEditorWidget { + SEditorWidget() : FormWidget(nullptr), Editor(nullptr) {} + SEditorWidget(VPropertyFormWidget* form_widget) : FormWidget(form_widget), Editor(nullptr) {} + SEditorWidget(QWidget* editor_widget) : FormWidget(nullptr), Editor(editor_widget) {} + + VPropertyFormWidget* FormWidget; + QWidget* Editor; + }; + + //! The root property to use + QList Properties; + + //! Binds the properties to their editors + QList EditorWidgets; + + //! Determines the behaviour of the editors. If this is true, when a focus out event etc. happens, the data will be submitted to the VProperty. If false, you will have to call commitData() yourself. + bool UpdateEditors; + + //! Default constructor + VPropertyFormWidgetPrivate() + : UpdateEditors(true) + {} + + //! Constructor + VPropertyFormWidgetPrivate(const QList& properties) + : Properties(properties), UpdateEditors(true) {} +}; + +} + +#endif // VPROPERTYFORMWIDGET_P_H diff --git a/src/libs/vpropertyexplorer/vpropertymodel.cpp b/src/libs/vpropertyexplorer/vpropertymodel.cpp new file mode 100644 index 000000000..1cb82a24f --- /dev/null +++ b/src/libs/vpropertyexplorer/vpropertymodel.cpp @@ -0,0 +1,286 @@ +#include "vpropertymodel.h" + +#include +#include "vpropertyset.h" + +using namespace VPE; + +#include "vpropertymodel_p.h" + +VPropertyModel::VPropertyModel(VPropertyModelPrivate *d, QObject *parent) + : QAbstractItemModel(parent), d_ptr(d) +{ +} + + +VPropertyModel::VPropertyModel(QObject * parent) : + QAbstractItemModel(parent), d_ptr(new VPropertyModelPrivate()) +{ +} + +VPropertyModel::~VPropertyModel() +{ + if(d_ptr->Properties) + delete d_ptr->Properties; + + delete d_ptr; +} + +//! Adds the property to the model and attaches it to the parentid +bool VPropertyModel::addProperty(VProperty* property, const QString& id, const QString &parentid, bool emitsignals) +{ + if(!property) + return false; + + if(!d_ptr->Properties) // If not existant, create property set + d_ptr->Properties = new VPropertySet(); + + if(emitsignals) { + VProperty* tmpParent = getProperty(parentid); + int tmpRow = tmpParent != nullptr ? tmpParent->getRowCount() : d_ptr->Properties->getRootPropertyCount(); + beginInsertRows((tmpParent != nullptr ? getIndexFromProperty(tmpParent) : QModelIndex()), tmpRow, tmpRow); + } + + d_ptr->Properties->addProperty(property, id, parentid); + + if(emitsignals) + endInsertRows(); + + return true; + +} + +//! Creates a property and adds it to the model +VProperty* VPropertyModel::createProperty(const QString& id, const QString& name, const QString& parentid, const QVariant& data) +{ + VProperty* tmpProp = new VProperty(name); + tmpProp->setValue(data); + if(tmpProp && addProperty(tmpProp, id, parentid)) + return tmpProp; + else + return nullptr; +} + +//! Gets a property by it's ID +VProperty* VPropertyModel::getProperty(const QString& id) +{ + return d_ptr->Properties != nullptr ? d_ptr->Properties->getProperty(id) : nullptr; +} + + + +//! Returns the model index at row/column +QModelIndex VPropertyModel::index(int row, int column, const QModelIndex& parent) const +{ + if (d_ptr->Properties == nullptr || (parent.isValid() && parent.column() > 1)) + return QModelIndex(); + + if(parent.isValid()) { + // Get the parent index + VProperty* parentItem = getProperty(parent); + if(parentItem) { + VProperty* childItem = parentItem->getChild(row); + if (childItem) + return createIndex(row, column, childItem); + } + } else if(row >= 0 && row < d_ptr->Properties->count()) { + return createIndex(row, column, d_ptr->Properties->getRootProperty(row)); + } + + return QModelIndex(); +} + +//! Returns the parent of one model index +QModelIndex VPropertyModel::parent ( const QModelIndex & index ) const +{ + if (!index.isValid()) + return QModelIndex(); + + VProperty* childItem = getProperty(index); + if(childItem) { + VProperty* parentItem = childItem->getParent(); + if(parentItem) { + VProperty* grandParentItem = parentItem->getParent(); + int parents_row = grandParentItem != nullptr ? grandParentItem->getChildRow(parentItem) : d_ptr->Properties->getRootProperties().indexOf(parentItem); + + if(parents_row >= 0) + return createIndex(parents_row, 0, parentItem); + } + } + + return QModelIndex(); +} + +//! Returns the item flags for the given index +Qt::ItemFlags VPropertyModel::flags (const QModelIndex& index) const +{ + VProperty* tmpProperty = getProperty(index); + if(!tmpProperty) + return Qt::NoItemFlags; + else + return tmpProperty->flags(index.column()); +} + +//! Sets the role data for the item at index to value +bool VPropertyModel::setData (const QModelIndex& index, const QVariant& value, int role) +{ + VProperty* tmpProperty = getProperty(index); + if(index.column() == 1 && tmpProperty) { + bool tmpHasChanged = tmpProperty->setData(value, role); + if(tmpProperty->getUpdateParent() && tmpHasChanged) { // If neccessary, update the parent as well + QModelIndex tmpParentIndex = parent(index); + emit dataChanged(tmpParentIndex, tmpParentIndex); + } + + if(tmpHasChanged) + emit onDataChangedByEditor(tmpProperty); + } + + + return true; +} + + +//! Returns the data of an model index +QVariant VPropertyModel::data ( const QModelIndex & index, int role ) const +{ + VProperty* tmpProperty = getProperty(index); + if(!tmpProperty) + return QVariant(); + else + return tmpProperty->data(index.column(), role); +} + + +QVariant VPropertyModel::headerData (int section, Qt::Orientation orientation, int role) const +{ + if(orientation == Qt::Horizontal && role == Qt::DisplayRole) { + // Header data + if (section == 0) return d_ptr->HeadlineProperty; + else if (section == 1) return d_ptr->HeadlineValue; + } + else if(role == Qt::DisplayRole) + return QVariant(section); + + return QVariant(); +} + + +//! Returns the number of rows +int VPropertyModel::rowCount ( const QModelIndex & parent ) const +{ + if(parent.isValid()) { + VProperty* tmpParent = getProperty(parent); + if(tmpParent) + return tmpParent->getRowCount(); + } + + // Return the root property count + if(d_ptr->Properties) + return d_ptr->Properties->getRootPropertyCount(); + + return 0; +} + + +//! Returns the number of columns +int VPropertyModel::columnCount ( const QModelIndex & parent) const +{ + Q_UNUSED(parent); + return 2; +} + + +//! Gets a property by its ModelIndex +VProperty* VPropertyModel::getProperty(const QModelIndex &index) const +{ + if (index.isValid()) { + VProperty* prop = static_cast(index.internalPointer()); + + if (prop) + return prop; + } + return nullptr; +} + +QString VPropertyModel::getPropertyID(VProperty *prop) const +{ + return d_ptr->Properties != nullptr ? d_ptr->Properties->getPropertyID(prop) : QString(); +} + +QModelIndex VPropertyModel::getIndexFromProperty(VProperty* property, int column) const +{ + if (!property || column > columnCount() || column < 0) + return QModelIndex(); + + VProperty* parentItem = property->getParent(); + int row = 0; + + if(parentItem) { + row = parentItem->getChildRow(property); + } + + return createIndex(row, column, property); +} + + +void VPropertyModel::onDataChangedByModel(VProperty* property) +{ + QModelIndex tmpIndex = getIndexFromProperty(property, 1); + if(tmpIndex.isValid()) + { + emit dataChanged(tmpIndex, tmpIndex); + emit onDataChangedByEditor(property); + } +} + +const VPropertySet *VPropertyModel::getPropertySet() const +{ + return d_ptr->Properties; +} + +void VPropertyModel::clear(bool emit_signals) +{ + setPropertySet(nullptr, emit_signals); +} + +VPropertySet *VPropertyModel::takePropertySet(VPropertySet *new_property_set, bool emit_signals) +{ + VPropertySet* tmpOldPropertySet = d_ptr->Properties; + + if(emit_signals) emit beginResetModel(); + d_ptr->Properties = new_property_set; + if(emit_signals) emit endResetModel(); + + return tmpOldPropertySet; +} + +void VPropertyModel::setPropertySet(VPropertySet *property_set, bool emit_signals) +{ + VPropertySet* tmpOldPropertySet = takePropertySet(property_set, emit_signals); + if(tmpOldPropertySet) + delete tmpOldPropertySet; +} + +VProperty *VPropertyModel::takeProperty(const QString &id) +{ + QModelIndex tmpIndex = getIndexFromProperty(getProperty(id)); + if(d_ptr->Properties && tmpIndex.isValid()) { + beginRemoveRows(tmpIndex.parent(), tmpIndex.row(), tmpIndex.row()); + VProperty* tmpProp = d_ptr->Properties->takeProperty(id); + endRemoveRows(); + return tmpProp; + } + + return nullptr; +} + +void VPropertyModel::removeProperty(const QString &id) +{ + QModelIndex tmpIndex = getIndexFromProperty(getProperty(id)); + if(d_ptr->Properties && tmpIndex.isValid()) { + beginRemoveRows(tmpIndex.parent(), tmpIndex.row(), tmpIndex.row()); + d_ptr->Properties->removeProperty(id); + endRemoveRows(); + } +} diff --git a/src/libs/vpropertyexplorer/vpropertymodel.h b/src/libs/vpropertyexplorer/vpropertymodel.h new file mode 100644 index 000000000..fb9df7a39 --- /dev/null +++ b/src/libs/vpropertyexplorer/vpropertymodel.h @@ -0,0 +1,140 @@ +#ifndef VPROPERTYMODEL_H +#define VPROPERTYMODEL_H + +#include "vpropertyexplorer_global.h" + +#include +#include +#include + +#include "vproperty.h" + +namespace VPE { + +class VPropertyModelPrivate; +class VPropertySet; + +//! \brief This is the base model for managing all the properties +//! and passing them to the view. +//! +//! When you create your own "proxy models", this is the place to +//! start: just subclass VPropertyModel and extend the new class. +//! Have a look at existing examples of proxies. +//! +//! Note that in this context, the term "proxy model" does not refer +//! to VProxyModel as that is another concept. +//! The idea behind "proxy models" in the QtPropertyExplorer framework +//! is to provide an convenient interface which takes data as your +//! application (or a third-party-library) provides it, and converts this +//! data to VProperty-objects, manage them and produce output for the views. +//! +//! In most cases, you will not need to rewrite the basic functions of +//! QAbstractItemModel, as VPropertyModel provides standard implementations +//! to work with. Thus, instead of subclassing VPropertyModel, it is also +//! possible to use VPropertyModel directly (as it is not an abstract class). +//! This might be more convenient in some cases. +class VPROPERTYEXPLORERSHARED_EXPORT VPropertyModel : public QAbstractItemModel +{ + Q_OBJECT +public: + explicit VPropertyModel(QObject * parent = 0); + virtual ~VPropertyModel(); + + //! Adds the property to the model and attaches it to the parentid + //! \param emitsignals If this is set to false, this function will not call beginInsertRows() and endInsertRows(), so it has to be called from a subclass + virtual bool addProperty(VProperty* property, const QString& id, const QString& parentid = QString(), + bool emitsignals = true); + + //! Creates a property and adds it to the model + virtual VProperty* createProperty(const QString& id, const QString& name, const QString& parentid = QString(), + const QVariant& data = QVariant()); + + //! Gets a property by it's ID + virtual VProperty* getProperty(const QString& id); + + //! Returns the item flags for the given index + virtual Qt::ItemFlags flags (const QModelIndex& index) const; + + //! Sets the role data for the item at index to value + virtual bool setData (const QModelIndex& index, const QVariant& value, int role = Qt::EditRole); + + //! Returns the model index at row/column + virtual QModelIndex index (int row, int column, const QModelIndex & parent = QModelIndex() ) const; + + //! Returns the parent of one model index + virtual QModelIndex parent (const QModelIndex& index) const; + + //! Returns the data of an model index + virtual QVariant data (const QModelIndex& index, int role = Qt::DisplayRole) const; + + //! Returns the data for the given role and section in the header with the specified orientation. + virtual QVariant headerData (int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const; + + //! Returns the number of rows + virtual int rowCount ( const QModelIndex & parent = QModelIndex() ) const; + + //! Returns the number of columns + virtual int columnCount ( const QModelIndex & parent = QModelIndex() ) const; + + + + //! Gets a property by its ModelIndex + //! \param index The modelIndex of the property. + //! \return Returns the property with the given index, or NULL if none such property exists + virtual VProperty* getProperty(const QModelIndex &index) const; + + //! Returns the ID of the property within the model + //! The concept of property IDs is, that the object that manages the properties + //! and not the properties themselves handle the IDs. + //! \param property + //! \return Returns the ID under which the property is stored within the model + virtual QString getPropertyID(VProperty* prop) const; + + //! Returns a const pointer to the property set managed by this model. If you want to manipulate the property set, either use the methods provided by the model or use takePropertySet() and setPropertySet(). + //! \return A constant pointer to the property set or NULL if there currently is none. + virtual const VPropertySet* getPropertySet() const; + + //! Clears the model, deletes the property set managed by this model. + //! \param emit_signals Default: true. Set this to false if you want to prevent the model from emmiting the reset model signals + virtual void clear(bool emit_signals = true); + + //! Removes the current property set and returns it. If new_property_set is set, the old one will be replaced by the new one + //! \param new_property_set The new property set to replace the old one with. Default: NULL + //! \param emit_signals Default: true. Set this to false if you want to prevent the model from emmiting the reset model signals + //! \return A constant pointer to the property set or NULL if there currently is none. + virtual VPropertySet* takePropertySet(VPropertySet* new_property_set = nullptr, bool emit_signals = true); + + //! Sets a new property set. The model will take ownership of the property set. The old property set will be deleted. + //! \param property_set The new property set. Setting this to NULL has the same effect as calling clear. + //! \param emit_signals Default: true. Set this to false if you want to prevent the model from emmiting the reset model signals + //! \return A constant pointer to the property set or NULL if there currently is none. + virtual void setPropertySet(VPropertySet* property_set, bool emit_signals = true); + + //! Removes a property from the model and returns it + virtual VProperty* takeProperty(const QString& id); + + //! Removes a property from the model and deletes it + virtual void removeProperty(const QString& id); + +signals: + //! This signal is being emitted, when the setData method is being called + void onDataChangedByEditor(VProperty* property); + +public slots: + //! This function causes the views to update the property + void onDataChangedByModel(VProperty* property); + +protected: + //! Gets a property by its ModelIndex + virtual QModelIndex getIndexFromProperty(VProperty* property, int column = 0) const; + + //! Protected constructor passing the private object + VPropertyModel(VPropertyModelPrivate* d, QObject* parent = 0); + + //! The model data + VPropertyModelPrivate* d_ptr; +}; + +} + +#endif // VPROPERTYMODEL_H diff --git a/src/libs/vpropertyexplorer/vpropertymodel_p.h b/src/libs/vpropertyexplorer/vpropertymodel_p.h new file mode 100644 index 000000000..9109a3e90 --- /dev/null +++ b/src/libs/vpropertyexplorer/vpropertymodel_p.h @@ -0,0 +1,40 @@ +#ifndef VPROPERTYMODEL_P_H +#define VPROPERTYMODEL_P_H + +// ONLY INCLUDE THIS IN .CPP FILES + +#include +#include +#include + +namespace VPE { + +class VProperty; +class VPropertySet; + +class VPropertyModelPrivate { +public: + //! The property set holding the properties + VPropertySet* Properties; + + //! The header data for the property name column + QString HeadlineProperty; + + //! The header data for the value column + QString HeadlineValue; + + //! Constructor + VPropertyModelPrivate() + : Properties(nullptr) + { + //: The text that appears in the first column header + HeadlineProperty = QObject::tr("Property"); + + //: The text that appears in the second column header + HeadlineValue = QObject::tr("Value"); + } +}; + +} + +#endif // VPROPERTYMODEL_P_H diff --git a/src/libs/vpropertyexplorer/vpropertyset.cpp b/src/libs/vpropertyexplorer/vpropertyset.cpp new file mode 100644 index 000000000..d5554acd9 --- /dev/null +++ b/src/libs/vpropertyexplorer/vpropertyset.cpp @@ -0,0 +1,211 @@ +#include "vpropertyset.h" +using namespace VPE; + +#include "vpropertyset_p.h" + + +VPropertySet::VPropertySet() + : d_ptr(new VPropertySetPrivate()) +{ +} + + +VPropertySet::~VPropertySet() +{ + // Delete all the properties + clear(true); + + delete d_ptr; +} + +bool VPropertySet::addProperty(VProperty *property, const QString &id, const QString &parentid) +{ + // Check if the property to add is not a null pointer + if(!property) + return false; + + VProperty* tmpParent = parentid.isEmpty() ? NULL : getProperty(parentid); + return addProperty(property, id, tmpParent); +} + +bool VPropertySet::addProperty(VProperty *property, const QString &id, VProperty *parent_property) +{ + // Check if the property to add is not a null pointer + if(!property) + return false; + + QString tmpOldID = getPropertyID(property); + if(!tmpOldID.isEmpty()) + d_ptr->Properties.remove(tmpOldID); + + if(parent_property) + parent_property->addChild(property); + else { + d_ptr->RootProperties.append(property); + if(property->getParent()) + property->getParent()->removeChild(property); + } + + if(!id.isEmpty()) + d_ptr->Properties.insert(id, property); + + return true; +} + +bool VPropertySet::hasProperty(VProperty *property) const +{ + if(!property) + return false; + + return hasProperty(property, NULL); +} + +VProperty *VPropertySet::getProperty(const QString &id) const +{ + return d_ptr->Properties.value(id, NULL); +} + +VProperty *VPropertySet::takeProperty(const QString &id) +{ + VProperty* tmpProp = getProperty(id); + removeProperty(tmpProp, false); + + // Return the property + return tmpProp; +} + +void VPropertySet::removeProperty(const QString &id) +{ + VProperty* tmpProp = takeProperty(id); + if(tmpProp) + delete tmpProp; +} + +void VPropertySet::removeProperty(VProperty* prop, bool delete_property) +{ + // Remove all the children + removePropertyFromSet(prop); + + // Remove from parent and optionally delete + if(prop) { + prop->setParent(NULL); + + if(delete_property) + delete prop; + } +} + +int VPropertySet::count() const +{ + return d_ptr->Properties.count(); +} + +void VPropertySet::clear(bool delete_properties) +{ + d_ptr->Properties.clear(); + while(!d_ptr->RootProperties.isEmpty()) { + VProperty* tmpProp = d_ptr->RootProperties.takeLast(); + if(tmpProp != nullptr && delete_properties) { + delete tmpProp; + } + } +} + +QString VPropertySet::getPropertyID(const VProperty *prop, bool look_for_parent_id) const +{ + QString tmpResult; + const VProperty* tmpCurrentProp = prop; + + while(tmpCurrentProp && (look_for_parent_id || prop == tmpCurrentProp) && tmpResult.isEmpty()) { + + // todo: The following code doesn't work, because .key() doesn't accept a const VProperty* pointer ... + //tmpResult = d_ptr->Properties.key(tmpCurrentProp, QString()); + + // ... which is why we need the code below + for (QMap::const_iterator i = d_ptr->Properties.constBegin(); i != d_ptr->Properties.constEnd(); ++i) { + if(tmpCurrentProp == (*i)) + return i.key(); + } + + tmpCurrentProp = tmpCurrentProp->getParent(); + } + + return tmpResult; +} + +const QMap &VPropertySet::getPropertiesMap() const +{ + return d_ptr->Properties; +} + +const QList &VPropertySet::getRootProperties() const +{ + return d_ptr->RootProperties; +} + +VProperty *VPropertySet::getRootProperty(int row) const +{ + return d_ptr->RootProperties.value(row, NULL); +} + +int VPropertySet::getRootPropertyCount() const +{ + return d_ptr->RootProperties.count(); +} + +VPropertySet* VPropertySet::clone() const +{ + VPropertySet* tmpResult = new VPropertySet(); + + foreach(VProperty* tmpProperty, d_ptr->RootProperties) + cloneProperty(tmpProperty, NULL, tmpResult); + + + return tmpResult; +} + + + +bool VPropertySet::hasProperty(VProperty *property, VProperty *parent) const +{ + if(!property) + return false; + + const QList& tmpChildrenList = (parent != NULL ? parent->getChildren() : d_ptr->RootProperties); + foreach(VProperty* tmpProp, tmpChildrenList) { + if(!tmpProp) + continue; + else if(tmpProp == property || hasProperty(property, tmpProp)) + return true; + } + + return false; +} + +void VPropertySet::cloneProperty(VProperty* property_to_clone, VProperty *parent_property, VPropertySet *output_set) const +{ + if(!output_set || !property_to_clone || !hasProperty(property_to_clone)) + return; + + QString tmpID = getPropertyID(property_to_clone, false); + VProperty* tmpNewProperty = property_to_clone->clone(false); // We want to clone the children ourselves (because of the IDs) + + output_set->addProperty(tmpNewProperty, tmpID, parent_property); + for(int i = 0; i < property_to_clone->getRowCount(); ++i) + cloneProperty(property_to_clone->getChild(i), tmpNewProperty, output_set); +} + +void VPropertySet::removePropertyFromSet(VProperty *prop) +{ + // Remove all the children + foreach(VProperty* tmpChild, prop->getChildren()) + removeProperty(tmpChild); + + + QList tmpKeys = d_ptr->Properties.keys(prop); + foreach(const QString& tmpID, tmpKeys) + d_ptr->Properties.remove(tmpID); + + // Remove from list + d_ptr->RootProperties.removeAll(prop); +} diff --git a/src/libs/vpropertyexplorer/vpropertyset.h b/src/libs/vpropertyexplorer/vpropertyset.h new file mode 100644 index 000000000..1a7ff9ca0 --- /dev/null +++ b/src/libs/vpropertyexplorer/vpropertyset.h @@ -0,0 +1,111 @@ +#ifndef VPROPERTYSET_H +#define VPROPERTYSET_H + +#include "vpropertyexplorer_global.h" + +#include +#include + +#include "vproperty.h" + +namespace VPE { + +// Forward declaration +class VPropertySetPrivate; + +// todo: better description +//! \brief VPropertySet is a simple class for managing a set of properties. +//! If you don't need all the Model-functionality, chose this class +//! over VPropertyModel. +//! + +//! +class VPROPERTYEXPLORERSHARED_EXPORT VPropertySet +{ +public: + //! Default constructor, creating an empty property set + explicit VPropertySet(); + + //! Destructor + virtual ~VPropertySet(); + + //! Adds the property to the model and attaches it to the parentid. Note that if the property has a parent which is not part of this set, it will be removed from that parent. + //! \param property The property to add + //! \param id The property ID. If id is empty, the property will not be accessable by it's id but still be added. If the property was filed under another ID before, that will no longer be valid. + //! \param parentid The property's ID to which to add the property as child. Pass empty string to add it to the root properties. + virtual bool addProperty(VProperty* property, const QString& id, const QString& parentid); + + //! Adds the property to the model and attaches it to the parent property. + //! \param property The property to add + //! \param id The property ID. If id is empty, the property will not be accessable by it's id but still be added. If the property was filed under another ID before, that will no longer be valid. + //! \param parentid The property to which to add the property as child. Pass NULL to add it to the root properties. + virtual bool addProperty(VProperty* property, const QString& id, VProperty* parent_property = nullptr); + + //! Checks whether a property belongs to this set and returns the result + //! \param property The property to check for + //! \return True, if the property is part of this set, false otherwise + virtual bool hasProperty(VProperty* property) const; + + //! Gets a property by it's ID + virtual VProperty* getProperty(const QString& id) const; + + //! Removes a property from the set and returns it + virtual VProperty* takeProperty(const QString& id); + + //! Removes a property from the set and deletes it + virtual void removeProperty(const QString& id); + + //! Removes a property from the set and deletes it optionally + virtual void removeProperty(VProperty* prop, bool delete_property = true); + + //! Returns the number of properties with in ID that are directly accessable by getProperty() + virtual int count() const; + + //! Clears the set and (optionally) deletes all properties + //! \param delete_properties Set this to false, if you don't want the properties to get deleted. + virtual void clear(bool delete_properties = true); + + //! Returns the ID of the property within the set + //! The concept of property IDs is, that the object that manages the properties + //! and not the properties themselves handle the IDs. + //! \param prop The property of which to get the ID. + //! \param look_for_parent_id If this is TRUE and the property has no ID, all the parent properties are checked. + //! \return Returns the ID under which the property is stored within the set + virtual QString getPropertyID(const VProperty* prop, bool look_for_parent_id = true) const; + + //! Returns a const reference to the map of properties + const QMap& getPropertiesMap() const; + + //! Returns a const reference to the list of root properties + const QList& getRootProperties() const; + + //! Returns the root property in a certain row + //! \param row The root row in which to look for the root property + VProperty* getRootProperty(int row) const; + + //! Returns the number of independent properties + int getRootPropertyCount() const; + + //! Clones the property set + VPropertySet* clone() const; + +protected: + //! Checks whether a property belongs to this set and returns the result + //! \param property The property to check for + //! \param parent The parent property from which to start checking all the children + //! \return True, if the property is part of this set, false otherwise + virtual bool hasProperty(VProperty* property, VProperty* parent) const; + + //! Clones a property into another property set + void cloneProperty(VProperty* property_to_clone, VProperty* parent_property, VPropertySet* output_set) const; + + //! Recursivly removes a property's child properties from the set, but not from the parent + virtual void removePropertyFromSet(VProperty* prop); + + //! The data + VPropertySetPrivate* d_ptr; +}; + +} + +#endif // VPROPERTYMODEL_H diff --git a/src/libs/vpropertyexplorer/vpropertyset_p.h b/src/libs/vpropertyexplorer/vpropertyset_p.h new file mode 100644 index 000000000..b4750abe2 --- /dev/null +++ b/src/libs/vpropertyexplorer/vpropertyset_p.h @@ -0,0 +1,29 @@ +#ifndef VPROPERTYSET_P_H +#define VPROPERTYSET_P_H + +// ONLY INCLUDE THIS IN .CPP FILES + +#include +#include + +namespace VPE { + +class VProperty; + +class VPropertySetPrivate { +public: + //! Property map (ID, Property) + QMap Properties; // All the Properties managed by this model are being stored in this map for quick access + + //! List containing the root properties + QList RootProperties; + + //! Constructor + VPropertySetPrivate() + { + } +}; + +} + +#endif // VPROPERTYMODEL_P_H diff --git a/src/libs/vpropertyexplorer/vpropertytreeview.cpp b/src/libs/vpropertyexplorer/vpropertytreeview.cpp new file mode 100644 index 000000000..7f36602ef --- /dev/null +++ b/src/libs/vpropertyexplorer/vpropertytreeview.cpp @@ -0,0 +1,57 @@ +#include "vpropertytreeview.h" + +#include "vpropertydelegate.h" +#include "vpropertymodel.h" + +#include "vpropertytreeview_p.h" + +using namespace VPE; + +VPropertyTreeView::VPropertyTreeView(QWidget *parent) + : QTreeView(parent), d_ptr(new VPropertyTreeViewPrivate()) +{ + init(); +} + +VPropertyTreeView::VPropertyTreeView(VPropertyModel *model, QWidget *parent) + : QTreeView(parent), d_ptr(new VPropertyTreeViewPrivate()) +{ + init(); + + if(model) + setModel(model); +} + +VPropertyTreeView::VPropertyTreeView(VPropertyTreeViewPrivate *d, bool init_, QWidget *parent) + : QTreeView(parent), d_ptr(d) +{ + if(init_) + init(); +} + +VPropertyTreeView::~VPropertyTreeView() +{ + delete d_ptr; +} + + +void VPropertyTreeView::setRowHeight(int height, bool add_to_standard) +{ + d_ptr->PropertyDelegate->setRowHeight(height, add_to_standard); +} + +void VPropertyTreeView::init() +{ + setAlternatingRowColors(true); + setUniformRowHeights(true); + d_ptr->PropertyDelegate = new VPropertyDelegate(this); + setItemDelegate(d_ptr->PropertyDelegate); + + setSelectionMode(QTreeView::SingleSelection); + setSelectionBehavior(QTreeView::SelectRows); + setRootIsDecorated(true); + + setEditTriggers(QAbstractItemView::CurrentChanged | QAbstractItemView::SelectedClicked); +} + + diff --git a/src/libs/vpropertyexplorer/vpropertytreeview.h b/src/libs/vpropertyexplorer/vpropertytreeview.h new file mode 100644 index 000000000..3e9bb5946 --- /dev/null +++ b/src/libs/vpropertyexplorer/vpropertytreeview.h @@ -0,0 +1,45 @@ +#ifndef VPROPERTYTREEVIEW_H +#define VPROPERTYTREEVIEW_H + +#include +#include "vpropertyexplorer_global.h" + +namespace VPE { + +class VPropertyTreeViewPrivate; + +class VPROPERTYEXPLORERSHARED_EXPORT VPropertyDelegate; +class VPROPERTYEXPLORERSHARED_EXPORT VPropertyModel; + +class VPROPERTYEXPLORERSHARED_EXPORT VPropertyTreeView : public QTreeView +{ + Q_OBJECT +public: + //! Default constructor + explicit VPropertyTreeView(QWidget *parent = 0); + + //! The destructor, taking a model and setting it to the tree view + //! \param The model to set as model for this tree view + VPropertyTreeView(VPropertyModel* model, QWidget *parent = 0); + + //! Destructor + virtual ~VPropertyTreeView(); + + //! Sets the height for each row. Set this to 0 in order to let the standard delegate decide + void setRowHeight(int height = 0, bool add_to_standard = false); + + +protected: + //! This method is called by the constructors to initialize the view + virtual void init(); + + //! protected constructor + explicit VPropertyTreeView(VPropertyTreeViewPrivate* d, bool init_, QWidget *parent = 0); + + //! The protected data + VPropertyTreeViewPrivate* d_ptr; +}; + +} + +#endif // VPROPERTYTREEVIEWEEVIEW_H diff --git a/src/libs/vpropertyexplorer/vpropertytreeview_p.h b/src/libs/vpropertyexplorer/vpropertytreeview_p.h new file mode 100644 index 000000000..e5075517a --- /dev/null +++ b/src/libs/vpropertyexplorer/vpropertytreeview_p.h @@ -0,0 +1,30 @@ +#ifndef VPROPERTYTREEVIEW_P_H +#define VPROPERTYTREEVIEW_P_H + +// ONLY INCLUDE THIS IN .CPP FILES + +#include +#include + +namespace VPE { + +class VPropertyDelegate; + +class VPropertyTreeViewPrivate +{ +public: + //! Property Delegate + VPropertyDelegate* PropertyDelegate; + + //! Constructor + VPropertyTreeViewPrivate(VPropertyDelegate* delegate) + : PropertyDelegate(delegate) {} + + //! Constructor + VPropertyTreeViewPrivate() + : PropertyDelegate(nullptr) {} +}; + +} + +#endif // VPROPERTYTREEVIEW_P_H diff --git a/src/libs/vpropertyexplorer/vserializedproperty.cpp b/src/libs/vpropertyexplorer/vserializedproperty.cpp new file mode 100644 index 000000000..1b4602833 --- /dev/null +++ b/src/libs/vpropertyexplorer/vserializedproperty.cpp @@ -0,0 +1,49 @@ +#include "vserializedproperty.h" + +using namespace VPE; + +VSerializedProperty::VSerializedProperty() + : ID(), Type(), Value() +{ +} + +/*! Creates a new VSerializedProperty from an existing property + +*/ +VSerializedProperty::VSerializedProperty(const VProperty* property, const VPropertySet* set) + : ID(), Type(property ? property->type() : QString()), Value(property ? property->getValue() : QVariant()) +{ + if(set) { + ID = set->getPropertyID(property); + + initChildren(property, set); + } +} + +VSerializedProperty::VSerializedProperty(const VProperty *property, const QString &id, const VPropertySet *set) + : ID(id), Type(property ? property->type() : QString()), Value(property ? property->getValue() : QVariant()) +{ + initChildren(property, set); +} + +VSerializedProperty::VSerializedProperty(const QString &id, const QString &type, const QVariant &value) + : ID(id), Type(type), Value(value) +{ +} + +VPE::VSerializedProperty::~VSerializedProperty() +{ + // +} + +void VSerializedProperty::initChildren(const VProperty *property, const VPropertySet *set) +{ + if(property && set) { + const QList& tmpChildren = property->getChildren(); + foreach(const VProperty* tmpChild, tmpChildren) { + QString tmpChildID = set->getPropertyID(property); + Children.append(VSerializedProperty(tmpChild, tmpChildID, set)); + } + } +} + diff --git a/src/libs/vpropertyexplorer/vserializedproperty.h b/src/libs/vpropertyexplorer/vserializedproperty.h new file mode 100644 index 000000000..b5b7597f7 --- /dev/null +++ b/src/libs/vpropertyexplorer/vserializedproperty.h @@ -0,0 +1,52 @@ +#ifndef VSERIALIZEDPROPERTY_H +#define VSERIALIZEDPROPERTY_H + +#include "vpropertyexplorer_global.h" + +#include +#include +#include + +#include "vproperty.h" +#include "vpropertyset.h" + +namespace VPE { + + +class VPROPERTYEXPLORERSHARED_EXPORT VSerializedProperty +{ +public: + //! Constructor + VSerializedProperty(); + + //! Constructor + VSerializedProperty(const VProperty* property, const VPropertySet* set); + + //! Constructor + VSerializedProperty(const VProperty* property, const QString& id, const VPropertySet* set); + + //! Constructor + VSerializedProperty(const QString& id, const QString& type, const QVariant& value); + + //! Destructor + ~VSerializedProperty(); + + //! The property type + QString ID; + + //! The property type + QString Type; + + //! The serialized value of the property + QVariant Value; + + //! List of child properties + QList Children; + +private: + void initChildren(const VProperty* property, const VPropertySet* set); +}; + +} + +#endif // VSERIALIZEDPROPERTY_H diff --git a/src/libs/vpropertyexplorer/vstandardpropertyfactory.cpp b/src/libs/vpropertyexplorer/vstandardpropertyfactory.cpp new file mode 100644 index 000000000..8b175764c --- /dev/null +++ b/src/libs/vpropertyexplorer/vstandardpropertyfactory.cpp @@ -0,0 +1,66 @@ +#include "vstandardpropertyfactory.h" + +#include "vpropertyfactorymanager.h" + +// Supported Properties +#include "vproperty.h" +#include "plugins/vboolproperty.h" +#include "plugins/vcolorproperty.h" +#include "plugins/vemptyproperty.h" +#include "plugins/venumproperty.h" +#include "plugins/vfileproperty.h" +#include "plugins/vnumberproperty.h" +#include "plugins/vshortcutproperty.h" +#include "plugins/Vector3d/vvector3dproperty.h" + + +using namespace VPE; + +VStandardPropertyFactory::VStandardPropertyFactory() + : VAbstractPropertyFactory() +{ +} + +VStandardPropertyFactory::VStandardPropertyFactory(VPropertyFactoryManager *manager) + : VAbstractPropertyFactory() +{ + if(manager) { + manager->registerFactory("string", this); + manager->registerFactory("bool", this); + manager->registerFactory("color", this); + manager->registerFactory("empty", this); + manager->registerFactory("enum", this); + manager->registerFactory("file", this); + manager->registerFactory("integer", this); + manager->registerFactory("double", this); + manager->registerFactory("shortcut", this); + manager->registerFactory("vector3d", this); + } +} + +VProperty *VStandardPropertyFactory::createProperty(const QString &type, const QString &name) +{ + if(type == QString("string")) { + return new VProperty(name); + } else if(type == QString("bool")) { + return new VBoolProperty(name); + } else if(type == QString("color")) { + return new VColorProperty(name); + } else if(type == QString("empty")) { + return new VEmptyProperty(name); + } else if(type == QString("enum")) { + return new VEnumProperty(name); + } else if(type == QString("file")) { + return new VFileProperty(name); + } else if(type == QString("integer")) { + return new VIntegerProperty(name); + } else if(type == QString("double")) { + return new VDoubleProperty(name); + } else if(type == QString("shortcut")) { + return new VShortcutProperty(name); + } else if(type == QString("vector3d")) { + return new QVector3DProperty(name); + } + else + return nullptr; +} diff --git a/src/libs/vpropertyexplorer/vstandardpropertyfactory.h b/src/libs/vpropertyexplorer/vstandardpropertyfactory.h new file mode 100644 index 000000000..b8bc877fe --- /dev/null +++ b/src/libs/vpropertyexplorer/vstandardpropertyfactory.h @@ -0,0 +1,33 @@ +#ifndef VASTANDARDPROPERTYFACTORY_H +#define VASTANDARDPROPERTYFACTORY_H + +#include "vpropertyexplorer_global.h" +#include "vabstractpropertyfactory.h" + +namespace VPE { + +class VProperty; + +class VPropertyFactoryManager; + +//! The standard property factory is able to create all the properties that are included in VPropertyExplorer +//! by default. +class VPROPERTYEXPLORERSHARED_EXPORT VStandardPropertyFactory : public VAbstractPropertyFactory +{ +public: + //! Constructor + VStandardPropertyFactory(); + + //! Constructor + //! \param manager Registers this factory at the manager for all it's types + VStandardPropertyFactory(VPropertyFactoryManager* manager); + + //! Creates a new property of a certain type and assigns a name and description (otionally) + //! \param type The type of the property as string + //! \return Returns the created property or NULL if it couldn't be be created + virtual VProperty* createProperty(const QString& type, const QString &name); +}; + +} + +#endif // VASTANDARDPROPERTYFACTORY_H diff --git a/src/libs/vpropertyexplorer/vwidgetproperty_p.h b/src/libs/vpropertyexplorer/vwidgetproperty_p.h new file mode 100644 index 000000000..24dca698f --- /dev/null +++ b/src/libs/vpropertyexplorer/vwidgetproperty_p.h @@ -0,0 +1,35 @@ +#ifndef VWIDGETPROPERTY_P_H +#define VWIDGETPROPERTY_P_H + +// ONLY INCLUDE THIS IN .CPP FILES + +#include "vproperty_p.h" + +#include +#include + +namespace VPE { + +class VWidgetPropertyPrivate : public VPropertyPrivate { +public: + //! The widget to show + QPointer Widget; + + //! Constructor passing name and type + VWidgetPropertyPrivate(const QString& name, QVariant::Type type, QWidget* widget = nullptr) + : VPropertyPrivate(name, type), Widget(widget) {} + + //! Constructor + VWidgetPropertyPrivate() + : VPropertyPrivate(), Widget(nullptr) {} + + //! Destructor + ~VWidgetPropertyPrivate() { + if(Widget) + Widget->deleteLater(); + } +}; + +} + +#endif // VWIDGETPROPERTY_P_H