forked from blue/squawk
cleanup some warnings suppression
This commit is contained in:
parent
5fbb03fc46
commit
23ec80ccba
26 changed files with 630 additions and 924 deletions
|
@ -18,6 +18,7 @@
|
|||
|
||||
#include "accounts.h"
|
||||
#include "shared/icons.h"
|
||||
#include "shared/defines.h"
|
||||
|
||||
#include <QIcon>
|
||||
#include <QDebug>
|
||||
|
@ -26,32 +27,24 @@ std::deque<QString> Models::Accounts::columns = {"Name", "Server", "State", "Err
|
|||
|
||||
Models::Accounts::Accounts(QObject* parent):
|
||||
QAbstractTableModel(parent),
|
||||
accs()
|
||||
{
|
||||
accs() {}
|
||||
|
||||
}
|
||||
Models::Accounts::~Accounts() {}
|
||||
|
||||
Models::Accounts::~Accounts()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
QVariant Models::Accounts::data (const QModelIndex& index, int role) const
|
||||
{
|
||||
QVariant Models::Accounts::data (const QModelIndex& index, int role) const {
|
||||
QVariant answer;
|
||||
switch (role) {
|
||||
case Qt::DisplayRole:
|
||||
answer = accs[index.row()]->data(index.column());
|
||||
break;
|
||||
case Qt::DecorationRole:
|
||||
if (index.column() == 2) {
|
||||
if (index.column() == 2)
|
||||
answer = Shared::connectionStateIcon(accs[index.row()]->getState());
|
||||
}
|
||||
break;
|
||||
case Qt::ForegroundRole:
|
||||
if (!accs[index.row()]->getActive()) {
|
||||
if (!accs[index.row()]->getActive())
|
||||
answer = qApp->palette().brush(QPalette::Disabled, QPalette::Text);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
@ -59,53 +52,46 @@ QVariant Models::Accounts::data (const QModelIndex& index, int role) const
|
|||
return answer;
|
||||
}
|
||||
|
||||
int Models::Accounts::columnCount ( const QModelIndex& parent ) const
|
||||
{
|
||||
int Models::Accounts::columnCount (const QModelIndex& parent) const {
|
||||
SHARED_UNUSED(parent);
|
||||
return columns.size();
|
||||
}
|
||||
|
||||
int Models::Accounts::rowCount ( const QModelIndex& parent ) const
|
||||
{
|
||||
int Models::Accounts::rowCount (const QModelIndex& parent) const {
|
||||
SHARED_UNUSED(parent);
|
||||
return accs.size();
|
||||
}
|
||||
|
||||
unsigned int Models::Accounts::size() const
|
||||
{
|
||||
unsigned int Models::Accounts::size() const {
|
||||
return rowCount(QModelIndex());
|
||||
}
|
||||
|
||||
unsigned int Models::Accounts::activeSize() const
|
||||
{
|
||||
unsigned int Models::Accounts::activeSize() const {
|
||||
unsigned int size = 0;
|
||||
for (const Models::Account* acc : accs) {
|
||||
if (acc->getActive()) {
|
||||
if (acc->getActive())
|
||||
++size;
|
||||
}
|
||||
}
|
||||
|
||||
return size;
|
||||
}
|
||||
|
||||
QVariant Models::Accounts::headerData(int section, Qt::Orientation orientation, int role) const
|
||||
{
|
||||
if (role == Qt::DisplayRole && orientation == Qt::Horizontal) {
|
||||
QVariant Models::Accounts::headerData(int section, Qt::Orientation orientation, int role) const {
|
||||
if (role == Qt::DisplayRole && orientation == Qt::Horizontal)
|
||||
return tr(columns[section].toLatin1());
|
||||
}
|
||||
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
|
||||
void Models::Accounts::addAccount(Account* account)
|
||||
{
|
||||
void Models::Accounts::addAccount(Account* account) {
|
||||
beginInsertRows(QModelIndex(), accs.size(), accs.size());
|
||||
int index = 0;
|
||||
std::deque<Account*>::const_iterator before = accs.begin();
|
||||
while (before != accs.end()) {
|
||||
Account* bfr = *before;
|
||||
if (bfr->getDisplayedName() > account->getDisplayedName()) {
|
||||
if (bfr->getDisplayedName() > account->getDisplayedName())
|
||||
break;
|
||||
}
|
||||
index++;
|
||||
|
||||
before++;
|
||||
}
|
||||
|
||||
|
@ -117,25 +103,23 @@ void Models::Accounts::addAccount(Account* account)
|
|||
emit changed();
|
||||
}
|
||||
|
||||
void Models::Accounts::onAccountChanged(Item* item, int row, int col)
|
||||
{
|
||||
if (row < 0) {
|
||||
void Models::Accounts::onAccountChanged(Item* item, int row, int col) {
|
||||
if (row < 0)
|
||||
return;
|
||||
}
|
||||
|
||||
if (static_cast<std::deque<Models::Account*>::size_type>(row) < accs.size()) {
|
||||
Account* acc = getAccount(row);
|
||||
if (item != acc) {
|
||||
if (item != acc)
|
||||
return; //it means the signal is emitted by one of accounts' children, not exactly him, this model has no interest in that
|
||||
}
|
||||
|
||||
if (col == 0) {
|
||||
int newRow = 0;
|
||||
std::deque<Account*>::const_iterator before = accs.begin();
|
||||
while (before != accs.end()) {
|
||||
Item* bfr = *before;
|
||||
if (bfr->getDisplayedName() > item->getDisplayedName()) {
|
||||
if (bfr->getDisplayedName() > item->getDisplayedName())
|
||||
break;
|
||||
}
|
||||
|
||||
newRow++;
|
||||
before++;
|
||||
}
|
||||
|
@ -152,20 +136,18 @@ void Models::Accounts::onAccountChanged(Item* item, int row, int col)
|
|||
}
|
||||
}
|
||||
|
||||
if (col < columnCount(QModelIndex())) {
|
||||
if (col < columnCount(QModelIndex()))
|
||||
emit dataChanged(createIndex(row, col), createIndex(row, col));
|
||||
}
|
||||
|
||||
emit changed();
|
||||
}
|
||||
}
|
||||
|
||||
Models::Account * Models::Accounts::getAccount(int index)
|
||||
{
|
||||
Models::Account * Models::Accounts::getAccount(int index) {
|
||||
return accs[index];
|
||||
}
|
||||
|
||||
void Models::Accounts::removeAccount(int index)
|
||||
{
|
||||
void Models::Accounts::removeAccount(int index) {
|
||||
Account* account = accs[index];
|
||||
beginRemoveRows(QModelIndex(), index, index);
|
||||
disconnect(account, &Account::childChanged, this, &Accounts::onAccountChanged);
|
||||
|
@ -175,14 +157,13 @@ void Models::Accounts::removeAccount(int index)
|
|||
emit sizeChanged(accs.size());
|
||||
}
|
||||
|
||||
std::deque<QString> Models::Accounts::getActiveNames() const
|
||||
{
|
||||
std::deque<QString> Models::Accounts::getActiveNames() const {
|
||||
std::deque<QString> res;
|
||||
|
||||
for (const Models::Account* acc : accs) {
|
||||
if (acc->getActive()) {
|
||||
if (acc->getActive())
|
||||
res.push_back(acc->getName());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return res;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue