34 #include "ui_ipconnectionoptionspage.h"
37 : IOptionsPage(parent)
49 m_page =
new Ui::IPconnectionOptionsPage();
50 QWidget *w =
new QWidget(parent);
55 for (
const auto &host : m_config->
hosts()) {
56 m_model->insertRow(m_model->
rowCount());
64 m_page->tblHosts->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
66 m_page->tblHosts->setModel(m_model);
68 connect(m_page->btnAdd, &QPushButton::clicked,
this,
69 [
this]() { m_model->insertRow(m_model->
rowCount()); });
71 connect(m_page->btnRemove, &QPushButton::clicked,
this, [
this]() {
72 const auto selection = m_page->tblHosts->selectionModel()->selectedIndexes();
73 if (selection.count() && selection.at(0).isValid())
74 m_page->tblHosts->model()->removeRow(selection.at(0).row());
83 for (
int row = 0; row < m_model->
rowCount();) {
85 auto port = m_model->
data(m_model->index(row,
ColumnPort)).toInt();
86 if (!hostname.length() || port < 1 || port > 65535)
87 m_model->removeRow(row);
102 const QStyleOptionViewItem &option,
103 const QModelIndex &index)
const
107 switch (index.column()) {
109 auto editor =
new QComboBox(parent);
112 editor->setFrame(
false);
116 auto editor =
new QLineEdit(parent);
117 editor->setFrame(
false);
121 auto editor =
new QSpinBox(parent);
122 editor->setMinimum(1);
123 editor->setMaximum(65535);
124 editor->setFrame(
false);
135 QVariant val = index.model()->data(index, Qt::EditRole);
137 switch (index.column()) {
139 auto comboBox =
static_cast<QComboBox *
>(editor);
140 for (
int i = 0;
i < comboBox->count();
i++) {
142 comboBox->setCurrentIndex(
i);
147 auto lineEdit =
static_cast<QLineEdit *
>(editor);
148 lineEdit->setText(val.toString());
152 auto spinBox =
static_cast<QSpinBox *
>(editor);
153 spinBox->setValue(val.toInt());
162 const QModelIndex &index)
const
166 switch (index.column()) {
168 auto comboBox =
static_cast<QComboBox *
>(editor);
169 val.setValue(QVariant::fromValue(comboBox->currentData()));
173 auto lineEdit =
static_cast<QLineEdit *
>(editor);
174 val.setValue(lineEdit->text());
178 auto spinBox =
static_cast<QSpinBox *
>(editor);
179 spinBox->interpretText();
180 val.setValue(spinBox->value());
188 model->setData(index, val, Qt::EditRole);
192 const QStyleOptionViewItem &option,
193 const QModelIndex &index)
const
196 editor->setGeometry(option.rect);
201 if (parent.isValid())
203 return m_hosts.count();
208 if (parent.isValid())
215 if (!index.isValid() || index.row() >= m_hosts.count())
223 if (role == Qt::DisplayRole || role == Qt::EditRole) {
224 switch (index.column()) {
226 return QVariant::fromValue(host.
protocol);
242 if (role != Qt::DisplayRole)
245 if (orientation == Qt::Horizontal) {
248 return tr(
"Protocol");
250 return tr(
"IP/Hostname");
257 return QString::number(section + 1);
262 if (!index.isValid())
263 return Qt::ItemIsEnabled;
264 return QAbstractTableModel::flags(index) | Qt::ItemIsEditable;
269 if (index.isValid() && role == Qt::EditRole) {
270 auto &host = m_hosts[index.row()];
271 switch (index.column()) {
276 host.hostname = value.toString();
279 host.port = value.toInt();
284 emit dataChanged(index, index);
294 beginInsertRows(QModelIndex(), position, position + rows - 1);
296 for (
int row = 0; row < rows; row++)
307 beginRemoveRows(QModelIndex(), position, position + rows - 1);
309 for (
int row = 0; row < rows; row++)
310 m_hosts.removeAt(position);
QVector< Host > & hosts()
void availableDevChanged()
QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const
int columnCount(const QModelIndex &parent=QModelIndex()) const
IPConnectionOptionsPage(IPConnectionConfiguration *config, QObject *parent=nullptr)
void setHosts(QVector< Host > &hosts)
virtual ~IPConnectionOptionsPage()
QVariant data(const QModelIndex &index, int role=Qt::EditRole) const
bool setData(const QModelIndex &index, const QVariant &value, int role=Qt::EditRole)
void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const override
QWidget * createPage(QWidget *parent)
bool removeRows(int position, int rows, const QModelIndex &index=QModelIndex())
void setEditorData(QWidget *editor, const QModelIndex &index) const override
QWidget * createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const override
void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const override
QVector< IPConnectionConfiguration::Host > & hosts()
bool insertRows(int position, int rows, const QModelIndex &index=QModelIndex())
int rowCount(const QModelIndex &parent=QModelIndex()) const
Qt::ItemFlags flags(const QModelIndex &index) const