diff --git a/GUI/coregui/Models/ComboProperty.cpp b/GUI/coregui/Models/ComboProperty.cpp index 6091ed671a09fd807d208820d2a27de603619b8e..25230e509081070d69bff707c08c3f0f0f406824 100644 --- a/GUI/coregui/Models/ComboProperty.cpp +++ b/GUI/coregui/Models/ComboProperty.cpp @@ -133,7 +133,7 @@ void ComboProperty::setStringOfValues(const QString& values) m_current_index = m_values.contains(current) ? m_values.indexOf(current) : 0; } -QVariant ComboProperty::getVariant() const +QVariant ComboProperty::variant() const { QVariant result; result.setValue(*this); diff --git a/GUI/coregui/Models/ComboProperty.h b/GUI/coregui/Models/ComboProperty.h index f795b7772c38b4d0ccbbf51e78a1bed118dff05f..3cc25a8c2f083eed749a4f8e2ac239e5e58205cc 100644 --- a/GUI/coregui/Models/ComboProperty.h +++ b/GUI/coregui/Models/ComboProperty.h @@ -50,7 +50,7 @@ public: QString stringOfValues() const; void setStringOfValues(const QString& values); - QVariant getVariant() const; + QVariant variant() const; private: QStringList m_values; diff --git a/GUI/coregui/Models/FitParameterItems.cpp b/GUI/coregui/Models/FitParameterItems.cpp index dee62dbc03cd1a498d6b603c8b59baf92d603c63..5af338c839bd9c437bfd927157044dd65fb7dee7 100644 --- a/GUI/coregui/Models/FitParameterItems.cpp +++ b/GUI/coregui/Models/FitParameterItems.cpp @@ -67,7 +67,7 @@ const QString FitParameterItem::T_LINK = "Link tag"; FitParameterItem::FitParameterItem() : SessionItem(Constants::FitParameterType) { - addProperty(P_TYPE, fitParameterTypeCombo().getVariant()); + addProperty(P_TYPE, fitParameterTypeCombo().variant()); addProperty(P_START_VALUE, 0.0); addProperty(P_MIN, 0.0); addProperty(P_MAX, 0.0)->setEnabled(false); diff --git a/GUI/coregui/Models/GUIObjectBuilder.cpp b/GUI/coregui/Models/GUIObjectBuilder.cpp index 6e3070a41533f77cc51314c3f9f46f28846387c2..9f8bb34ecc8468f98e130f01f1c00451ea00ec8f 100644 --- a/GUI/coregui/Models/GUIObjectBuilder.cpp +++ b/GUI/coregui/Models/GUIObjectBuilder.cpp @@ -173,7 +173,7 @@ void GUIObjectBuilder::visit(const ParticleLayout* p_sample) approx_prop.setValue(Constants::LAYOUT_SSCA); break; } - p_layout_item->setItemValue(ParticleLayoutItem::P_APPROX, approx_prop.getVariant()); + p_layout_item->setItemValue(ParticleLayoutItem::P_APPROX, approx_prop.variant()); p_layout_item->setItemValue(ParticleLayoutItem::P_TOTAL_DENSITY, p_sample->totalParticleSurfaceDensity()); m_levelToParentItem[depth()] = p_layout_item; @@ -192,7 +192,7 @@ void GUIObjectBuilder::visit(const Layer* p_sample) SessionItem* p_layer_item = m_sampleModel->insertNewItem( Constants::LayerType, m_sampleModel->indexOfItem(p_parent)); p_layer_item->setItemValue(LayerItem::P_MATERIAL, - createMaterialFromDomain(p_sample->material()).getVariant()); + createMaterialFromDomain(p_sample->material()).variant()); TransformFromDomain::setItemFromSample(p_layer_item, p_sample, p_interface); @@ -215,7 +215,7 @@ void GUIObjectBuilder::visit(const Particle* p_sample) { auto p_particle_item = InsertIParticle(p_sample, Constants::ParticleType); p_particle_item->setItemValue(ParticleItem::P_MATERIAL, - createMaterialFromDomain(p_sample->material()).getVariant()); + createMaterialFromDomain(p_sample->material()).variant()); } void GUIObjectBuilder::visit(const ParticleDistribution* p_sample) diff --git a/GUI/coregui/Models/IntensityDataItem.cpp b/GUI/coregui/Models/IntensityDataItem.cpp index d268d5c8da1c17625bbd49be80e6d9895f320df0..133a718dd3b87214de327428f94e3a421e088fbe 100644 --- a/GUI/coregui/Models/IntensityDataItem.cpp +++ b/GUI/coregui/Models/IntensityDataItem.cpp @@ -51,13 +51,13 @@ const QString IntensityDataItem::T_PROJECTIONS = "Projection tag"; IntensityDataItem::IntensityDataItem() : SessionItem(Constants::IntensityDataType) { ComboProperty units = ComboProperty() << Constants::UnitsNbins; - addProperty(P_AXES_UNITS, units.getVariant()); + addProperty(P_AXES_UNITS, units.variant()); addProperty(P_TITLE, QString())->setVisible(false); addProperty(P_PROJECTIONS_FLAG, false)->setVisible(false); addProperty(P_IS_INTERPOLATED, true); - addProperty(P_GRADIENT, gradientCombo().getVariant()); + addProperty(P_GRADIENT, gradientCombo().variant()); SessionItem* item = addGroupProperty(P_XAXIS, Constants::BasicAxisType); item->getItem(BasicAxisItem::P_NBINS)->setVisible(false); diff --git a/GUI/coregui/Models/JobItemUtils.cpp b/GUI/coregui/Models/JobItemUtils.cpp index 368abe0fd182d2bd8421993e4feefd1ba6e6cc44..a7b689e01f2444e08858509b08579ef49213895d 100644 --- a/GUI/coregui/Models/JobItemUtils.cpp +++ b/GUI/coregui/Models/JobItemUtils.cpp @@ -169,7 +169,7 @@ void JobItemUtils::setIntensityItemAxesUnits(IntensityDataItem* intensityItem, = preferableGUIAxesUnits(detector->defaultAxesUnits()); combo.setValue(nameFromAxesUnits(preferrable_units)); - intensityItem->setItemValue(IntensityDataItem::P_AXES_UNITS, combo.getVariant()); + intensityItem->setItemValue(IntensityDataItem::P_AXES_UNITS, combo.variant()); } void JobItemUtils::updateAxesTitle(IntensityDataItem* intensityItem) diff --git a/GUI/coregui/Models/LayerItem.cpp b/GUI/coregui/Models/LayerItem.cpp index d43b3b44158e235beb46542f116049a97685380b..4ae971cfc796741cf7681cd7a8f6ca6a0f0eb5b5 100644 --- a/GUI/coregui/Models/LayerItem.cpp +++ b/GUI/coregui/Models/LayerItem.cpp @@ -38,8 +38,9 @@ LayerItem::LayerItem() addProperty(P_THICKNESS, 0.0)->setLimits(RealLimits::lowerLimited(0.0)) .setToolTip(QStringLiteral("Thickness of a layer in nanometers")); - addProperty(P_MATERIAL, MaterialItemUtils::defaultMaterialProperty().getVariant()) - ->setToolTip(QStringLiteral("Material the layer is made of")); + addProperty(P_MATERIAL, MaterialItemUtils::defaultMaterialProperty().variant()) + ->setToolTip(QStringLiteral("Material the layer is made of")) + .setEditorType(Constants::MaterialEditorExternalType); addProperty(P_NSLICES, 1)->setLimits(RealLimits::lowerLimited(0.0)) .setToolTip(layer_nslices_tooltip); diff --git a/GUI/coregui/Models/LinkInstrumentItem.cpp b/GUI/coregui/Models/LinkInstrumentItem.cpp index 3cc10078a00ab2bb82edcc08ba40158294522c5a..9e0d41cda6a8dffa5e9868f2de4d24906b5c9ade 100644 --- a/GUI/coregui/Models/LinkInstrumentItem.cpp +++ b/GUI/coregui/Models/LinkInstrumentItem.cpp @@ -30,5 +30,5 @@ LinkInstrumentItem::LinkInstrumentItem() addProperty(P_INSTRUMENT_ID, QString()); addProperty(P_INSTRUMENT_NAME, QString()); ComboProperty instruments = ComboProperty() << "Undefined"; - addProperty(P_INSTRUMENT_COMBO, instruments.getVariant()); + addProperty(P_INSTRUMENT_COMBO, instruments.variant()); } diff --git a/GUI/coregui/Models/MaterialItem.cpp b/GUI/coregui/Models/MaterialItem.cpp index e325044c91f33f1061ada8b6e907bee75d9a1e54..5db870c3ff9dfcb77be04db44ca0a697bfd6c88e 100644 --- a/GUI/coregui/Models/MaterialItem.cpp +++ b/GUI/coregui/Models/MaterialItem.cpp @@ -15,11 +15,12 @@ // ************************************************************************** // #include "MaterialItem.h" -#include "ColorProperty.h" +#include "ExternalProperty.h" #include "GUIHelpers.h" #include "MaterialDataItem.h" #include "MaterialFactoryFuncs.h" #include "SessionItemUtils.h" +#include "MaterialItemUtils.h" using SessionItemUtils::GetVectorItem; @@ -38,8 +39,9 @@ MaterialItem::MaterialItem() { setItemName(Constants::HomogeneousMaterialType); - ColorProperty color; - addProperty(P_COLOR, color.getVariant()); + ExternalProperty color = MaterialItemUtils::colorProperty(QColor(Qt::red)); + addProperty(P_COLOR, color.variant())->setEditorType(Constants::ColorEditorExternalType); + addGroupProperty(P_MATERIAL_DATA, Constants::MaterialDataType); addGroupProperty(P_MAGNETIZATION, Constants::VectorType)->setToolTip(magnetization_tooltip); addProperty(P_IDENTIFIER, GUIHelpers::createUuid()); @@ -53,8 +55,8 @@ QString MaterialItem::getIdentifier() const QColor MaterialItem::getColor() const { - ColorProperty property = getItemValue(P_COLOR).value<ColorProperty>(); - return property.getColor(); + ExternalProperty property = getItemValue(P_COLOR).value<ExternalProperty>(); + return property.color(); } //TODO: make this function create proper type of material (refractive index m-l or wl-indp. mat-l) diff --git a/GUI/coregui/Models/MaterialModel.cpp b/GUI/coregui/Models/MaterialModel.cpp index 0952255cccc9d1447ea466fefcf1657d49b25ce2..daa30a2590bb2cd8b6ca9b4a579f114067d3dac6 100644 --- a/GUI/coregui/Models/MaterialModel.cpp +++ b/GUI/coregui/Models/MaterialModel.cpp @@ -53,8 +53,8 @@ MaterialItem* MaterialModel::addMaterial(const QString& name, double material_da materialDataItem->setReal(material_data_real); materialDataItem->setImag(material_data_imag); - ColorProperty color(MaterialItemUtils::suggestMaterialColor(name)); - materialItem->setItemValue(MaterialItem::P_COLOR, color.getVariant()); + QColor color = MaterialItemUtils::suggestMaterialColor(name); + materialItem->setItemValue(MaterialItem::P_COLOR, MaterialItemUtils::colorProperty(color).variant()); return materialItem; } @@ -70,20 +70,6 @@ MaterialItem* MaterialModel::getMaterial(const QModelIndex& index) return dynamic_cast<MaterialItem*>(itemForIndex(index)); } -MaterialItem* MaterialModel::getMaterial(const ExternalProperty& property) -{ - QModelIndex parentIndex; - for (int i_row = 0; i_row < rowCount(parentIndex); ++i_row) { - QModelIndex itemIndex = index(i_row, 0, parentIndex); - - if (MaterialItem* material = dynamic_cast<MaterialItem*>(itemForIndex(itemIndex))) { - if (material->getIdentifier() == property.getIdentifier()) - return material; - } - } - return nullptr; -} - //! Returns clone of material with given index. MaterialItem* MaterialModel::cloneMaterial(const QModelIndex& index) diff --git a/GUI/coregui/Models/MaterialModel.h b/GUI/coregui/Models/MaterialModel.h index 932faed59b30874c0bcd26556aa8e6ccad874b86..f7b1ed26dde07efc91b6e73c54d02ccb4ebecf42 100644 --- a/GUI/coregui/Models/MaterialModel.h +++ b/GUI/coregui/Models/MaterialModel.h @@ -36,7 +36,6 @@ public: void removeMaterial(MaterialItem*); MaterialItem* getMaterial(const QModelIndex& index); - MaterialItem* getMaterial(const ExternalProperty& property); MaterialItem* cloneMaterial(const QModelIndex& index); diff --git a/GUI/coregui/Models/MaterialPropertyController.cpp b/GUI/coregui/Models/MaterialPropertyController.cpp index 6efbe76b1da1d5c13c712520a6a70aa6a86c01e7..79d856d7e73fe72feb76a53c6e7843de301f542f 100644 --- a/GUI/coregui/Models/MaterialPropertyController.cpp +++ b/GUI/coregui/Models/MaterialPropertyController.cpp @@ -55,12 +55,12 @@ void MaterialPropertyController::onMaterialModelLoad() ExternalProperty property = sampleItem->getItemValue(tag).value<ExternalProperty>(); if (MaterialItem* material - = m_materialModel->materialFromIdentifier(property.getIdentifier())) { + = m_materialModel->materialFromIdentifier(property.identifier())) { ExternalProperty new_property = MaterialItemUtils::materialProperty(*material); - sampleItem->setItemValue(tag, new_property.getVariant()); + sampleItem->setItemValue(tag, new_property.variant()); } else { ExternalProperty undefined; - sampleItem->setItemValue(tag, undefined.getVariant()); + sampleItem->setItemValue(tag, undefined.variant()); } } } @@ -79,9 +79,9 @@ void MaterialPropertyController::onMaterialDataChanged(const QModelIndex& topLef Q_ASSERT(!tag.isEmpty()); ExternalProperty property = sampleItem->getItemValue(tag).value<ExternalProperty>(); - if (property.getIdentifier() == materialItem->getIdentifier()) { + if (property.identifier() == materialItem->getIdentifier()) { ExternalProperty new_property = MaterialItemUtils::materialProperty(*materialItem); - sampleItem->setItemValue(tag, new_property.getVariant()); + sampleItem->setItemValue(tag, new_property.variant()); } } } @@ -110,9 +110,9 @@ void MaterialPropertyController::onMaterialRowsAboutToBeRemoved(const QModelInde Q_ASSERT(!tag.isEmpty()); ExternalProperty property = sampleItem->getItemValue(tag).value<ExternalProperty>(); - if (identifiersToDelete.contains(property.getIdentifier())) { + if (identifiersToDelete.contains(property.identifier())) { ExternalProperty undefined; - sampleItem->setItemValue(tag, undefined.getVariant()); + sampleItem->setItemValue(tag, undefined.variant()); } } } diff --git a/GUI/coregui/Models/MinimizerItem.cpp b/GUI/coregui/Models/MinimizerItem.cpp index 6e312cd35beb7f6409349dd24878da86b0c43cfc..6d9e1fed3d937a20d1356f692ebff3254a497247 100644 --- a/GUI/coregui/Models/MinimizerItem.cpp +++ b/GUI/coregui/Models/MinimizerItem.cpp @@ -57,7 +57,7 @@ const QString MinuitMinimizerItem::P_MAXFUNCTIONCALLS MinuitMinimizerItem::MinuitMinimizerItem() : MinimizerItem(Constants::MinuitMinimizerType) { - addProperty(P_ALGORITHMS, MinimizerItemCatalogue::algorithmCombo(modelType()).getVariant()); + addProperty(P_ALGORITHMS, MinimizerItemCatalogue::algorithmCombo(modelType()).variant()); addProperty(P_STRATEGY, 1) ->setToolTip("Minimization strategy (0-low, 1-medium, 2-high quality)"); @@ -97,7 +97,7 @@ const QString GSLMultiMinimizerItem::P_MAXITERATIONS GSLMultiMinimizerItem::GSLMultiMinimizerItem() : MinimizerItem(Constants::GSLMultiMinimizerType) { - addProperty(P_ALGORITHMS, MinimizerItemCatalogue::algorithmCombo(modelType()).getVariant()); + addProperty(P_ALGORITHMS, MinimizerItemCatalogue::algorithmCombo(modelType()).variant()); addProperty(P_MAXITERATIONS, 0)->setToolTip("Maximum number of iterations"); } diff --git a/GUI/coregui/Models/ColorProperty.h b/GUI/coregui/Models/ObsoleteColorProperty.h similarity index 77% rename from GUI/coregui/Models/ColorProperty.h rename to GUI/coregui/Models/ObsoleteColorProperty.h index c4adfd44b0d40dd9f7230facc18c8ed6aea9d953..52980ec6aba892a693ce92e88fdc448c60ed2fd6 100644 --- a/GUI/coregui/Models/ColorProperty.h +++ b/GUI/coregui/Models/ObsoleteColorProperty.h @@ -2,8 +2,8 @@ // // BornAgain: simulate and fit scattering at grazing incidence // -//! @file GUI/coregui/Models/ColorProperty.h -//! @brief Defines class ColorProperty +//! @file GUI/coregui/Models/ObsoleteColorProperty.h +//! @brief Defines class ObsoleteColorProperty //! //! @homepage http://www.bornagainproject.org //! @license GNU General Public License v3 or higher (see COPYING) @@ -14,8 +14,8 @@ // // ************************************************************************** // -#ifndef COLORPROPERTY_H -#define COLORPROPERTY_H +#ifndef OBSOLETECOLORPROPERTY_H +#define OBSOLETECOLORPROPERTY_H #include "WinDllMacros.h" #include <QPixmap> @@ -25,11 +25,11 @@ //! //! The reason is to have simple color editor in PropertyEditor instead of //! original one which is too sophisticated. -class BA_CORE_API_ ColorProperty +class BA_CORE_API_ ObsoleteColorProperty { public: - ColorProperty() : m_color(Qt::red) {} - ColorProperty(QColor color) : m_color(color) {} + ObsoleteColorProperty() : m_color(Qt::red) {} + ObsoleteColorProperty(QColor color) : m_color(color) {} QPixmap getPixmap() const { QPixmap pixmap(10,10); pixmap.fill(m_color); @@ -53,8 +53,8 @@ private: QColor m_color; }; -Q_DECLARE_METATYPE(ColorProperty) +Q_DECLARE_METATYPE(ObsoleteColorProperty) -#endif // COLORPROPERTY_H +#endif // OBSOLETECOLORPROPERTY_H diff --git a/GUI/coregui/Models/ParticleDistributionItem.cpp b/GUI/coregui/Models/ParticleDistributionItem.cpp index 2afe766b32df4aef277c9e93c2801cbce392e713..d73c6008dc8d0f4990294dd703c8811dc11c3ad5 100644 --- a/GUI/coregui/Models/ParticleDistributionItem.cpp +++ b/GUI/coregui/Models/ParticleDistributionItem.cpp @@ -57,7 +57,7 @@ ParticleDistributionItem::ParticleDistributionItem() setDefaultTag(T_PARTICLES); ComboProperty par_prop; - addProperty(P_DISTRIBUTED_PARAMETER, par_prop.getVariant())->setToolTip( + addProperty(P_DISTRIBUTED_PARAMETER, par_prop.variant())->setToolTip( QStringLiteral("Parameter to distribute")); updateParameterList(); @@ -138,7 +138,7 @@ void ParticleDistributionItem::updateParameterList() // we first set parameter, and then clear the cache name, to not to allow // initDistributionItem to override limits obtained from the domain if(prop != newProp) - setItemValue(P_DISTRIBUTED_PARAMETER, newProp.getVariant()); + setItemValue(P_DISTRIBUTED_PARAMETER, newProp.variant()); if(make_cache_clear) m_domain_cache_name.clear(); diff --git a/GUI/coregui/Models/ParticleItem.cpp b/GUI/coregui/Models/ParticleItem.cpp index 309c515ba8b1ffbc215798081bf359660b790cfe..27c9e4ad262858a4675a863fd904e17eeb832100 100644 --- a/GUI/coregui/Models/ParticleItem.cpp +++ b/GUI/coregui/Models/ParticleItem.cpp @@ -47,8 +47,9 @@ ParticleItem::ParticleItem() : SessionGraphicsItem(Constants::ParticleType) { addGroupProperty(P_FORM_FACTOR, Constants::FormFactorGroup); - addProperty(P_MATERIAL, MaterialItemUtils::defaultMaterialProperty().getVariant()) - ->setToolTip(QStringLiteral("Material of particle")); + addProperty(P_MATERIAL, MaterialItemUtils::defaultMaterialProperty().variant()) + ->setToolTip(QStringLiteral("Material of particle")) + .setEditorType(Constants::MaterialEditorExternalType); addProperty(P_ABUNDANCE, 1.0)->setLimits(RealLimits::limited(0.0, 1.0)).setDecimals(3) .setToolTip(abundance_tooltip); diff --git a/GUI/coregui/Models/ParticleLayoutItem.cpp b/GUI/coregui/Models/ParticleLayoutItem.cpp index c17a199ff668726efd9870a7fecfbb8f35f2d176..706c269a0ab11bf1998a29bef4ea020bf7905453 100644 --- a/GUI/coregui/Models/ParticleLayoutItem.cpp +++ b/GUI/coregui/Models/ParticleLayoutItem.cpp @@ -45,7 +45,7 @@ ParticleLayoutItem::ParticleLayoutItem() : SessionGraphicsItem(Constants::Partic setToolTip(QStringLiteral("A layout of particles")); ComboProperty approx = ComboProperty() << Constants::LAYOUT_DA << Constants::LAYOUT_SSCA; - addProperty(P_APPROX, approx.getVariant())->setToolTip( + addProperty(P_APPROX, approx.variant())->setToolTip( QStringLiteral("Approximation used to distribute the particles")); addProperty(P_TOTAL_DENSITY, 1.0)->setToolTip(density_tooltip); getItem(P_TOTAL_DENSITY)->setDecimals(10); diff --git a/GUI/coregui/Models/RealDataItem.cpp b/GUI/coregui/Models/RealDataItem.cpp index a6fc9ae4c0942f57f88dcd62df2695fa172db129..5cef412988970d5fa6cc6f4482e6d8ee22832354 100644 --- a/GUI/coregui/Models/RealDataItem.cpp +++ b/GUI/coregui/Models/RealDataItem.cpp @@ -130,7 +130,7 @@ void RealDataItem::updateToInstrument() if(m_linkedInstrument == 0) { ComboProperty combo = ComboProperty() << Constants::UnitsNbins; - item->setItemValue(IntensityDataItem::P_AXES_UNITS, combo.getVariant()); + item->setItemValue(IntensityDataItem::P_AXES_UNITS, combo.variant()); item->getItem(IntensityDataItem::P_AXES_UNITS)->setVisible(true); item->setXaxisTitle("X [nbins]"); item->setYaxisTitle("Y [nbins]"); diff --git a/GUI/coregui/Models/RectangularDetectorItem.cpp b/GUI/coregui/Models/RectangularDetectorItem.cpp index 0b5a7882e0cdcda9105374e40d5d3d1093232995..bbf88a91277e25a64e0aefd2ae9c58454cc7297f 100644 --- a/GUI/coregui/Models/RectangularDetectorItem.cpp +++ b/GUI/coregui/Models/RectangularDetectorItem.cpp @@ -89,7 +89,7 @@ RectangularDetectorItem::RectangularDetectorItem() item->getItem(BasicAxisItem::P_MAX)->setToolTip(QStringLiteral("Height of the detector in mm")); // alignment selector - addProperty(P_ALIGNMENT, alignmentCombo().getVariant()); + addProperty(P_ALIGNMENT, alignmentCombo().variant()); // alignment parameters item = addGroupProperty(P_NORMAL, Constants::VectorType); @@ -133,7 +133,7 @@ void RectangularDetectorItem::setDetectorAlignment(const QString& alignment) "RectangularDetectorItem::setDetectorAlignment -> Unexpected alignment"); combo_property.setValue(alignment); - setItemValue(RectangularDetectorItem::P_ALIGNMENT, combo_property.getVariant()); + setItemValue(RectangularDetectorItem::P_ALIGNMENT, combo_property.variant()); } void RectangularDetectorItem::setSize(int nx, int ny) diff --git a/GUI/coregui/Models/SessionItemUtils.cpp b/GUI/coregui/Models/SessionItemUtils.cpp index 8a3c7fa1862b3b8fcdca35bcbbd2a900a5fe22f9..581b049c85466e9d81b3c5d4fe8debb38bae4c36 100644 --- a/GUI/coregui/Models/SessionItemUtils.cpp +++ b/GUI/coregui/Models/SessionItemUtils.cpp @@ -18,7 +18,6 @@ #include "SessionItem.h" #include "VectorItem.h" #include "MaterialItem.h" -#include "ColorProperty.h" #include "ExternalProperty.h" #include <QColor> #include <QIcon> @@ -88,10 +87,7 @@ QVariant SessionItemUtils::ToolTipRole(const SessionItem& item, int ncol) QVariant SessionItemUtils::DecorationRole(const SessionItem& item) { if (item.value().canConvert<ExternalProperty>()) - return QIcon(item.value().value<ExternalProperty>().getPixmap()); - - if (item.value().canConvert<ColorProperty>()) - return QIcon(item.value().value<ColorProperty>().getPixmap()); + return QIcon(item.value().value<ExternalProperty>().pixmap()); return QVariant(); } diff --git a/GUI/coregui/Models/SessionXML.cpp b/GUI/coregui/Models/SessionXML.cpp index c7e51b63926cf2c802e041ad4b9abb534a54940c..0e582da0091d45b65bf078f0078018594c828dc6 100644 --- a/GUI/coregui/Models/SessionXML.cpp +++ b/GUI/coregui/Models/SessionXML.cpp @@ -14,7 +14,7 @@ // // ************************************************************************** // -#include "ColorProperty.h" +#include "ObsoleteColorProperty.h" #include "ComboProperty.h" #include "GUIHelpers.h" #include "GroupItem.h" @@ -100,12 +100,12 @@ void SessionWriter::writeVariant(QXmlStreamWriter *writer, QVariant variant, int } else if (type_name == Constants::ExternalPropertyType) { - ExternalProperty material_property = variant.value<ExternalProperty>(); - writer->writeAttribute(SessionXML::ParameterValueAttribute, - material_property.getName()); - writer->writeAttribute(SessionXML::IdentifierAttribute, - material_property.getIdentifier()); + ExternalProperty prop = variant.value<ExternalProperty>(); + writer->writeAttribute(SessionXML::ExternalPropertyTextAtt, prop.text()); + QString tcol = prop.color().isValid() ? prop.color().name(QColor::HexArgb) : ""; + writer->writeAttribute(SessionXML::ExternalPropertyColorAtt, tcol); + writer->writeAttribute(SessionXML::ExternalPropertyIdentifierAtt, prop.identifier()); } else if (type_name == Constants::ComboPropertyType) { @@ -122,16 +122,7 @@ void SessionWriter::writeVariant(QXmlStreamWriter *writer, QVariant variant, int writer->writeAttribute(SessionXML::ParameterValueAttribute, ff_name); } - else if (type_name == Constants::ColorPropertyType) { - int r, g, b, a; - QColor material_color = variant.value<ColorProperty>().getColor(); - material_color.getRgb(&r, &g, &b, &a); - writer->writeAttribute(SessionXML::ColorRedAttribute, QString::number(r)); - writer->writeAttribute(SessionXML::ColorGreenAttribute, QString::number(g)); - writer->writeAttribute(SessionXML::ColorBlueAttribute, QString::number(b)); - writer->writeAttribute(SessionXML::ColorAlphaAttribute, QString::number(a)); - - } else { + else { throw GUIHelpers::Error("SessionModel::writeProperty: Parameter type not supported " + type_name); } @@ -278,10 +269,15 @@ QString SessionReader::readProperty(QXmlStreamReader *reader, } else if (parameter_type == Constants::ExternalPropertyType) { - QString identifier = reader->attributes().value(SessionXML::IdentifierAttribute).toString(); - - ExternalProperty material_property(identifier); - variant = material_property.getVariant(); + QString text = reader->attributes().value(SessionXML::ExternalPropertyTextAtt).toString(); + QString colorName = reader->attributes().value(SessionXML::ExternalPropertyColorAtt).toString(); + QString identifier = reader->attributes().value(SessionXML::ExternalPropertyIdentifierAtt).toString(); + + ExternalProperty property; + property.setText(text); + property.setColor(QColor(colorName)); + property.setIdentifier(identifier); + variant = property.variant(); } else if (parameter_type == Constants::ComboPropertyType) { @@ -294,7 +290,7 @@ QString SessionReader::readProperty(QXmlStreamReader *reader, combo_property.setStringOfValues(parameterExt); combo_property.setCurrentIndex(parameter_value); - variant = combo_property.getVariant(); + variant = combo_property.variant(); } else if (parameter_type == Constants::GroupPropertyType) { @@ -312,15 +308,6 @@ QString SessionReader::readProperty(QXmlStreamReader *reader, } } - else if (parameter_type == Constants::ColorPropertyType) { - int r = reader->attributes().value(SessionXML::ColorRedAttribute).toInt(); - int g = reader->attributes().value(SessionXML::ColorGreenAttribute).toInt(); - int b = reader->attributes().value(SessionXML::ColorBlueAttribute).toInt(); - int a = reader->attributes().value(SessionXML::ColorAlphaAttribute).toInt(); - ColorProperty color(QColor(r, g, b, a)); - variant = color.getVariant(); - } - else { throw GUIHelpers::Error("SessionModel::readProperty: " "Parameter type not supported" + parameter_type); diff --git a/GUI/coregui/Models/SessionXML.h b/GUI/coregui/Models/SessionXML.h index 455fb216186477aa5223ce402e2ae13e8daed433..8f6cf13d456debf075fd0c4ac14d8e5e4fb3f556 100644 --- a/GUI/coregui/Models/SessionXML.h +++ b/GUI/coregui/Models/SessionXML.h @@ -52,14 +52,9 @@ const QString ParameterValueAttribute("ParValue"); const QString ParameterRoleAttribute("ParRole"); const QString ParameterExtAttribute("ParExt"); -const QString IdentifierAttribute("Identifier"); - -const QString ColorRedAttribute("Red"); -const QString ColorGreenAttribute("Green"); -const QString ColorBlueAttribute("Blue"); -const QString ColorAlphaAttribute("Alpha"); - -const QString AngleUnitsAttribute("Units"); +const QString ExternalPropertyTextAtt("Text"); +const QString ExternalPropertyColorAtt("Color"); +const QString ExternalPropertyIdentifierAtt("Identifier"); } diff --git a/GUI/coregui/Models/SimulationOptionsItem.cpp b/GUI/coregui/Models/SimulationOptionsItem.cpp index 6e8b13dc8c134586069099f50ab84eeecd52dcc1..bdad10fd29b8a3e8e7529e2589ed308c4b865c25 100644 --- a/GUI/coregui/Models/SimulationOptionsItem.cpp +++ b/GUI/coregui/Models/SimulationOptionsItem.cpp @@ -61,28 +61,28 @@ SimulationOptionsItem::SimulationOptionsItem() << Constants::JOB_RUN_IN_BACKGROUND << Constants::JOB_RUN_SUBMIT_ONLY; policy.setToolTips(getRunPolicyTooltips()); - addProperty(P_RUN_POLICY, policy.getVariant())->setToolTip(tooltip_runpolicy); + addProperty(P_RUN_POLICY, policy.variant())->setToolTip(tooltip_runpolicy); ComboProperty nthreads; nthreads << getCPUUsageOptions(); - addProperty(P_NTHREADS, nthreads.getVariant())->setToolTip(tooltip_nthreads); + addProperty(P_NTHREADS, nthreads.variant())->setToolTip(tooltip_nthreads); ComboProperty computationMethod; computationMethod << Constants::SIMULATION_ANALYTICAL << Constants::SIMULATION_MONTECARLO; addProperty(P_COMPUTATION_METHOD, - computationMethod.getVariant())->setToolTip(tooltip_computation); + computationMethod.variant())->setToolTip(tooltip_computation); addProperty(P_MC_POINTS, 100)->setEnabled(false); ComboProperty averageLayerMaterials; averageLayerMaterials <<Constants::AMBIENT_LAYER_MATERIAL << Constants::AVERAGE_LAYER_MATERIAL; addProperty(P_FRESNEL_MATERIAL_METHOD, - averageLayerMaterials.getVariant())->setToolTip(tooltip_ambientmaterial); + averageLayerMaterials.variant())->setToolTip(tooltip_ambientmaterial); ComboProperty includeSpecularPeak; includeSpecularPeak << Constants::No << Constants::Yes; addProperty(P_INCLUDE_SPECULAR_PEAK, - includeSpecularPeak.getVariant())->setToolTip(tooltip_specularpeak); + includeSpecularPeak.variant())->setToolTip(tooltip_specularpeak); mapper()->setOnPropertyChange( [this](const QString &name) { @@ -122,14 +122,14 @@ void SimulationOptionsItem::setRunPolicy(const QString &policy) { ComboProperty combo = getItemValue(P_RUN_POLICY).value<ComboProperty>(); combo.setValue(policy); - setItemValue(P_RUN_POLICY, combo.getVariant()); + setItemValue(P_RUN_POLICY, combo.variant()); } void SimulationOptionsItem::setComputationMethod(const QString &name) { ComboProperty combo = getItemValue(P_COMPUTATION_METHOD).value<ComboProperty>(); combo.setValue(name); - setItemValue(P_COMPUTATION_METHOD, combo.getVariant()); + setItemValue(P_COMPUTATION_METHOD, combo.variant()); } QString SimulationOptionsItem::getComputationMethod() const @@ -152,7 +152,7 @@ void SimulationOptionsItem::setFresnelMaterialMethod(const QString& name) { ComboProperty combo = getItemValue(P_FRESNEL_MATERIAL_METHOD).value<ComboProperty>(); combo.setValue(name); - setItemValue(P_FRESNEL_MATERIAL_METHOD, combo.getVariant()); + setItemValue(P_FRESNEL_MATERIAL_METHOD, combo.variant()); } QString SimulationOptionsItem::getFresnelMaterialMethod() const @@ -165,7 +165,7 @@ void SimulationOptionsItem::setIncludeSpecularPeak(const QString& name) { ComboProperty combo = getItemValue(P_INCLUDE_SPECULAR_PEAK).value<ComboProperty>(); combo.setValue(name); - setItemValue(P_INCLUDE_SPECULAR_PEAK, combo.getVariant()); + setItemValue(P_INCLUDE_SPECULAR_PEAK, combo.variant()); } QString SimulationOptionsItem::getIncludeSpecularPeak() const diff --git a/GUI/coregui/Models/TransformToDomain.cpp b/GUI/coregui/Models/TransformToDomain.cpp index f94456537df367fae2a066cc5a8db2e40cdfab9f..5a44f6f19d8c80a258c2bf7be8608a722732fd00 100644 --- a/GUI/coregui/Models/TransformToDomain.cpp +++ b/GUI/coregui/Models/TransformToDomain.cpp @@ -60,20 +60,9 @@ using SessionItemUtils::GetVectorItem; std::unique_ptr<Material> TransformToDomain::createDomainMaterial(const SessionItem& item) { - ExternalProperty material_property; - if (item.modelType() == Constants::ParticleType) { - material_property - = item.getItemValue(ParticleItem::P_MATERIAL).value<ExternalProperty>(); - } else if (item.modelType() == Constants::LayerType) { - material_property - = item.getItemValue(LayerItem::P_MATERIAL).value<ExternalProperty>(); - } - if (!material_property.isDefined()) - throw GUIHelpers::Error( - "TransformToDomain::createDomainMaterial() -> Error. Can't create material " - "for item '"+item.displayName()+"'."); - - return MaterialItemUtils::createDomainMaterial(material_property); + QString tag = MaterialItemUtils::materialTag(item); + ExternalProperty property = item.getItemValue(tag).value<ExternalProperty>(); + return MaterialItemUtils::createDomainMaterial(property); } std::unique_ptr<MultiLayer> TransformToDomain::createMultiLayer(const SessionItem& item) diff --git a/GUI/coregui/Models/item_constants.h b/GUI/coregui/Models/item_constants.h index 08a74a099ec0856d0a7a2520a15b3bcdbef7a54d..1ad245db42e9ff34f1780325acbc172ada07eb0d 100644 --- a/GUI/coregui/Models/item_constants.h +++ b/GUI/coregui/Models/item_constants.h @@ -270,12 +270,13 @@ const QString MaskEditorPresentation = "Mask Editor"; const ModelType ExternalPropertyType = "ExternalProperty"; const ModelType ComboPropertyType = "ComboProperty"; -const ModelType ColorPropertyType = "ColorProperty"; const ModelType GroupPropertyType = "GroupProperty_t"; // --- Custom editors for variant propertues --- const ModelType DefaultEditorType = "Default"; const ModelType ScientificEditorType = "SceintificDouble"; +const ModelType MaterialEditorExternalType = "ExtMaterialEditor"; +const ModelType ColorEditorExternalType = "ExtColorEditor"; } #endif // ITEM_CONSTANTS_H diff --git a/GUI/coregui/Views/IntensityDataWidgets/IntensityDataCanvas.cpp b/GUI/coregui/Views/IntensityDataWidgets/IntensityDataCanvas.cpp index a3b072abc5ea6b8ee27cf8e96d749619557293b9..4696eafecda78f8f5705e80632f4ee9e7e816e9b 100644 --- a/GUI/coregui/Views/IntensityDataWidgets/IntensityDataCanvas.cpp +++ b/GUI/coregui/Views/IntensityDataWidgets/IntensityDataCanvas.cpp @@ -157,7 +157,7 @@ void IntensityDataCanvas::applyPersistentSettings() QString persistentGradient = settings.value(gradient_setting_name()).toString(); if (combo.getValue() != persistentGradient) { combo.setValue(settings.value(gradient_setting_name()).toString()); - intensityDataItem()->setItemValue(IntensityDataItem::P_GRADIENT, combo.getVariant()); + intensityDataItem()->setItemValue(IntensityDataItem::P_GRADIENT, combo.variant()); } } diff --git a/GUI/coregui/Views/MaterialEditor/ExternalProperty.cpp b/GUI/coregui/Views/MaterialEditor/ExternalProperty.cpp index f8348d58b1ea5edc0eb8d6f04f01282344f93812..e7710e0c9835ab3ee75785a7608b140c08b93447 100644 --- a/GUI/coregui/Views/MaterialEditor/ExternalProperty.cpp +++ b/GUI/coregui/Views/MaterialEditor/ExternalProperty.cpp @@ -18,24 +18,21 @@ #include "MaterialItem.h" #include "MaterialModel.h" -ExternalProperty::ExternalProperty(const QString& identifier) - : m_identifier(identifier) - , m_name("Undefined") - , m_color(Qt::red) +ExternalProperty::ExternalProperty() {} -QString ExternalProperty::getName() const +QString ExternalProperty::text() const { - return m_name; + return m_text; } -void ExternalProperty::setName(const QString& name) +void ExternalProperty::setText(const QString& name) { - m_name = name; + m_text = name; } -QColor ExternalProperty::getColor() const +QColor ExternalProperty::color() const { return m_color; } @@ -45,15 +42,58 @@ void ExternalProperty::setColor(const QColor& color) m_color = color; } +QString ExternalProperty::identifier() const { + return m_identifier; +} -QPixmap ExternalProperty::getPixmap() const +void ExternalProperty::setIdentifier(const QString& identifier) +{ + m_identifier = identifier; +} + +QPixmap ExternalProperty::pixmap() const { QPixmap pixmap(10,10); - pixmap.fill(getColor()); + pixmap.fill(color()); return pixmap; } -bool ExternalProperty::isDefined() const +//! Returns true if property is in valid state (i.e. have at least one member defined). + +bool ExternalProperty::isValid() const +{ + if (m_identifier.isEmpty() && m_text.isEmpty() && !m_color.isValid()) + return false; + + return true; +} + +QVariant ExternalProperty::variant() const +{ + QVariant variant; + variant.setValue(*this); + return variant; +} + +bool ExternalProperty::operator==(const ExternalProperty& other) const +{ + if (m_identifier != other.m_identifier) + return false; + if (m_text != other.m_text) + return false; + if (m_color != other.m_color) + return false; + + return true; +} + +bool ExternalProperty::operator!=(const ExternalProperty& other) const { - return !m_identifier.isEmpty(); + return !(*this == other); } + +bool ExternalProperty::operator<(const ExternalProperty& other) const +{ + return m_identifier < other.m_identifier && m_text < other.m_text; +} + diff --git a/GUI/coregui/Views/MaterialEditor/ExternalProperty.h b/GUI/coregui/Views/MaterialEditor/ExternalProperty.h index 6b09bf9e3a3cebfe393d0cfbd44aa9e6ae69190f..bc89186ee603277c86118ddf957a25280e1da8e4 100644 --- a/GUI/coregui/Views/MaterialEditor/ExternalProperty.h +++ b/GUI/coregui/Views/MaterialEditor/ExternalProperty.h @@ -24,38 +24,37 @@ #include <QString> #include <QVariant> -//! The MaterialProperty class defines unique identifier to help LayerItem, ParticleItem etc -//! to access materials from MaterialEditor; +//! The ExternalProperty class defines custom QVariant property to carry the text, color and +//! an identifier. + class BA_CORE_API_ ExternalProperty { public: - explicit ExternalProperty(const QString &identifier=QString()); + explicit ExternalProperty(); - QString getIdentifier() const { - return m_identifier; - } + QString text() const; + void setText(const QString& name); - QVariant getVariant() const - { - QVariant variant; - variant.setValue(*this); - return variant; - } + QColor color() const; + void setColor(const QColor& color); - QString getName() const; - void setName(const QString& name); + QString identifier() const; + void setIdentifier(const QString& identifier); - QColor getColor() const; - void setColor(const QColor& color); + QPixmap pixmap() const; - QPixmap getPixmap() const; + bool isValid() const; - bool isDefined() const; + QVariant variant() const; + + bool operator==(const ExternalProperty& other) const; + bool operator!=(const ExternalProperty& other) const; + bool operator<(const ExternalProperty& other) const; private: - QString m_identifier; - QString m_name; + QString m_text; QColor m_color; + QString m_identifier; }; Q_DECLARE_METATYPE(ExternalProperty) diff --git a/GUI/coregui/Views/MaterialEditor/MaterialEditor.cpp b/GUI/coregui/Views/MaterialEditor/MaterialEditor.cpp index 52c09865cb44cd7186c27fccd8189f9baafc7cc8..699a3143268bc3f5d4718638bc621580bff68546 100644 --- a/GUI/coregui/Views/MaterialEditor/MaterialEditor.cpp +++ b/GUI/coregui/Views/MaterialEditor/MaterialEditor.cpp @@ -20,6 +20,7 @@ #include "MaterialItem.h" #include "MaterialModel.h" #include "SessionDecorationModel.h" +#include "ExternalProperty.h" #include <QListView> #include <QSplitter> #include <QVBoxLayout> @@ -69,9 +70,10 @@ MaterialItem* MaterialEditor::selectedMaterial() //! Sets selection corresponding to initial material property void MaterialEditor::setInitialMaterialProperty(const ExternalProperty& matProperty) { - if (MaterialItem* mat = m_materialModel->getMaterial(matProperty)) { + if (MaterialItem* mat = m_materialModel->materialFromIdentifier(matProperty.identifier())) { selectionModel()->clearSelection(); - selectionModel()->select(m_materialModel->indexOfItem(mat), QItemSelectionModel::Select); + selectionModel()->setCurrentIndex(m_materialModel->indexOfItem(mat), QItemSelectionModel::ClearAndSelect); + selectionModel()->select(m_materialModel->indexOfItem(mat), QItemSelectionModel::ClearAndSelect); } } diff --git a/GUI/coregui/Views/MaterialEditor/MaterialItemUtils.cpp b/GUI/coregui/Views/MaterialEditor/MaterialItemUtils.cpp index b5089d8ca5cf05aaea24d99ab98fc7a395065db0..6b4cfa95ed5f43044e38525ee461845c1feb6e9e 100644 --- a/GUI/coregui/Views/MaterialEditor/MaterialItemUtils.cpp +++ b/GUI/coregui/Views/MaterialEditor/MaterialItemUtils.cpp @@ -26,6 +26,7 @@ #include "MaterialEditorDialog.h" #include "AppSvc.h" #include "MaterialItem.h" +#include <QColorDialog> QColor MaterialItemUtils::suggestMaterialColor(const QString &name) @@ -63,11 +64,11 @@ std::unique_ptr<Material> MaterialItemUtils::createDomainMaterial(const ExternalProperty &material_property) { MaterialItem *materialItem - = AppSvc::materialModel()->materialFromIdentifier(material_property.getIdentifier()); + = AppSvc::materialModel()->materialFromIdentifier(material_property.identifier()); if(!materialItem) throw GUIHelpers::Error("MaterialUtils::createDomainMaterial() -> Error. Can't create " - "material with name '"+material_property.getName()+"'."); + "material with name '"+material_property.text()+"'."); return materialItem->createMaterial(); } @@ -92,22 +93,33 @@ QStringList MaterialItemUtils::materialRelatedModelTypes() return {Constants::ParticleType, Constants::LayerType}; } +//! Constructs material property for given material. ExternalProperty MaterialItemUtils::materialProperty(const SessionItem& materialItem) { - ExternalProperty result(materialItem.getItemValue(MaterialItem::P_IDENTIFIER).toString()); + ExternalProperty result; - ColorProperty colorProperty = materialItem.getItemValue(MaterialItem::P_COLOR).value<ColorProperty>(); - result.setColor(colorProperty.getColor()); - result.setName(materialItem.itemName()); + ExternalProperty colorProperty = materialItem.getItemValue(MaterialItem::P_COLOR).value<ExternalProperty>(); + result.setIdentifier(materialItem.getItemValue(MaterialItem::P_IDENTIFIER).toString()); + result.setColor(colorProperty.color()); + result.setText(materialItem.itemName()); return result; } -ExternalProperty MaterialItemUtils::selectMaterialProperty(const ExternalProperty& previousMaterial) +ExternalProperty MaterialItemUtils::colorProperty(const QColor& color) +{ + ExternalProperty result; + result.setColor(color); + result.setText(QString("[%1, %2, %3] (%4)") + .arg(color.red()).arg(color.green()).arg(color.blue()).arg(color.alpha())); + return result; +} + +ExternalProperty MaterialItemUtils::selectMaterialProperty(const ExternalProperty& previous) { MaterialEditorDialog dialog(AppSvc::materialModel()); - dialog.setMaterialProperty(previousMaterial); + dialog.setMaterialProperty(previous); if(dialog.exec() == QDialog::Accepted) { return dialog.selectedMaterialProperty(); } @@ -115,3 +127,16 @@ ExternalProperty MaterialItemUtils::selectMaterialProperty(const ExternalPropert return ExternalProperty(); } + +ExternalProperty MaterialItemUtils::selectColorProperty(const ExternalProperty& previous) +{ + ExternalProperty result; + + bool ok = false; + QRgb oldRgba = previous.color().rgba(); + QRgb newRgba = QColorDialog::getRgba(oldRgba, &ok, nullptr); + if (ok && newRgba != oldRgba) + result = MaterialItemUtils::colorProperty(QColor::fromRgba(newRgba)); + + return result; +} diff --git a/GUI/coregui/Views/MaterialEditor/MaterialItemUtils.h b/GUI/coregui/Views/MaterialEditor/MaterialItemUtils.h index ca05f7ac8d2c46fc254570953f4a16d430be8bcb..e083455f644489d109fa9ddd8ca98f11a7e50963 100644 --- a/GUI/coregui/Views/MaterialEditor/MaterialItemUtils.h +++ b/GUI/coregui/Views/MaterialEditor/MaterialItemUtils.h @@ -17,7 +17,7 @@ #ifndef MATERIALITEMUTILS_H #define MATERIALITEMUTILS_H -#include "ColorProperty.h" +#include "ObsoleteColorProperty.h" #include "MaterialItem.h" #include "ExternalProperty.h" #include <QColor> @@ -40,8 +40,14 @@ BA_CORE_API_ QStringList materialRelatedModelTypes(); //! Constructs material property corresponding to given material. BA_CORE_API_ ExternalProperty materialProperty(const SessionItem& materialItem); +//! Constructs color property from given color. +BA_CORE_API_ ExternalProperty colorProperty(const QColor& color); + //! Calls material selector dialog. -BA_CORE_API_ ExternalProperty selectMaterialProperty(const ExternalProperty &previousMaterial=ExternalProperty()); +BA_CORE_API_ ExternalProperty selectMaterialProperty(const ExternalProperty &previous=ExternalProperty()); + +//! Calls color selector dialog. +BA_CORE_API_ ExternalProperty selectColorProperty(const ExternalProperty &previous=ExternalProperty()); } diff --git a/GUI/coregui/Views/PropertyEditor/CustomEditors.cpp b/GUI/coregui/Views/PropertyEditor/CustomEditors.cpp index 14e73e3612e66b6f4aadce6b485b87c6fd95577e..6ca6d61ec9691d187c01eb6b824e48aa565f33ce 100644 --- a/GUI/coregui/Views/PropertyEditor/CustomEditors.cpp +++ b/GUI/coregui/Views/PropertyEditor/CustomEditors.cpp @@ -19,8 +19,9 @@ #include "ExternalProperty.h" #include "GroupProperty.h" #include "ComboProperty.h" -#include "ColorProperty.h" +#include "ObsoleteColorProperty.h" #include "MaterialItemUtils.h" +#include "GUIHelpers.h" #include <QBoxLayout> #include <QLabel> #include <QToolButton> @@ -56,6 +57,7 @@ ExternalPropertyEditor::ExternalPropertyEditor(QWidget* parent) , m_textLabel(new QLabel) , m_pixmapLabel(new QLabel) , m_focusFilter(new LostFocusFilter(this)) + , m_extDialogType(Constants::MaterialEditorExternalType) { setMouseTracking(true); setAutoFillBackground(true); @@ -64,8 +66,8 @@ ExternalPropertyEditor::ExternalPropertyEditor(QWidget* parent) layout->setContentsMargins(4, 0, 0, 0); ExternalProperty defProperty; // to get label and pixmap of undefined material - m_textLabel->setText(defProperty.getName()); - m_pixmapLabel->setPixmap(defProperty.getPixmap()); + m_textLabel->setText(defProperty.text()); + m_pixmapLabel->setPixmap(defProperty.pixmap()); auto button = new QToolButton; button->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred)); @@ -82,79 +84,38 @@ ExternalPropertyEditor::ExternalPropertyEditor(QWidget* parent) setLayout(layout); } +void ExternalPropertyEditor::setExternalDialogType(const QString& editorType) +{ + m_extDialogType = editorType; +} + void ExternalPropertyEditor::buttonClicked() { // temporarily installing filter to prevent loss of focus caused by too insistent dialog installEventFilter(m_focusFilter); - ExternalProperty materialProperty = m_data.value<ExternalProperty>(); - ExternalProperty mat = MaterialItemUtils::selectMaterialProperty(materialProperty); + ExternalProperty property = m_data.value<ExternalProperty>(); + + ExternalProperty newProperty; + if (m_extDialogType == Constants::MaterialEditorExternalType) { + newProperty = MaterialItemUtils::selectMaterialProperty(property); + } else if(m_extDialogType == Constants::ColorEditorExternalType) { + newProperty = MaterialItemUtils::selectColorProperty(property); + } else { + throw GUIHelpers::Error("ExternalPropertyEditor::buttonClicked() -> Unexpected dialog"); + } + removeEventFilter(m_focusFilter); - if(mat.isDefined() ) - setDataIntern(mat.getVariant()); + if (newProperty.isValid() && newProperty != property) + setDataIntern(newProperty.variant()); } void ExternalPropertyEditor::initEditor() { Q_ASSERT(m_data.canConvert<ExternalProperty>()); ExternalProperty materialProperty = m_data.value<ExternalProperty>(); - m_textLabel->setText(materialProperty.getName()); - m_pixmapLabel->setPixmap(materialProperty.getPixmap()); -} - -// --- ColorPropertyEditor --- - -ColorPropertyEditor::ColorPropertyEditor(QWidget* parent) - : CustomEditor(parent) - , m_textLabel(new QLabel) - , m_pixmapLabel(new QLabel) - , m_focusFilter(new LostFocusFilter(this)) -{ - setMouseTracking(true); - setAutoFillBackground(true); - - auto layout = new QHBoxLayout; - layout->setContentsMargins(4, 0, 0, 0); - - ColorProperty defProperty; // to get label and pixmap of undefined material - m_textLabel->setText(defProperty.getText()); - m_pixmapLabel->setPixmap(defProperty.getPixmap()); - - auto button = new QToolButton; - button->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred)); - button->setText(QLatin1String(" . . . ")); - button->setToolTip("Color selector"); - layout->addWidget(m_pixmapLabel); - layout->addWidget(m_textLabel); - layout->addStretch(1); - layout->addWidget(button); - setFocusPolicy(Qt::StrongFocus); - setAttribute(Qt::WA_InputMethodEnabled); - connect(button, &QToolButton::clicked, this, &ColorPropertyEditor::buttonClicked); - - setLayout(layout); -} - -void ColorPropertyEditor::buttonClicked() -{ - ColorProperty colorProperty = m_data.value<ColorProperty>(); - - bool ok = false; - QRgb oldRgba = colorProperty.getColor().rgba(); - QRgb newRgba = QColorDialog::getRgba(oldRgba, &ok, this); - if (ok && newRgba != oldRgba) { - colorProperty.setColor(QColor::fromRgba(newRgba)); - m_pixmapLabel->setPixmap(colorProperty.getPixmap()); - setDataIntern(colorProperty.getVariant()); - } -} - -void ColorPropertyEditor::initEditor() -{ - Q_ASSERT(m_data.canConvert<ColorProperty>()); - ColorProperty colorProperty = m_data.value<ColorProperty>(); - m_textLabel->setText(colorProperty.getText()); - m_pixmapLabel->setPixmap(colorProperty.getPixmap()); + m_textLabel->setText(materialProperty.text()); + m_pixmapLabel->setPixmap(materialProperty.pixmap()); } // --- CustomComboEditor --- diff --git a/GUI/coregui/Views/PropertyEditor/CustomEditors.h b/GUI/coregui/Views/PropertyEditor/CustomEditors.h index 13b5cea6d8abf4c6a5c207e34d5b98e73d77b18a..ff800133fdf2fb772be3c718b9d0618f6413cc87 100644 --- a/GUI/coregui/Views/PropertyEditor/CustomEditors.h +++ b/GUI/coregui/Views/PropertyEditor/CustomEditors.h @@ -56,25 +56,7 @@ class BA_CORE_API_ ExternalPropertyEditor : public CustomEditor public: explicit ExternalPropertyEditor(QWidget* parent = nullptr); -private slots: - void buttonClicked(); - -protected: - void initEditor(); - -private: - QLabel* m_textLabel; - QLabel* m_pixmapLabel; - LostFocusFilter* m_focusFilter; -}; - -//! Editor for ColorProperty variant. - -class BA_CORE_API_ ColorPropertyEditor : public CustomEditor -{ - Q_OBJECT -public: - explicit ColorPropertyEditor(QWidget* parent = nullptr); + void setExternalDialogType(const QString& dialogType); private slots: void buttonClicked(); @@ -86,6 +68,7 @@ private: QLabel* m_textLabel; QLabel* m_pixmapLabel; LostFocusFilter* m_focusFilter; + QString m_extDialogType; //!< Type of the dialog which will be created on button click }; //! Common editor for QComboBox-like custom editors. diff --git a/GUI/coregui/Views/PropertyEditor/ObsoletePropertyBrowserUtils.cpp b/GUI/coregui/Views/PropertyEditor/ObsoletePropertyBrowserUtils.cpp index c35bcadd32e7204e369db31d93db0d0a738e0b23..b9a8698da19d17044e775952e166ecc4111fac4f 100644 --- a/GUI/coregui/Views/PropertyEditor/ObsoletePropertyBrowserUtils.cpp +++ b/GUI/coregui/Views/PropertyEditor/ObsoletePropertyBrowserUtils.cpp @@ -46,10 +46,10 @@ ObsoleteMaterialPropertyEdit::ObsoleteMaterialPropertyEdit(QWidget *parent) layout->setSpacing(0); m_textLabel = new QLabel; - m_textLabel->setText(m_materialProperty.getName()); + m_textLabel->setText(m_materialProperty.text()); m_pixmapLabel = new QLabel; - m_pixmapLabel->setPixmap(m_materialProperty.getPixmap()); + m_pixmapLabel->setPixmap(m_materialProperty.pixmap()); QToolButton *button = new QToolButton; button->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, @@ -73,7 +73,7 @@ void ObsoleteMaterialPropertyEdit::buttonClicked() ExternalProperty mat = MaterialItemUtils::selectMaterialProperty(m_materialProperty); removeEventFilter(m_focusFilter); - if(mat.isDefined() ) { + if(mat.isValid() ) { setMaterialProperty(mat); emit materialPropertyChanged(m_materialProperty); } @@ -84,8 +84,8 @@ void ObsoleteMaterialPropertyEdit::setMaterialProperty( const ExternalProperty &materialProperty) { m_materialProperty = materialProperty; - m_textLabel->setText(m_materialProperty.getName()); - m_pixmapLabel->setPixmap(m_materialProperty.getPixmap()); + m_textLabel->setText(m_materialProperty.text()); + m_pixmapLabel->setPixmap(m_materialProperty.pixmap()); } @@ -229,7 +229,7 @@ void ObsoleteColorPropertyEdit::buttonClicked() } void ObsoleteColorPropertyEdit::setColorProperty( - const ColorProperty &colorProperty) + const ObsoleteColorProperty &colorProperty) { m_colorProperty = colorProperty; m_textLabel->setText(colorValueText(m_colorProperty.getColor())); diff --git a/GUI/coregui/Views/PropertyEditor/ObsoletePropertyBrowserUtils.h b/GUI/coregui/Views/PropertyEditor/ObsoletePropertyBrowserUtils.h index 98563dc7c04851f0c66d8b879b3f6c18fd83a67b..970d8a24ed84707fe52bc1b939017d1e8fc6e419 100644 --- a/GUI/coregui/Views/PropertyEditor/ObsoletePropertyBrowserUtils.h +++ b/GUI/coregui/Views/PropertyEditor/ObsoletePropertyBrowserUtils.h @@ -19,7 +19,7 @@ #include <QWidget> #include "ExternalProperty.h" -#include "ColorProperty.h" +#include "ObsoleteColorProperty.h" #include "ObsoleteScientificDoubleProperty.h" #include "GroupProperty.h" #include "ComboProperty.h" @@ -99,20 +99,20 @@ class BA_CORE_API_ ObsoleteColorPropertyEdit : public QWidget public: ObsoleteColorPropertyEdit(QWidget *parent = 0); - void setColorProperty(const ColorProperty &colorProperty); - ColorProperty getColorProperty() const {return m_colorProperty; } + void setColorProperty(const ObsoleteColorProperty &colorProperty); + ObsoleteColorProperty getColorProperty() const {return m_colorProperty; } QString colorValueText(const QColor &c); signals: - void colorPropertyChanged(const ColorProperty &material_color); + void colorPropertyChanged(const ObsoleteColorProperty &material_color); private slots: void buttonClicked(); private: QLabel *m_textLabel; QLabel *m_pixmapLabel; - ColorProperty m_colorProperty; + ObsoleteColorProperty m_colorProperty; }; diff --git a/GUI/coregui/Views/PropertyEditor/ObsoletePropertyVariantFactory.cpp b/GUI/coregui/Views/PropertyEditor/ObsoletePropertyVariantFactory.cpp index d12232392cb2dface5a84e23e631cc75064c6b3e..eda3fe50570166dc3fc437cb4cbdd0cbec480f19 100644 --- a/GUI/coregui/Views/PropertyEditor/ObsoletePropertyVariantFactory.cpp +++ b/GUI/coregui/Views/PropertyEditor/ObsoletePropertyVariantFactory.cpp @@ -89,14 +89,14 @@ QWidget *ObsoletePropertyVariantFactory::createEditor(QtVariantPropertyManager * ObsoletePropertyVariantManager::colorPropertyTypeId()) { ObsoleteColorPropertyEdit *editor = new ObsoleteColorPropertyEdit(parent); QVariant var = manager->value(property); - ColorProperty mat = var.value<ColorProperty>(); + ObsoleteColorProperty mat = var.value<ObsoleteColorProperty>(); editor->setColorProperty(mat); m_property_to_color_editors[property].append(editor); m_color_editor_to_property[editor] = property; - connect(editor, SIGNAL(colorPropertyChanged(const ColorProperty &)), - this, SLOT(slotSetValue(const ColorProperty &))); + connect(editor, SIGNAL(colorPropertyChanged(const ObsoleteColorProperty &)), + this, SLOT(slotSetValue(const ObsoleteColorProperty &))); connect(editor, SIGNAL(destroyed(QObject *)), this, SLOT(slotEditorDestroyed(QObject *))); return editor; @@ -191,7 +191,7 @@ void ObsoletePropertyVariantFactory::slotPropertyChanged(QtProperty *property, m_property_to_color_editors[property]; QListIterator<ObsoleteColorPropertyEdit *> itEditor(editors); while (itEditor.hasNext()) { - ColorProperty mat = value.value<ColorProperty>(); + ObsoleteColorProperty mat = value.value<ObsoleteColorProperty>(); itEditor.next()->setColorProperty(mat); } } @@ -244,7 +244,7 @@ void ObsoletePropertyVariantFactory::slotSetValue(const ExternalProperty &value) } } -void ObsoletePropertyVariantFactory::slotSetValue(const ColorProperty &value) +void ObsoletePropertyVariantFactory::slotSetValue(const ObsoleteColorProperty &value) { QObject *object = sender(); QMap<ObsoleteColorPropertyEdit *, QtProperty *>::ConstIterator itEditor = diff --git a/GUI/coregui/Views/PropertyEditor/ObsoletePropertyVariantFactory.h b/GUI/coregui/Views/PropertyEditor/ObsoletePropertyVariantFactory.h index 1099133edc7a7cb5388cfbaadb867f5a85db10ed..c45fdc4ceb434e4d307f44c427df5ae821b3da40 100644 --- a/GUI/coregui/Views/PropertyEditor/ObsoletePropertyVariantFactory.h +++ b/GUI/coregui/Views/PropertyEditor/ObsoletePropertyVariantFactory.h @@ -25,7 +25,7 @@ class ObsoleteMaterialPropertyEdit; class ExternalProperty; class ObsoleteColorPropertyEdit; -class ColorProperty; +class ObsoleteColorProperty; class ObsoleteScientificDoublePropertyEdit; class ObsoleteScientificDoubleProperty; class ObsoleteGroupPropertyEdit; @@ -52,7 +52,7 @@ protected: private slots: void slotPropertyChanged(QtProperty *property, const QVariant &value); void slotSetValue(const ExternalProperty &value); - void slotSetValue(const ColorProperty &value); + void slotSetValue(const ObsoleteColorProperty &value); void slotSetValue(const ObsoleteScientificDoubleProperty &value); void slotSetValue(const GroupProperty_t &value); void slotSetValue(const ComboProperty &value); diff --git a/GUI/coregui/Views/PropertyEditor/ObsoletePropertyVariantManager.cpp b/GUI/coregui/Views/PropertyEditor/ObsoletePropertyVariantManager.cpp index 7e2c46fe17a0cde889630e3b6b470edd50773339..38e97a58c91bc23b10dadb91f6298248c5035977 100644 --- a/GUI/coregui/Views/PropertyEditor/ObsoletePropertyVariantManager.cpp +++ b/GUI/coregui/Views/PropertyEditor/ObsoletePropertyVariantManager.cpp @@ -33,7 +33,7 @@ int ObsoletePropertyVariantManager::materialTypeId() int ObsoletePropertyVariantManager::colorPropertyTypeId() { - int result = qMetaTypeId<ColorProperty>(); + int result = qMetaTypeId<ObsoleteColorProperty>(); return result; } @@ -122,7 +122,7 @@ QVariant ObsoletePropertyVariantManager::value(const QtProperty *property) const QString ObsoletePropertyVariantManager::valueText(const QtProperty *property) const { if (m_theMaterialValues.contains(property)) { - return m_theMaterialValues[property].getName(); + return m_theMaterialValues[property].text(); } if (m_theColorValues.contains(property)) { return m_theColorValues[property].getText(); @@ -143,7 +143,7 @@ QString ObsoletePropertyVariantManager::valueText(const QtProperty *property) co QIcon ObsoletePropertyVariantManager::valueIcon(const QtProperty *property) const { if (m_theMaterialValues.contains(property)) { - return QIcon(m_theMaterialValues[property].getPixmap()); + return QIcon(m_theMaterialValues[property].pixmap()); } if (m_theColorValues.contains(property)) { return QIcon(m_theColorValues[property].getPixmap()); @@ -166,7 +166,7 @@ void ObsoletePropertyVariantManager::setValue(QtProperty *property, const QVaria } if (m_theColorValues.contains(property)) { if( val.userType() != colorPropertyTypeId() ) return; - ColorProperty mat = val.value<ColorProperty>(); + ObsoleteColorProperty mat = val.value<ObsoleteColorProperty>(); m_theColorValues[property] = mat; QVariant v2; v2.setValue(mat); @@ -216,7 +216,7 @@ void ObsoletePropertyVariantManager::initializeProperty(QtProperty *property) m_theMaterialValues[property] = m; } if (propertyType(property) == colorPropertyTypeId()) { - ColorProperty m; + ObsoleteColorProperty m; m_theColorValues[property] = m; } if (propertyType(property) == scientificDoubleTypeId()) { diff --git a/GUI/coregui/Views/PropertyEditor/ObsoletePropertyVariantManager.h b/GUI/coregui/Views/PropertyEditor/ObsoletePropertyVariantManager.h index fcb0b722ba37f5cbc5885697b0d1d392ffd92750..f3c54ffb1e3709ad727d47c664c544b99b0e083a 100644 --- a/GUI/coregui/Views/PropertyEditor/ObsoletePropertyVariantManager.h +++ b/GUI/coregui/Views/PropertyEditor/ObsoletePropertyVariantManager.h @@ -19,7 +19,7 @@ //! collection of classes extending QtPropertyBrowser functionality -#include "ColorProperty.h" +#include "ObsoleteColorProperty.h" #include "ComboProperty.h" #include "GroupProperty.h" #include "ExternalProperty.h" @@ -57,7 +57,7 @@ protected: virtual void uninitializeProperty(QtProperty *property); private: QMap<const QtProperty *, ExternalProperty> m_theMaterialValues; - QMap<const QtProperty *, ColorProperty> m_theColorValues; + QMap<const QtProperty *, ObsoleteColorProperty> m_theColorValues; QMap<const QtProperty *, ObsoleteScientificDoubleProperty> m_theScientificDoubleValues; QMap<const QtProperty *, GroupProperty_t> m_theFancyGroupValues; QMap<const QtProperty *, ComboProperty> m_theComboValues; diff --git a/GUI/coregui/Views/PropertyEditor/PropertyEditorFactory.cpp b/GUI/coregui/Views/PropertyEditor/PropertyEditorFactory.cpp index 617533f39639173661d51928591d9cfd6ac6184c..9e91c69a2b1894703581afa797029137a12516ca 100644 --- a/GUI/coregui/Views/PropertyEditor/PropertyEditorFactory.cpp +++ b/GUI/coregui/Views/PropertyEditor/PropertyEditorFactory.cpp @@ -21,7 +21,6 @@ #include "GroupProperty.h" #include "CustomEditors.h" #include "ComboProperty.h" -#include "ColorProperty.h" #include "CustomEventFilters.h" #include <QDoubleSpinBox> #include <QSpinBox> @@ -51,16 +50,11 @@ bool isIntProperty(const QVariant& variant) return variant.type() == QVariant::Int; } -bool isMaterialProperty(const QVariant& variant) +bool isExternalProperty(const QVariant& variant) { return variant.canConvert<ExternalProperty>(); } -bool isColorProperty(const QVariant& variant) -{ - return variant.canConvert<ColorProperty>(); -} - bool isGroupProperty(const QVariant& variant) { return variant.canConvert<GroupProperty_t>(); @@ -85,9 +79,7 @@ bool isBoolProperty(const QVariant& variant) bool PropertyEditorFactory::IsCustomVariant(const QVariant& variant) { - if (isMaterialProperty(variant)) - return true; - if (isColorProperty(variant)) + if (isExternalProperty(variant)) return true; if (isGroupProperty(variant)) return true; @@ -102,10 +94,8 @@ bool PropertyEditorFactory::IsCustomVariant(const QVariant& variant) // TODO replace with template method when custom variants refactored QString PropertyEditorFactory::ToString(const QVariant& variant) { - if (isMaterialProperty(variant)) - return variant.value<ExternalProperty>().getName(); - if (isColorProperty(variant)) - return variant.value<ColorProperty>().getText(); + if (isExternalProperty(variant)) + return variant.value<ExternalProperty>().text(); if (isGroupProperty(variant)) return variant.value<GroupProperty_t>()->currentLabel(); if (isComboProperty(variant)) @@ -145,15 +135,11 @@ QWidget* PropertyEditorFactory::CreateEditor(const SessionItem& item, QWidget* p result = createCustomStringEditor(item); } - else if(isMaterialProperty(item.value())) { + else if(isExternalProperty(item.value())) { auto editor = new ExternalPropertyEditor; editor->setData(item.value()); - result = editor; - } - - else if(isColorProperty(item.value())) { - auto editor = new ColorPropertyEditor; - editor->setData(item.value()); + if (item.editorType() != Constants::DefaultEditorType) + editor->setExternalDialogType(item.editorType()); result = editor; } diff --git a/GUI/coregui/Views/RealSpaceWidgets/TransformTo3D.cpp b/GUI/coregui/Views/RealSpaceWidgets/TransformTo3D.cpp index 303e96cc0f34afd6d2d5ae043925a96a58a08ff2..15b6f7cbbf3d60a8a5932a81ae360ddd6d5e6d60 100644 --- a/GUI/coregui/Views/RealSpaceWidgets/TransformTo3D.cpp +++ b/GUI/coregui/Views/RealSpaceWidgets/TransformTo3D.cpp @@ -69,7 +69,7 @@ std::unique_ptr<ba3d::Layer> TransformTo3D::createLayer(const SessionItem& layer std::unique_ptr<ba3d::Layer> result = std::make_unique<ba3d::Layer>( ba3d::dxyz(ba3d::dr(-s2,+s2), ba3d::dr(-s2,+s2), ba3d::dr(ztop, zbottom))); - QColor color = layerItem.getItemValue(LayerItem::P_MATERIAL).value<ExternalProperty>().getColor(); + QColor color = layerItem.getItemValue(LayerItem::P_MATERIAL).value<ExternalProperty>().color(); color.setAlphaF(.3); result->color = color; @@ -106,7 +106,7 @@ TransformTo3D::createParticle(const SessionItem& particleItem) ExternalProperty material = particleItem.getItemValue(ParticleItem::P_MATERIAL).value<ExternalProperty>(); - result->color = material.getColor(); + result->color = material.color(); SessionItem* positionItem = particleItem.getItem(ParticleItem::P_POSITION); double x = positionItem->getItemValue(VectorItem::P_X).toDouble(); diff --git a/GUI/coregui/Views/SampleDesigner/ILayerView.cpp b/GUI/coregui/Views/SampleDesigner/ILayerView.cpp index 911cb57f872df1e67bed249bda763e6bda48716a..6cc81ef22d9c8f021103d9dd501b7eb0033efbbd 100644 --- a/GUI/coregui/Views/SampleDesigner/ILayerView.cpp +++ b/GUI/coregui/Views/SampleDesigner/ILayerView.cpp @@ -80,7 +80,7 @@ void ILayerView::updateColor() QVariant v = m_item->getItemValue(LayerItem::P_MATERIAL); if (v.isValid()) { ExternalProperty mp = v.value<ExternalProperty>(); - setColor(mp.getColor()); + setColor(mp.color()); update(); } else { Q_ASSERT(0); diff --git a/Tests/UnitTests/GUI/TestComboProperty.h b/Tests/UnitTests/GUI/TestComboProperty.h index 52765450ed4a00aa243f9d1864ee63b6aaf2a467..c0fa0817d996ec516b4f9a90509512a038dc8264 100644 --- a/Tests/UnitTests/GUI/TestComboProperty.h +++ b/Tests/UnitTests/GUI/TestComboProperty.h @@ -1,17 +1,17 @@ #include <QtTest> #include "ComboProperty.h" -#include "PropertyItem.h" -#include "SessionXML.h" -#include <QXmlStreamWriter> -#include <QXmlStreamReader> +#include "test_utils.h" #include <QPair> -#include <QDebug> -#include <memory> class TestComboProperty : public QObject { Q_OBJECT +private: + ComboProperty propertyFromXML(const QString& buffer) { + return TestUtils::propertyFromXML<ComboProperty>(buffer); + } + private slots: void test_ComboEquality(); void test_VariantEquality(); @@ -51,16 +51,16 @@ inline void TestComboProperty::test_VariantEquality() ComboProperty c1 = ComboProperty() << "a1" << "a2"; ComboProperty c2 = ComboProperty() << "a1" << "a2"; - QVERIFY(c1.getVariant() == c2.getVariant()); + QVERIFY(c1.variant() == c2.variant()); c2 << "a3"; - QVERIFY(c1.getVariant() != c2.getVariant()); + QVERIFY(c1.variant() != c2.variant()); c2.setValue("a2"); - QVERIFY(c1.getVariant() != c2.getVariant()); + QVERIFY(c1.variant() != c2.variant()); c1 << "a3"; c1.setValue("a2"); - QVERIFY(c1.getVariant() == c2.getVariant()); + QVERIFY(c1.variant() == c2.variant()); } inline void TestComboProperty::test_setValue() @@ -120,30 +120,13 @@ inline void TestComboProperty::test_comboXML() // Writing combo to XML ComboProperty combo = ComboProperty() << "a1" << "a2" << "a3"; - QString buffer; - QXmlStreamWriter writer(&buffer); - - SessionWriter::writeVariant(&writer, combo.getVariant(), 0); - - QCOMPARE(buffer, QString("<Parameter ParType=\"ComboProperty\" ParRole=\"0\" ParValue=\"0\" " - "ParExt=\"a1;a2;a3\"/>")); + QString expected = "<Parameter ParType=\"ComboProperty\" ParRole=\"0\" ParValue=\"0\" " + "ParExt=\"a1;a2;a3\"/>"; + QCOMPARE(TestUtils::propertyToXML(combo), expected); // reading from XML - std::unique_ptr<PropertyItem> item(new PropertyItem); - - QXmlStreamReader reader(buffer); - - while (!reader.atEnd()) { - reader.readNext(); - if (reader.isStartElement()) { - if (reader.name() == SessionXML::ParameterTag) { - SessionReader::readProperty(&reader, item.get()); - } - } - } - - ComboProperty combo_property = item->value().value<ComboProperty>(); - + ComboProperty combo_property = propertyFromXML(expected); QCOMPARE(combo_property.getValue(), QString("a1")); QCOMPARE(combo_property.stringOfValues(), QString("a1;a2;a3")); + QVERIFY(combo_property == combo); } diff --git a/Tests/UnitTests/GUI/TestExternalProperty.h b/Tests/UnitTests/GUI/TestExternalProperty.h new file mode 100644 index 0000000000000000000000000000000000000000..4ef6ae848ae07be558f928ec6db3e2a86d1ec0cb --- /dev/null +++ b/Tests/UnitTests/GUI/TestExternalProperty.h @@ -0,0 +1,103 @@ +#include <QtTest> +#include "ExternalProperty.h" +#include "test_utils.h" + +class TestExternalProperty : public QObject +{ + Q_OBJECT + +private: + ExternalProperty propertyFromXML(const QString& buffer) { + return TestUtils::propertyFromXML<ExternalProperty>(buffer); + } + +private slots: + void test_initialState(); + void test_equalityOperators(); + void test_variantEquality(); + void test_toXML(); +}; + +inline void TestExternalProperty::test_initialState() +{ + ExternalProperty property; + QVERIFY(property.isValid() == false); + QVERIFY(property.color().isValid() == false); + QVERIFY(property.identifier().isEmpty() == true); + QVERIFY(property.text().isEmpty() == true); + + // changing any property should change state to valid + property.setColor(QColor(Qt::red)); + QVERIFY(property.color() == QColor(Qt::red)); + QVERIFY(property.isValid() == true); + property.setColor(QColor()); + QVERIFY(property.isValid() == false); + property.setText("aaa"); + QVERIFY(property.text() == QString("aaa")); + QVERIFY(property.isValid() == true); + property.setText(QString()); + QVERIFY(property.isValid() == false); +} + +//! Testing equality operators. + +inline void TestExternalProperty::test_equalityOperators() +{ + ExternalProperty prop1; + ExternalProperty prop2; + + QVERIFY (prop1 == prop2); + prop1.setColor(QColor(Qt::red)); + QVERIFY (prop1 != prop2); + prop2.setColor(QColor(Qt::red)); + QVERIFY (prop1 == prop2); + + prop1.setIdentifier("aaa"); + QVERIFY (prop1 != prop2); + prop2.setIdentifier("aaa"); + QVERIFY (prop1 == prop2); +} + +//! Testing equality operators for QVariants based on ExternalProperty. +//! Comparators should be enabled in main.cpp + +inline void TestExternalProperty::test_variantEquality() +{ + ExternalProperty prop1; + ExternalProperty prop2; + + QVERIFY(prop1.variant() == prop2.variant()); + prop1.setIdentifier("aaa"); + QVERIFY(prop1.variant() != prop2.variant()); + prop2.setIdentifier("aaa"); + QVERIFY(prop1.variant() == prop2.variant()); +} + +inline void TestExternalProperty::test_toXML() +{ + QString expected; + + // empty property to XML + ExternalProperty property; + expected = "<Parameter ParType=\"ExternalProperty\" ParRole=\"0\" Text=\"\" Color=\"\" Identifier=\"\"/>"; + QCOMPARE(TestUtils::propertyToXML(property), expected); + + // from XML to empty property + QCOMPARE(propertyFromXML(expected).text(), property.text()); + QCOMPARE(propertyFromXML(expected).color(), property.color()); + QCOMPARE(propertyFromXML(expected).identifier(), property.identifier()); + QVERIFY(propertyFromXML(expected) == property); + + // initialized property to XML + property.setIdentifier("{123456}"); + property.setText("abc"); + property.setColor(QColor(Qt::red)); + expected = "<Parameter ParType=\"ExternalProperty\" ParRole=\"0\" Text=\"abc\" Color=\"#ffff0000\" Identifier=\"{123456}\"/>"; + QCOMPARE(TestUtils::propertyToXML(property), expected); + + // from XML to initialized property + QCOMPARE(propertyFromXML(expected).identifier(), property.identifier()); + QCOMPARE(propertyFromXML(expected).text(), property.text()); + QCOMPARE(propertyFromXML(expected).color(), property.color()); + QVERIFY(propertyFromXML(expected) == property); +} diff --git a/Tests/UnitTests/GUI/TestGUI.cpp b/Tests/UnitTests/GUI/TestGUI.cpp index d4edd27b3f50f91522278508e5e15b632f7494c7..57e52b4b70ae766b93d40f697495ca8bb2d3ead9 100644 --- a/Tests/UnitTests/GUI/TestGUI.cpp +++ b/Tests/UnitTests/GUI/TestGUI.cpp @@ -38,6 +38,7 @@ #include "TestComponentUtils.h" #include "TestLayerItems.h" #include "TestMaterialPropertyController.h" +#include "TestExternalProperty.h" #include <memory> class GUITestFactory { @@ -67,6 +68,8 @@ int main(int argc, char** argv) { Q_UNUSED(app); QMetaType::registerComparators<ComboProperty>(); + QMetaType::registerComparators<ExternalProperty>(); + qRegisterMetaType<QAbstractItemModel::LayoutChangeHint>("LayoutChangeHint"); GUITestFactory tests; @@ -108,6 +111,7 @@ int main(int argc, char** argv) { tests.add<TestProxyModelStrategy>(); tests.add<TestSessionItemUtils>(); tests.add<TestComponentUtils>(); + tests.add<TestExternalProperty>(); return tests.runAll(argc, argv); } diff --git a/Tests/UnitTests/GUI/TestLayerItems.h b/Tests/UnitTests/GUI/TestLayerItems.h index 19eaac821b9870d463060feb35b0da3b087cf2db..5b7ba517b352fc0967763bc7137151998bc07a8d 100644 --- a/Tests/UnitTests/GUI/TestLayerItems.h +++ b/Tests/UnitTests/GUI/TestLayerItems.h @@ -27,8 +27,8 @@ inline void TestLayerItems::test_LayerDefaultMaterial() auto defMaterial = materials.front(); ExternalProperty material = layer->getItemValue(LayerItem::P_MATERIAL).value<ExternalProperty>(); - QCOMPARE(material.getName(), QString("Default")); - QCOMPARE(material.getIdentifier(), defMaterial->getItemValue(MaterialItem::P_IDENTIFIER).toString()); + QCOMPARE(material.text(), QString("Default")); + QCOMPARE(material.identifier(), defMaterial->getItemValue(MaterialItem::P_IDENTIFIER).toString()); } //! Checks that change of material in MaterialModel is propagated to the LayerItem. diff --git a/Tests/UnitTests/GUI/TestMapperCases.h b/Tests/UnitTests/GUI/TestMapperCases.h index d936cc8085ca22e25fcce6b005ca4d05c2198acd..17d4c34b5da20b51ff3861e2994c344574b7f32b 100644 --- a/Tests/UnitTests/GUI/TestMapperCases.h +++ b/Tests/UnitTests/GUI/TestMapperCases.h @@ -55,6 +55,6 @@ inline void TestMapperCases::test_SimulationOptionsComputationToggle() QVERIFY(item->getItem(SimulationOptionsItem::P_MC_POINTS)->isEnabled() == false); combo.setValue(Constants::SIMULATION_MONTECARLO); - item->setItemValue(SimulationOptionsItem::P_COMPUTATION_METHOD, combo.getVariant()); + item->setItemValue(SimulationOptionsItem::P_COMPUTATION_METHOD, combo.variant()); QVERIFY(item->getItem(SimulationOptionsItem::P_MC_POINTS)->isEnabled() == true); } diff --git a/Tests/UnitTests/GUI/TestMaterialModel.h b/Tests/UnitTests/GUI/TestMaterialModel.h index eac429ca5d447a24a8b4b7ef40bbaffa8f79c323..5dc9ae044d448a835a58103cde0133a090f26ec1 100644 --- a/Tests/UnitTests/GUI/TestMaterialModel.h +++ b/Tests/UnitTests/GUI/TestMaterialModel.h @@ -100,9 +100,9 @@ inline void TestMaterialModel::test_materialPropertyFromMaterial() MaterialItem* mat = model.addMaterial("Something", 1.0, 2.0); ExternalProperty property = MaterialItemUtils::materialProperty(*mat); - QCOMPARE(property.getName(), QString("Something")); - QCOMPARE(property.getColor(), mat->getColor()); - QCOMPARE(property.getIdentifier(), mat->getIdentifier()); + QCOMPARE(property.text(), QString("Something")); + QCOMPARE(property.color(), mat->getColor()); + QCOMPARE(property.identifier(), mat->getIdentifier()); } //! Default MaterialProperty construction. @@ -111,23 +111,16 @@ inline void TestMaterialModel::test_defaultMaterialProperty() { MaterialModel model; - // testing default constructed material property - ExternalProperty property; - QCOMPARE(property.getName(), QString("Undefined")); - QCOMPARE(property.getColor(), QColor(Qt::red)); - QCOMPARE(property.getIdentifier(), QString("")); - // testing default material property from MaterialItemUtils - ExternalProperty property2 = MaterialItemUtils::defaultMaterialProperty(); - QCOMPARE(property2.getName(), QString("Undefined")); - QCOMPARE(property2.getColor(), QColor(Qt::red)); - QCOMPARE(property2.getIdentifier(), QString("")); + // in the absence of any materials, property should be in invalid state + ExternalProperty property = MaterialItemUtils::defaultMaterialProperty(); + QVERIFY(property.isValid() == false); // adding materials to the model, default property should refer to first material in a model auto mat1 = model.addMaterial("Something1", 1.0, 2.0); model.addMaterial("Something2", 3.0, 4.0); - ExternalProperty property3 = MaterialItemUtils::defaultMaterialProperty(); - QCOMPARE(property3.getName(), QString("Something1")); - QCOMPARE(property3.getColor(), mat1->getColor()); - QCOMPARE(property3.getIdentifier(), mat1->getIdentifier()); + ExternalProperty property2 = MaterialItemUtils::defaultMaterialProperty(); + QCOMPARE(property2.text(), QString("Something1")); + QCOMPARE(property2.color(), mat1->getColor()); + QCOMPARE(property2.identifier(), mat1->getIdentifier()); } diff --git a/Tests/UnitTests/GUI/TestMaterialPropertyController.h b/Tests/UnitTests/GUI/TestMaterialPropertyController.h index e02509d73e0669ea36eacb2c468c188a2f0b2b97..35e6a82788f9def730481626b1b7c7067a42bf79 100644 --- a/Tests/UnitTests/GUI/TestMaterialPropertyController.h +++ b/Tests/UnitTests/GUI/TestMaterialPropertyController.h @@ -5,7 +5,7 @@ #include "LayerItem.h" #include "MaterialItem.h" #include "ExternalProperty.h" -#include "ColorProperty.h" +#include "ObsoleteColorProperty.h" #include "MaterialItemUtils.h" class TestMaterialPropertyController : public QObject @@ -42,27 +42,25 @@ inline void TestMaterialPropertyController::test_ControllerForLayer() mat1->setItemName("newname"); // QCOMPARE(property_changed, 1); ExternalProperty property = layer->getItemValue(LayerItem::P_MATERIAL).value<ExternalProperty>(); - QCOMPARE(property.getIdentifier(), mat1->getIdentifier()); - QCOMPARE(property.getName(), mat1->itemName()); - QCOMPARE(property.getColor(), mat1->getColor()); + QCOMPARE(property.identifier(), mat1->getIdentifier()); + QCOMPARE(property.text(), mat1->itemName()); + QCOMPARE(property.color(), mat1->getColor()); // changing color of MaterialItem - ColorProperty colorProperty(Qt::red); - mat1->setItemValue(MaterialItem::P_COLOR, colorProperty.getVariant()); + ExternalProperty colorProperty = MaterialItemUtils::colorProperty(QColor(Qt::red)); + mat1->setItemValue(MaterialItem::P_COLOR, colorProperty.variant()); // QCOMPARE(property_changed, 2); property = layer->getItemValue(LayerItem::P_MATERIAL).value<ExternalProperty>(); - QCOMPARE(property.getIdentifier(), mat1->getIdentifier()); - QCOMPARE(property.getName(), mat1->itemName()); - QCOMPARE(property.getColor(), mat1->getColor()); - QCOMPARE(property.getColor(), QColor(Qt::red)); + QCOMPARE(property.identifier(), mat1->getIdentifier()); + QCOMPARE(property.text(), mat1->itemName()); + QCOMPARE(property.color(), mat1->getColor()); + QCOMPARE(property.color(), QColor(Qt::red)); // removing material from the model, property should become undefined materialModel.removeRows(0, 1, QModelIndex()); // QCOMPARE(property_changed, 3); property = layer->getItemValue(LayerItem::P_MATERIAL).value<ExternalProperty>(); - QCOMPARE(property.getIdentifier(), QString()); - QCOMPARE(property.getName(), QString("Undefined")); - QCOMPARE(property.getColor(), QColor(Qt::red)); + QVERIFY(property.isValid() == false); } //! Test MaterialProperty update in sample items when working on model clone. @@ -82,9 +80,9 @@ inline void TestMaterialPropertyController::test_ControllerInEditorContext() MaterialPropertyController controller; controller.setModels(&materialModel, &sampleModel); - layer1->setItemValue(LayerItem::P_MATERIAL, MaterialItemUtils::materialProperty(*mat1).getVariant()); - layer2->setItemValue(LayerItem::P_MATERIAL, MaterialItemUtils::materialProperty(*mat2).getVariant()); - layer3->setItemValue(LayerItem::P_MATERIAL, MaterialItemUtils::materialProperty(*mat3).getVariant()); + layer1->setItemValue(LayerItem::P_MATERIAL, MaterialItemUtils::materialProperty(*mat1).variant()); + layer2->setItemValue(LayerItem::P_MATERIAL, MaterialItemUtils::materialProperty(*mat2).variant()); + layer3->setItemValue(LayerItem::P_MATERIAL, MaterialItemUtils::materialProperty(*mat3).variant()); // Making copy of material model std::unique_ptr<MaterialModel> materialsCopy(materialModel.createCopy()); @@ -119,11 +117,9 @@ inline void TestMaterialPropertyController::test_ControllerInEditorContext() // layer2 should have undefined material property ExternalProperty property = layer2->getItemValue(LayerItem::P_MATERIAL).value<ExternalProperty>(); - QCOMPARE(property.getName(), QString("Undefined")); - QCOMPARE(property.getIdentifier(), QString("")); - QCOMPARE(property.getColor(), QColor(Qt::red)); + QVERIFY(property.isValid() == false); // layer3 should have different MaterialProperty name property = layer3->getItemValue(LayerItem::P_MATERIAL).value<ExternalProperty>(); - QCOMPARE(property.getName(), QString("name3changed")); + QCOMPARE(property.text(), QString("name3changed")); } diff --git a/Tests/UnitTests/GUI/test_utils.h b/Tests/UnitTests/GUI/test_utils.h index 2e375908f2ea51c707b1ecc2b92329bd68fa9137..74fadcac56995ba3918bc96cedc4457fc412ef9e 100644 --- a/Tests/UnitTests/GUI/test_utils.h +++ b/Tests/UnitTests/GUI/test_utils.h @@ -17,6 +17,9 @@ #define TEST_UTILS #include <QString> +#include "SessionXML.h" +#include "PropertyItem.h" +#include <QXmlStreamWriter> namespace TestUtils { @@ -25,6 +28,35 @@ namespace TestUtils //! it will be removed with all its content. void create_dir(const QString& dir_name); + +//! Converts property to XML string +template <typename T> +QString propertyToXML(const T& property) +{ + QString result; + QXmlStreamWriter writer(&result); + SessionWriter::writeVariant(&writer, property.variant(), /*role*/0); + return result; +} + +//! Converts XML string to property +template <typename T> +T propertyFromXML(const QString& buffer) { + std::unique_ptr<PropertyItem> item(new PropertyItem); + QXmlStreamReader reader(buffer); + + while (!reader.atEnd()) { + reader.readNext(); + if (reader.isStartElement()) { + if (reader.name() == SessionXML::ParameterTag) { + SessionReader::readProperty(&reader, item.get()); + } + } + } + + return item->value().value<T>(); +} + } #endif // TEST_UTILS diff --git a/auto/Wrap/libBornAgainCore_wrap.cpp b/auto/Wrap/libBornAgainCore_wrap.cpp index bac73385d2b50f7e1d03d3fd8ff9eef494603647..00c6fe67e6b3ccd87e9a4a26ce083add16bea87f 100644 --- a/auto/Wrap/libBornAgainCore_wrap.cpp +++ b/auto/Wrap/libBornAgainCore_wrap.cpp @@ -5994,7 +5994,7 @@ SWIG_AsVal_std_complex_Sl_double_Sg_ (PyObject *o, std::complex<double>* val) SWIGINTERNINLINE PyObject* -SWIG_From_std_complex_Sl_double_Sg_ (/*@SWIG:/usr/local/share/swig/3.0.8/typemaps/swigmacros.swg,104,%ifcplusplus@*/ +SWIG_From_std_complex_Sl_double_Sg_ (/*@SWIG:/home/pospelov/software/local/share/swig/3.0.8/typemaps/swigmacros.swg,104,%ifcplusplus@*/ const std::complex<double>&