#134 Delete server/network implemented

master
Tomatix 3 years ago
parent ff81cabbb3
commit 50abd64932
  1. 21
      IConfig/IConfigServers.cpp
  2. 1
      IConfig/ServerItem.h
  3. 20
      IConfig/ServerModel.cpp
  4. 2
      IConfig/ServerModel.h

@ -10,6 +10,7 @@
#include "AddServer.h"
#include "ConfigMgr.h"
#include "ServerItem.h"
#include <QMessageBox>
#include <QDebug>
IConfigServers::IConfigServers(QWidget *parent) :
@ -147,5 +148,23 @@ void IConfigServers::on_btnAddServer_clicked()
void IConfigServers::on_btnDeleteSelected_clicked()
{
auto index = ui->servers->currentIndex();
if (!index.isValid())
return;
const auto* item = static_cast<const ServerItem*>(index.internalPointer());
QMessageBox::StandardButton btn;
if (item->isNetwork())
btn = QMessageBox::question(this,
tr("Delete entire network"),
tr("You are about to delete an entire network!\nConfirm deletion of %1?").arg(item->name()));
else
btn = QMessageBox::question(this,
tr("Delete server"),
tr("Confirm deletion of %1?").arg(item->name()));
if (btn == QMessageBox::No)
return;
else
smodel.deleteEntry(index);
}

@ -55,6 +55,7 @@ public:
ServerItem* parent() const { return m_parent; }
int row() const { return m_row; }
void incRow() { ++m_row; }
void decRow() { --m_row; }
QList<ServerItem>& children() { return m_children; }

@ -253,6 +253,26 @@ void ServerModel::addNetwork(const QString& name, const QString& address, const
);
}
void ServerModel::deleteEntry(const QModelIndex& index)
{
auto* item = static_cast<ServerItem*>(index.internalPointer());
auto* parent = item->parent();
QList<ServerItem>* items{};
if (parent == nullptr)
items = &m_items;
else
items = &(parent->children());
beginRemoveRows(index.parent(), index.row(), index.row());
items->removeAt(item->row());
for (int i = item->row(); i < items->count(); ++i)
(*items)[i].decRow();
endRemoveRows();
}
QStringList ServerModel::getNetworks() const
{
QStringList networks;

@ -49,6 +49,8 @@ public:
/// Add a network to the model.
void addNetwork(const QString& name, const QString& address, const QString& password, bool isSsl);
void deleteEntry(const QModelIndex& index);
QStringList getNetworks() const;
QList<QModelIndex> getEditorColumns();

Loading…
Cancel
Save