Builds on windows again
This commit is contained in:
parent
33cf39b799
commit
bebb3391c3
160 changed files with 138 additions and 117 deletions
|
|
@ -1,182 +0,0 @@
|
|||
#include "ConnectionListModel.h"
|
||||
#include "ConnectionList.h"
|
||||
#include "ScopeGuard.h"
|
||||
#include "util.h"
|
||||
|
||||
#include <botan/cryptobox.h>
|
||||
|
||||
|
||||
ConnectionListModel::ConnectionListModel(ConnectionList *conns, QObject *parent)
|
||||
: QAbstractListModel(parent)
|
||||
, m_connections(conns)
|
||||
{
|
||||
}
|
||||
|
||||
ConnectionListModel::~ConnectionListModel()
|
||||
{
|
||||
}
|
||||
|
||||
int ConnectionListModel::rowCount(const QModelIndex &parent) const
|
||||
{
|
||||
int result = 0;
|
||||
if (parent == QModelIndex()) {
|
||||
result = m_connections->size();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
int ConnectionListModel::columnCount(const QModelIndex &/*parent*/) const
|
||||
{
|
||||
return 7;
|
||||
}
|
||||
|
||||
QVariant ConnectionListModel::data(const QModelIndex &index, int role) const
|
||||
{
|
||||
QVariant result;
|
||||
if (role == Qt::DisplayRole || role == Qt::EditRole) {
|
||||
int row = index.row();
|
||||
int col = index.column();
|
||||
const ConnectionConfig& cfg = m_connections->getConfigByIdx(row);
|
||||
switch (col) {
|
||||
case 0:
|
||||
result = makeLongDescription(cfg);
|
||||
break;
|
||||
case 1:
|
||||
result = stdStrToQ(cfg.name());
|
||||
break;
|
||||
case 2:
|
||||
result = stdStrToQ(cfg.host());
|
||||
break;
|
||||
case 3:
|
||||
result = cfg.port();
|
||||
break;
|
||||
case 4:
|
||||
result = stdStrToQ(cfg.user());
|
||||
break;
|
||||
case 5:
|
||||
result = stdStrToQ(cfg.password());
|
||||
break;
|
||||
case 6:
|
||||
result = stdStrToQ(cfg.dbname());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
bool ConnectionListModel::setData(const QModelIndex &index, const QVariant &value, int role)
|
||||
{
|
||||
bool result = false;
|
||||
if (role == Qt::EditRole) {
|
||||
int row = index.row();
|
||||
int col = index.column();
|
||||
// auto& elem = m_connections.at(row);
|
||||
// elem.m_dirty = true;
|
||||
// ConnectionConfig& cfg = elem.m_config;
|
||||
ConnectionConfig& cfg = m_connections->getConfigByIdx(row);
|
||||
if (col > 0) {
|
||||
result = true;
|
||||
}
|
||||
switch (col) {
|
||||
case 0:
|
||||
break;
|
||||
case 1:
|
||||
cfg.setName( qStrToStd(value.toString()) );
|
||||
break;
|
||||
case 2:
|
||||
cfg.setHost( qStrToStd(value.toString()) );
|
||||
break;
|
||||
case 3:
|
||||
cfg.setPort( value.toInt() );
|
||||
break;
|
||||
case 4:
|
||||
cfg.setUser( qStrToStd(value.toString()) );
|
||||
break;
|
||||
case 5:
|
||||
cfg.setPassword( qStrToStd(value.toString()) );
|
||||
break;
|
||||
case 6:
|
||||
cfg.setDbname( qStrToStd(value.toString()) );
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (result) {
|
||||
emit dataChanged(index, index);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
QString ConnectionListModel::makeLongDescription(const ConnectionConfig &cfg)
|
||||
{
|
||||
std::string result(cfg.name());
|
||||
result += " (";
|
||||
result += cfg.user();
|
||||
result += "@";
|
||||
result += cfg.host();
|
||||
result += ":";
|
||||
result += std::to_string(cfg.port());
|
||||
result += "/";
|
||||
result += cfg.dbname();
|
||||
result += ")";
|
||||
return stdStrToQ(result);
|
||||
}
|
||||
|
||||
void ConnectionListModel::newItem()
|
||||
{
|
||||
int i = m_connections->createNew();
|
||||
auto idx = createIndex(i, 0);
|
||||
emit dataChanged(idx, idx);
|
||||
}
|
||||
|
||||
Expected<ConnectionConfig> ConnectionListModel::get(int row)
|
||||
{
|
||||
if (row >= 0 && row < (int)m_connections->size()) {
|
||||
return m_connections->getConfigByIdx(row);
|
||||
}
|
||||
else {
|
||||
return Expected<ConnectionConfig>::fromException(std::out_of_range("Invalid row"));
|
||||
}
|
||||
}
|
||||
|
||||
//void ConnectionListModel::del(const int idx)
|
||||
bool ConnectionListModel::removeRows(int row, int count, const QModelIndex &parent)
|
||||
{
|
||||
bool result = false;
|
||||
if (row >= 0 && row < (int)m_connections->size()) {
|
||||
|
||||
beginRemoveRows(parent, row, row + count -1);
|
||||
SCOPE_EXIT { endRemoveRows(); };
|
||||
|
||||
m_connections->remove(row, count);
|
||||
result = true;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
//void ConnectionListModel::load()
|
||||
//{
|
||||
// m_connections->load();
|
||||
//}
|
||||
|
||||
void ConnectionListModel::save()
|
||||
{
|
||||
m_connections->save();
|
||||
}
|
||||
|
||||
void ConnectionListModel::save(int index)
|
||||
{
|
||||
m_connections->save(index);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue