BornAgain  1.19.0
Simulate and fit neutron and x-ray scattering at grazing incidence
externalpropertyeditor.cpp
Go to the documentation of this file.
1 // ************************************************************************************************
2 //
3 // qt-mvvm: Model-view-view-model framework for large GUI applications
4 //
5 //! @file mvvm/viewmodel/mvvm/editors/externalpropertyeditor.cpp
6 //! @brief Implements class CLASS?
7 //!
8 //! @homepage http://www.bornagainproject.org
9 //! @license GNU General Public License v3 or higher (see COPYING)
10 //! @copyright Forschungszentrum Jülich GmbH 2020
11 //! @authors Gennady Pospelov et al, Scientific Computing Group at MLZ (see CITATION, AUTHORS)
12 //
13 // ************************************************************************************************
14 
20 #include <QHBoxLayout>
21 #include <QLabel>
22 #include <QMessageBox>
23 #include <QToolButton>
24 #include <stdexcept>
25 
26 using namespace ModelView;
27 
29  : CustomEditor(parent)
30  , m_textLabel(new QLabel)
31  , m_pixmapLabel(new QLabel)
32  , m_focusFilter(new LostFocusFilter(this))
33 
34 {
35  setMouseTracking(true);
36  setAutoFillBackground(true);
37 
38  auto layout = new QHBoxLayout;
39  layout->setContentsMargins(4, 0, 0, 0);
40 
41  auto button = new QToolButton;
42  button->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Preferred));
43  button->setText(QLatin1String(" . . . "));
44  button->setToolTip("Open selector");
45  layout->addWidget(m_pixmapLabel);
46  layout->addWidget(m_textLabel);
47  layout->addStretch(1);
48  layout->addWidget(button);
49  setFocusPolicy(Qt::StrongFocus);
50  setAttribute(Qt::WA_InputMethodEnabled);
51  connect(button, &QToolButton::clicked, this, &ExternalPropertyEditor::buttonClicked);
52 
53  setLayout(layout);
54 }
55 
56 void ExternalPropertyEditor::setCallback(std::function<void(const QVariant&)> callback)
57 {
58  m_callback = std::move(callback);
59 }
60 
62 {
63  if (m_callback)
65  else
66  QMessageBox::warning(nullptr, "Not configured", "No external dialog configured.");
67 }
68 
70 {
72  throw std::runtime_error("Error. Wrong variant type (ExternalProperty is required).");
73 
74  auto prop = m_data.value<ExternalProperty>();
76  pixmap.fill(prop.color());
77  m_textLabel->setText(QString::fromStdString(prop.text()));
78  m_pixmapLabel->setPixmap(pixmap);
79 }
Base class for all custom variant editors.
Definition: customeditor.h:26
void setCallback(std::function< void(const QVariant &)> callback)
ExternalPropertyEditor(QWidget *parent=nullptr)
void update_components() override
Should update widget components from m_data, if necessary.
std::function< void(const QVariant &)> m_callback
Property to carry text, color and identifier.
Event filter to prevent loss of the focus.
Defines class CLASS?
Defines class CLASS?
Defines class CLASS?
Defines class CLASS?
Defines class CLASS?
void warning(QWidget *parent, const QString &title, const QString &text, const QString &detailedText)
Definition: GUIHelpers.cpp:74
MVVM_VIEWMODEL_EXPORT int DefaultPixmapSize()
Returns int value corresponding to pixmap in standard Qt table/tree decorations.
Definition: styleutils.cpp:17
MVVM_MODEL_EXPORT bool IsExtPropertyVariant(const Variant &variant)
Returns true in the case of ExternalProperty based variant.
materialitems.h Collection of materials to populate MaterialModel.