1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117
|
/*
* $Id: ConnectionsModel.cpp 13 2010-09-17 09:12:39Z werner $
*
* File: ConnectionsModel.cpp
* Author: Werner Jaeger
*
* Created on July 18, 2010, 5:30 PM
*
* Copyright 2010 Werner Jaeger.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "ConnectionsModel.h"
#include "ConnectionState.h"
#include "settings/ConnectionSettings.h"
#include "dialogs/ConnectionEditorDialog.h"
ConnectionsModel::ConnectionsModel(QObject* pParent) : QAbstractTableModel(pParent), m_pSettings(new ConnectionSettings())
{
}
ConnectionsModel::~ConnectionsModel()
{
delete m_pSettings;
}
bool ConnectionsModel::isWriteable() const
{
return(m_pSettings->isWriteable());
}
int ConnectionsModel::rowCount(const QModelIndex& /* parent */) const
{
return(m_pSettings->connections());
}
int ConnectionsModel::columnCount(const QModelIndex& /* parent */) const
{
return(1);
}
QVariant ConnectionsModel::data(const QModelIndex& index, int iRole) const
{
QVariant ret;
if (index.isValid())
{
if (iRole == Qt::DisplayRole)
ret = m_pSettings->connection(index.row());
else if (iRole == Qt::TextAlignmentRole)
ret = int(Qt::AlignLeft | Qt::AlignVCenter);
}
return(ret);
}
QVariant ConnectionsModel::headerData(int iSection, Qt::Orientation orientation, int iRole) const
{
QVariant ret;
if (iRole == Qt::DisplayRole && iSection == 0 && orientation == Qt::Horizontal)
ret = tr("Name");
return(ret);
}
ConnectionsModel::Result ConnectionsModel::addRow(const QString& strName, const QModelIndex& parent)
{
Result result(ConnectionsModel::Ok);
const int iRow = m_pSettings->connections();
beginInsertRows(parent, iRow, iRow);
switch (m_pSettings->addConnection(strName))
{
case ConnectionSettings::DuplicateName:
result = ConnectionsModel::DuplicateName;
break;
case ConnectionSettings::InvalidName:
result = ConnectionsModel::InvalidName;
break;
case ConnectionSettings::ReadOnly:
result = ConnectionsModel::ReadOnly;
break;
case ConnectionSettings::Ok:
result = ConnectionsModel::Ok;
break;
}
endInsertRows();
return(result);
}
bool ConnectionsModel::removeRow(int iRow, const QModelIndex& parent)
{
bool fRet;
beginRemoveRows(parent, iRow, iRow);
fRet = m_pSettings->removeConnection(iRow);
endRemoveRows();
return(fRet);
}
|