Skip to content
Snippets Groups Projects
Commit 9fe299d0 authored by Wuttke, Joachim's avatar Wuttke, Joachim
Browse files

ditto via new methods in SetWithModel

parent e9cfc6a4
No related branches found
No related tags found
1 merge request!2405Update instrument & sample lists after change of name or description
......@@ -102,11 +102,19 @@ public:
emit AbstractSetModel::setChanged();
}
//! To be called when name or description of the current item have changed.
void currentDataChanged()
void setCurrentName(const QString& s)
{
QModelIndex qi = m_qmodel->index(m_idx, 0);
m_qmodel->dataChanged(qi, qi, QVector<int>({Qt::DisplayRole, Qt::EditRole}));
if (s != currentItem()->name()) {
currentItem()->setName(s);
currentDataChanged();
}
}
void setCurrentDescription(const QString& s)
{
if (s != currentItem()->description()) {
currentItem()->setDescription(s);
currentDataChanged();
}
}
size_t currentIndex() const { return m_idx; }
......@@ -148,6 +156,12 @@ private:
if (m_idx == m_vec.size())
m_idx = m_vec.size() - 1;
}
//! To be called when name or description of the current item have changed.
void currentDataChanged()
{
QModelIndex qi = m_qmodel->index(m_idx, 0);
m_qmodel->dataChanged(qi, qi, QVector<int>({Qt::DisplayRole, Qt::EditRole}));
}
OwningVector<T> m_vec;
size_t m_idx = -1; //!< current index, or -1 for empty set
......
......@@ -165,11 +165,8 @@ QWidget* InstrumentView::createEditor(InstrumentItem* t)
layout->addWidget(g);
auto* nameEdit = new QLineEdit(t->name(), g);
connect(nameEdit, &QLineEdit::textEdited, [this, t](const QString& text) {
if (text != t->name()) {
t->setName(text);
m_set->currentDataChanged();
}
connect(nameEdit, &QLineEdit::textEdited, [this](const QString& text) {
m_set->setCurrentName(text);
});
formLayout->addRow("Name:", nameEdit);
......@@ -179,9 +176,8 @@ QWidget* InstrumentView::createEditor(InstrumentItem* t)
descriptionEdit->setAcceptRichText(false);
descriptionEdit->setTabChangesFocus(true);
descriptionEdit->setPlainText(t->description());
connect(descriptionEdit, &QTextEdit::textChanged, [this, t, descriptionEdit] {
t->setDescription(descriptionEdit->toPlainText());
m_set->currentDataChanged();
connect(descriptionEdit, &QTextEdit::textChanged, [this, descriptionEdit] {
m_set->setCurrentDescription(descriptionEdit->toPlainText());
});
formLayout->addRow("Description:", descriptionEdit);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment