Disable editing of the description of the connections in the connection ListView.

Also replace the integer literals defining the columns for enum to make more readable.
This commit is contained in:
eelke 2019-08-19 19:26:39 +02:00
parent 033d2b3d45
commit e4a43a77bd
2 changed files with 30 additions and 16 deletions

View file

@ -25,7 +25,7 @@ int ConnectionListModel::rowCount(const QModelIndex &parent) const
int ConnectionListModel::columnCount(const QModelIndex &/*parent*/) const
{
return 7;
return ColCount;
}
QVariant ConnectionListModel::data(const QModelIndex &index, int role) const
@ -36,25 +36,25 @@ QVariant ConnectionListModel::data(const QModelIndex &index, int role) const
int col = index.column();
const ConnectionConfig& cfg = m_connections->getConfigByIdx(row);
switch (col) {
case 0:
case Description:
result = makeLongDescription(cfg);
break;
case 1:
case Name:
result = stdStrToQ(cfg.name());
break;
case 2:
case Host:
result = stdStrToQ(cfg.host());
break;
case 3:
case Port:
result = cfg.port();
break;
case 4:
case User:
result = stdStrToQ(cfg.user());
break;
case 5:
case Password:
result = stdStrToQ(cfg.password());
break;
case 6:
case DbName:
result = stdStrToQ(cfg.dbname());
break;
}
@ -77,24 +77,24 @@ bool ConnectionListModel::setData(const QModelIndex &index, const QVariant &valu
result = true;
}
switch (col) {
case 0:
case Description:
break;
case 1:
case Name:
cfg.setName( qStrToStd(value.toString()) );
break;
case 2:
case Host:
cfg.setHost( qStrToStd(value.toString()) );
break;
case 3:
case Port:
cfg.setPort( value.toInt() );
break;
case 4:
case User:
cfg.setUser( qStrToStd(value.toString()) );
break;
case 5:
case Password:
cfg.setPassword( qStrToStd(value.toString()) );
break;
case 6:
case DbName:
cfg.setDbname( qStrToStd(value.toString()) );
break;
}
@ -110,7 +110,9 @@ Qt::ItemFlags ConnectionListModel::flags(const QModelIndex &index) const
Qt::ItemFlags result;
int row = index.row();
if (row >= 0 && row < (int)m_connections->size()) {
result = Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsEnabled;
result = Qt::ItemIsSelectable | Qt::ItemIsEnabled;
if (index.column() != Description)
result |= Qt::ItemIsEditable;
}
return result;
}

View file

@ -18,6 +18,18 @@ class ConnectionList;
class ConnectionListModel : public QAbstractListModel {
Q_OBJECT
public:
enum Columns {
Description,
Name,
Host,
Port,
User,
Password,
DbName,
ColCount
};
ConnectionListModel(ConnectionList *conns, QObject *parent);
ConnectionListModel(const ConnectionListModel&) = delete;
~ConnectionListModel() override;