Connection manager, editing working, hooked up more widgets.
This commit is contained in:
parent
c235169304
commit
30dbc59e41
3 changed files with 66 additions and 14 deletions
|
|
@ -67,7 +67,7 @@ int ConnectionListModel::rowCount(const QModelIndex &parent) const
|
||||||
|
|
||||||
int ConnectionListModel::columnCount(const QModelIndex &/*parent*/) const
|
int ConnectionListModel::columnCount(const QModelIndex &/*parent*/) const
|
||||||
{
|
{
|
||||||
return 2;
|
return 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant ConnectionListModel::data(const QModelIndex &index, int role) const
|
QVariant ConnectionListModel::data(const QModelIndex &index, int role) const
|
||||||
|
|
@ -76,17 +76,60 @@ QVariant ConnectionListModel::data(const QModelIndex &index, int role) const
|
||||||
if (role == Qt::DisplayRole || role == Qt::EditRole) {
|
if (role == Qt::DisplayRole || role == Qt::EditRole) {
|
||||||
int row = index.row();
|
int row = index.row();
|
||||||
int col = index.column();
|
int col = index.column();
|
||||||
// if (col == 0) {
|
const ConnectionConfig& cfg = m_connections.at(row);
|
||||||
result = makeLongDescription(m_connections.at(row));
|
switch (col) {
|
||||||
// }
|
case 0:
|
||||||
//else {
|
result = makeLongDescription(cfg);
|
||||||
//result = QString("other col");
|
break;
|
||||||
//}
|
case 1:
|
||||||
|
result = stdStrToQ(cfg.description());
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
result = stdStrToQ(cfg.host());
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
result = cfg.port();
|
||||||
|
break;
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool ConnectionListModel::setData(const QModelIndex &index, const QVariant &value, int role)
|
||||||
|
{
|
||||||
|
|
||||||
|
if (role == Qt::EditRole) {
|
||||||
|
int row = index.row();
|
||||||
|
int col = index.column();
|
||||||
|
ConnectionConfig& cfg = m_connections.at(row);
|
||||||
|
switch (col) {
|
||||||
|
case 0:
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
cfg.setDescription( qStrToStd(value.toString()) );
|
||||||
|
emit dataChanged(index, index);
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
cfg.setHost( qStrToStd(value.toString()) );
|
||||||
|
emit dataChanged(index, index);
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
cfg.setPort( value.toInt() );
|
||||||
|
emit dataChanged(index, index);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
Qt::ItemFlags ConnectionListModel::flags(const QModelIndex &index) const
|
||||||
|
{
|
||||||
|
return Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsEnabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
QString ConnectionListModel::makeLongDescription(const ConnectionConfig &cfg)
|
QString ConnectionListModel::makeLongDescription(const ConnectionConfig &cfg)
|
||||||
{
|
{
|
||||||
std::string result(cfg.description());
|
std::string result(cfg.description());
|
||||||
|
|
@ -94,8 +137,18 @@ QString ConnectionListModel::makeLongDescription(const ConnectionConfig &cfg)
|
||||||
result += cfg.user();
|
result += cfg.user();
|
||||||
result += "@";
|
result += "@";
|
||||||
result += cfg.host();
|
result += cfg.host();
|
||||||
|
result += ":";
|
||||||
|
result += std::to_string(cfg.port());
|
||||||
result += "/";
|
result += "/";
|
||||||
result += cfg.dbname();
|
result += cfg.dbname();
|
||||||
result += ")";
|
result += ")";
|
||||||
return stdStrToQ(result);
|
return stdStrToQ(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ConnectionListModel::add(const ConnectionConfig &cfg)
|
||||||
|
{
|
||||||
|
m_connections.push_back(cfg);
|
||||||
|
auto idx = createIndex(m_connections.size()-1, 0);
|
||||||
|
emit dataChanged(idx, idx);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -18,13 +18,10 @@ public:
|
||||||
virtual int columnCount(const QModelIndex &/*parent*/) const override;
|
virtual int columnCount(const QModelIndex &/*parent*/) const override;
|
||||||
virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
|
virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
|
||||||
// virtual QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
|
// virtual QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
|
||||||
|
virtual bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override;
|
||||||
|
virtual Qt::ItemFlags flags(const QModelIndex &index) const override;
|
||||||
|
|
||||||
void add(const ConnectionConfig &cfg)
|
void add(const ConnectionConfig &cfg);
|
||||||
{
|
|
||||||
m_connections.push_back(cfg);
|
|
||||||
auto idx = createIndex(m_connections.size()-1, 0);
|
|
||||||
emit dataChanged(idx, idx);
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
using t_Connections = std::vector<ConnectionConfig>;
|
using t_Connections = std::vector<ConnectionConfig>;
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,9 @@ ConnectionManagerWindow::ConnectionManagerWindow(QWidget *parent)
|
||||||
|
|
||||||
m_mapper = new QDataWidgetMapper(this);
|
m_mapper = new QDataWidgetMapper(this);
|
||||||
m_mapper->setModel(m_listModel);
|
m_mapper->setModel(m_listModel);
|
||||||
m_mapper->addMapping(ui->edtUser, 1);
|
m_mapper->addMapping(ui->edtName, 1);
|
||||||
|
m_mapper->addMapping(ui->edtHost, 2);
|
||||||
|
m_mapper->addMapping(ui->spinPort, 3);
|
||||||
m_mapper->toFirst();
|
m_mapper->toFirst();
|
||||||
|
|
||||||
connect(ui->listView->selectionModel(),
|
connect(ui->listView->selectionModel(),
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue