Brief description of class still missing. More...
#include <DistanceItem.h>
Signals | |
| void | distanceChanged () |
| void | pointNameChanged () |
Public Member Functions | |
| void | add () |
| void | addPointName (const QString &n) |
| virtual int | columnCount (const QModelIndex &parent) const |
| virtual QVariant | data (const QModelIndex &index, int role) const |
| DistanceItem (QObject *parent=0) | |
| const QList< Distance > & | distances () const |
| Qt::ItemFlags | flags (const QModelIndex &index) const |
| virtual QVariant | headerData (int section, Qt::Orientation orientation, int role) const |
| bool | load (const QString &fileName) |
| const QStringList & | pointNames () const |
| void | remove (int index) |
| virtual int | rowCount (const QModelIndex &parent) const |
| bool | save (const QString &fileName) const |
| virtual bool | setData (const QModelIndex &index, const QVariant &value, int role=Qt::EditRole) |
| ~DistanceItem () | |
Brief description of class still missing.
Full description of class still missing
| DistanceItem::DistanceItem | ( | QObject * | parent = 0 | ) |
| void DistanceItem::add | ( | ) |
References Distance::node1(), Distance::node2(), TRACE, and Distance::value().
{
TRACE;
int n=_distances.count();
beginInsertRows(QModelIndex(), n, n);
if(n==0) {
if(_pointNames.count()>=2) {
_distances.append(Distance(_pointNames.at(0), _pointNames.at(1), 0.0));
} else {
_distances.append(Distance());
}
} else if(n==1 || _distances.at(n-1).node1()==_distances.at(n-2).node1()) {
const Distance& d=_distances.last();
_distances.append(Distance(d.node1(), nextPointName(d.node2()), d.value()));
} else if(_distances.at(n-1).node1()==_distances.at(n-2).node2()) {
const Distance& d=_distances.last();
_distances.append(Distance(d.node2(), nextPointName(d.node2()), d.value()));
} else if(n>=_pointNames.count()-1 && _distances.at(n-1).node2()==nextPointName(_distances.at(n-1).node1())) {
const Distance& d=_distances.last();
_distances.append(Distance(d.node2(), nextPointName(d.node2()), d.value()));
} else {
const Distance& d=_distances.last();
_distances.append(Distance(d));
}
endInsertRows();
}
| void DistanceItem::addPointName | ( | const QString & | n | ) | [inline] |
Referenced by DistanceWidget::setStations().
{_pointNames.append(n);}
| int DistanceItem::columnCount | ( | const QModelIndex & | parent | ) | const [virtual] |
| QVariant DistanceItem::data | ( | const QModelIndex & | index, |
| int | role | ||
| ) | const [virtual] |
References Distance::node1(), Distance::node2(), TRACE, and Distance::value().
| void DistanceItem::distanceChanged | ( | ) | [signal] |
Referenced by setData().
| const QList<Distance>& DistanceItem::distances | ( | ) | const [inline] |
{return _distances;}
| Qt::ItemFlags DistanceItem::flags | ( | const QModelIndex & | index | ) | const |
| QVariant DistanceItem::headerData | ( | int | section, |
| Qt::Orientation | orientation, | ||
| int | role | ||
| ) | const [virtual] |
| bool DistanceItem::load | ( | const QString & | fileName | ) |
References Distance::fromString(), MSG_ID, and QGpCoreTools::tr().
{
QFile f(fileName);
if(!f.open(QIODevice::ReadOnly)) {
Message::warning(MSG_ID, tr("Loading distances"), tr("Cannot open file %1 for reading").arg(fileName));
return false;
}
QTextStream s(&f);
while(!s.atEnd()) {
QString line=s.readLine();
Distance d;
if(d.fromString(StringSection(line))) {
int n=_distances.count();
beginInsertRows(QModelIndex(), n, n);
_distances.append(d);
endInsertRows();
}
}
return true;
}
| void DistanceItem::pointNameChanged | ( | ) | [signal] |
Referenced by setData().
| const QStringList& DistanceItem::pointNames | ( | ) | const [inline] |
Referenced by DistanceWidget::setStations().
{return _pointNames;}
| void DistanceItem::remove | ( | int | index | ) |
| int DistanceItem::rowCount | ( | const QModelIndex & | parent | ) | const [virtual] |
| bool DistanceItem::save | ( | const QString & | fileName | ) | const |
References QGpCoreTools::endl(), MSG_ID, and QGpCoreTools::tr().
{
QFile f(fileName);
if(!f.open(QIODevice::WriteOnly)) {
Message::warning(MSG_ID, tr("Saving distances"), tr("Cannot open file %1 for writing").arg(fileName));
return false;
}
QTextStream s(&f);
for(QList<Distance>::const_iterator it=_distances.begin(); it!=_distances.end(); it++) {
s << it->toString(20, 'f') << endl;
}
return true;
}
| bool DistanceItem::setData | ( | const QModelIndex & | index, |
| const QVariant & | value, | ||
| int | role = Qt::EditRole |
||
| ) | [virtual] |
References distanceChanged(), pointNameChanged(), Distance::setNode1(), Distance::setNode2(), Distance::setValue(), and TRACE.
{
TRACE;
if(role!=Qt::EditRole) {
return false;
}
Distance& d=_distances[index.row()];
switch(index.column()) {
case 0:
d.setNode1(value.toString());
emit pointNameChanged();
return true;
case 1:
d.setNode2(value.toString());
emit pointNameChanged();
return true;
case 2:
d.setValue(value.toDouble());
emit distanceChanged();
return true;
default:
break;
}
return false;
}