5#include <iconloader_p.h>
6#include <QtCore/qstringlistmodel.h>
10using namespace Qt::StringLiterals;
15 : QDialog(parent), m_model(
new QStringListModel(
this))
18 listView->setModel(m_model);
20 connect(listView->selectionModel(),
21 &QItemSelectionModel::currentChanged,
22 this, &StringListEditor::currentIndexChanged);
23 connect(listView->itemDelegate(),
24 &QAbstractItemDelegate::closeEditor,
25 this, &StringListEditor::currentValueChanged);
27 connect(upButton, &QAbstractButton::clicked,
this, &StringListEditor::upButtonClicked);
28 connect(downButton, &QAbstractButton::clicked,
this, &StringListEditor::downButtonClicked);
29 connect(newButton, &QAbstractButton::clicked,
this, &StringListEditor::newButtonClicked);
30 connect(deleteButton, &QAbstractButton::clicked,
this, &StringListEditor::deleteButtonClicked);
31 connect(valueEdit, &QLineEdit::textEdited,
this, &StringListEditor::valueEdited);
33 QIcon upIcon = createIconSet(
"up.png"_L1);
34 QIcon downIcon = createIconSet(
"down.png"_L1);
35 QIcon minusIcon = createIconSet(
"minus.png"_L1);
36 QIcon plusIcon = createIconSet(
"plus.png"_L1);
37 upButton->setIcon(upIcon);
38 downButton->setIcon(downIcon);
39 newButton->setIcon(plusIcon);
40 deleteButton->setIcon(minusIcon);
47QStringList
StringListEditor::getStringList(QWidget *parent,
const QStringList &init,
int *result)
50 dlg.setStringList(init);
54 return (res == QDialog::Accepted) ? dlg.stringList() : init;
59 m_model->setStringList(stringList);
65 return m_model->stringList();
68void StringListEditor::currentIndexChanged(
const QModelIndex ¤t,
const QModelIndex &previous)
71 setCurrentIndex(current.row());
77 setCurrentIndex(currentIndex());
83 int from = currentIndex();
84 int to = currentIndex() - 1;
85 QString value = stringAt(from);
87 insertString(to, value);
94 int from = currentIndex();
95 int to = currentIndex() + 1;
96 QString value = stringAt(from);
98 insertString(to, value);
105 int to = currentIndex();
109 insertString(to, QString());
117 removeString(currentIndex());
118 setCurrentIndex(currentIndex());
124 setStringAt(currentIndex(), text);
129 upButton->setEnabled((count() > 1) && (currentIndex() > 0));
130 downButton->setEnabled((count() > 1) && (currentIndex() >= 0) && (currentIndex() < (count() - 1)));
131 deleteButton->setEnabled(currentIndex() != -1);
132 valueEdit->setEnabled(currentIndex() != -1);
137 return listView->currentIndex().row();
142 QModelIndex modelIndex = m_model->index(index, 0);
143 if (listView->currentIndex() != modelIndex)
144 listView->setCurrentIndex(modelIndex);
145 valueEdit->setText(stringAt(index));
150 return m_model->rowCount();
155 return qvariant_cast<QString>(m_model->data(m_model->index(index, 0), Qt::DisplayRole));
160 m_model->setData(m_model->index(index, 0), value);
165 m_model->removeRows(index, 1);
170 m_model->insertRows(index, 1);
171 m_model->setData(m_model->index(index, 0), value);
176 listView->edit(m_model->index(index, 0));
QStringList stringList() const
void setStringList(const QStringList &stringList)
Combined button and popup list for selecting options.
Auxiliary methods to store/retrieve settings.