Working on the connection manager.
Made a list model for displaying them in a list. Also added controles to edit the most important properties.
This commit is contained in:
parent
be1892ac52
commit
f5eab84c24
14 changed files with 1100 additions and 9 deletions
89
connectionlistmodel.cpp
Normal file
89
connectionlistmodel.cpp
Normal file
|
|
@ -0,0 +1,89 @@
|
|||
#include "connectionlistmodel.h"
|
||||
#include <QSettings>
|
||||
|
||||
|
||||
inline QString stdStrToQ(const std::string &s)
|
||||
{
|
||||
return QString::fromUtf8(s.c_str());
|
||||
}
|
||||
|
||||
inline std::string qStrToStd(const QString &s)
|
||||
{
|
||||
return std::string(s.toUtf8().data());
|
||||
}
|
||||
|
||||
inline std::string qvarToStdStr(const QVariant &c)
|
||||
{
|
||||
return qStrToStd(c.toString());
|
||||
}
|
||||
|
||||
|
||||
/** Saves a connection configuration.
|
||||
|
||||
Before calling this you may want to call beginGroup.
|
||||
*/
|
||||
void SaveConnectionConfig(QSettings &settings, const ConnectionConfig &cc)
|
||||
{
|
||||
settings.setValue("description", stdStrToQ(cc.description()));
|
||||
settings.setValue("host", stdStrToQ(cc.host()));
|
||||
settings.setValue("hostaddr", stdStrToQ(cc.hostAddr()));
|
||||
settings.setValue("port", cc.port());
|
||||
settings.setValue("user", stdStrToQ(cc.user()));
|
||||
settings.setValue("password", stdStrToQ(cc.password()));
|
||||
settings.setValue("dbname", stdStrToQ(cc.dbname()));
|
||||
settings.setValue("sslmode", (int)cc.sslMode());
|
||||
settings.setValue("sslcert", stdStrToQ(cc.sslCert()));
|
||||
settings.setValue("sslkey", stdStrToQ(cc.sslKey()));
|
||||
settings.setValue("sslrootcert", stdStrToQ(cc.sslRootCert()));
|
||||
settings.setValue("sslcrl", stdStrToQ(cc.sslCrl()));
|
||||
}
|
||||
|
||||
void LoadConnectionConfig(QSettings &settings, ConnectionConfig &cc)
|
||||
{
|
||||
cc.setDescription(qvarToStdStr(settings.value("description")));
|
||||
cc.setHost(qvarToStdStr(settings.value("host")));
|
||||
cc.setHostAddr(qvarToStdStr(settings.value("hostaddr")));
|
||||
cc.setPort(settings.value("port", 5432).toInt());
|
||||
cc.setUser(qvarToStdStr(settings.value("user")));
|
||||
cc.setPassword(qvarToStdStr(settings.value("password")));
|
||||
cc.setDbname(qvarToStdStr(settings.value("dbname")));
|
||||
cc.setSslMode((SslMode)settings.value("sslmode").toInt());
|
||||
cc.setSslCert(qvarToStdStr(settings.value("sslcert")));
|
||||
cc.setSslKey(qvarToStdStr(settings.value("sslkey")));
|
||||
cc.setSslRootCert(qvarToStdStr(settings.value("sslrootcert")));
|
||||
cc.setSslCrl(qvarToStdStr(settings.value("sslcrl")));
|
||||
}
|
||||
|
||||
|
||||
|
||||
ConnectionListModel::ConnectionListModel(QObject *parent)
|
||||
: QAbstractListModel(parent)
|
||||
{}
|
||||
|
||||
int ConnectionListModel::rowCount(const QModelIndex &parent) const
|
||||
{
|
||||
return m_connections.size();
|
||||
}
|
||||
|
||||
QVariant ConnectionListModel::data(const QModelIndex &index, int role) const
|
||||
{
|
||||
QVariant result;
|
||||
if (role == Qt::DisplayRole) {
|
||||
int row = index.row();
|
||||
result = makeLongDescription(m_connections.at(row));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
QString ConnectionListModel::makeLongDescription(const ConnectionConfig &cfg)
|
||||
{
|
||||
std::string result(cfg.description());
|
||||
result += " (";
|
||||
result += cfg.user();
|
||||
result += "@";
|
||||
result += cfg.host();
|
||||
result += "/";
|
||||
result += cfg.dbname();
|
||||
result += ")";
|
||||
return stdStrToQ(result);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue