|
|
#include "bindroutetablemodel.h"
|
|
|
#include "qdebug.h"
|
|
|
|
|
|
BindRouteTableModel::BindRouteTableModel(QObject *parent)
|
|
|
: QAbstractTableModel{parent}
|
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
BindRouteTableModel::~BindRouteTableModel()
|
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
int BindRouteTableModel::getRowCount()
|
|
|
{
|
|
|
return rowCount();
|
|
|
}
|
|
|
|
|
|
void BindRouteTableModel::setBeginResetModel()
|
|
|
{
|
|
|
//重置model数据之前调用beginResetModel,此时会触发modelAboutToBeReset信号
|
|
|
beginResetModel();
|
|
|
}
|
|
|
|
|
|
void BindRouteTableModel::setEndResetModel()
|
|
|
{
|
|
|
//数据设置结束后调用endResetModel,此时会触发modelReset信号
|
|
|
endResetModel();
|
|
|
}
|
|
|
|
|
|
//获取行数
|
|
|
int BindRouteTableModel::rowCount(const QModelIndex &parent) const
|
|
|
{
|
|
|
if(parent.isValid())
|
|
|
{
|
|
|
return 0;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
return routeData.points.size();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
//获取列数
|
|
|
int BindRouteTableModel::columnCount(const QModelIndex &parent) const
|
|
|
{
|
|
|
if(parent.isValid())
|
|
|
{
|
|
|
return 0;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
return m_headData.size();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
//获取单元格数据
|
|
|
QVariant BindRouteTableModel::data(const QModelIndex &index, int role) const
|
|
|
{
|
|
|
if (!index.isValid() || index.column()>=columnCount() || index.row()>=rowCount())
|
|
|
{
|
|
|
return QVariant();
|
|
|
}
|
|
|
|
|
|
if(role==Qt::DisplayRole)
|
|
|
{
|
|
|
switch (index.column()) {
|
|
|
case 0: //航线编号
|
|
|
return routeData.routeNumber;
|
|
|
break;
|
|
|
case 1://航点
|
|
|
return routeData.points.keys().at(index.row());
|
|
|
break;
|
|
|
case 2://lon
|
|
|
return QString::number(routeData.points[index.row()].x(),'f',6);
|
|
|
break;
|
|
|
case 3://lat
|
|
|
return QString::number(routeData.points[index.row()].y(),'f',6);
|
|
|
break;
|
|
|
case 4: //导航高度
|
|
|
{
|
|
|
if(index.row()==0)
|
|
|
{
|
|
|
return QString::number(0,'f',2);
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
// return QString::number(routeData.routeHeight,'f',2);
|
|
|
return QString::number(routeData.points[index.row()].z(),'f',2);
|
|
|
}
|
|
|
break;
|
|
|
}
|
|
|
case 5: //航路特征
|
|
|
{
|
|
|
if(index.row()==rowCount()-1)
|
|
|
{
|
|
|
return "01";
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
return routeData.routeFeatures;
|
|
|
}
|
|
|
break;
|
|
|
}
|
|
|
case 6:
|
|
|
return routeData.bindState;
|
|
|
break;
|
|
|
default:
|
|
|
return QVariant();
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
if(role==Qt::TextAlignmentRole) //对其方式
|
|
|
{
|
|
|
return Qt::AlignCenter; //对齐格式为居中
|
|
|
}
|
|
|
|
|
|
return QVariant();
|
|
|
}
|
|
|
|
|
|
//设置单元格数据
|
|
|
bool BindRouteTableModel::setData(const QModelIndex &index, const QVariant &value, int role)
|
|
|
{
|
|
|
if(role != Qt::EditRole || !index.isValid() || index.row() >= rowCount() || index.column() >= columnCount())
|
|
|
{
|
|
|
return false;
|
|
|
}
|
|
|
if (index.isValid() && role == Qt::EditRole)
|
|
|
{
|
|
|
// strList.replace(index.row(), value.toString());
|
|
|
|
|
|
//通知view调用model中的data渲染界面
|
|
|
emit dataChanged(index, index);
|
|
|
return true;
|
|
|
}
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
//获取表头数据
|
|
|
QVariant BindRouteTableModel::headerData(int section, Qt::Orientation orientation, int role) const
|
|
|
{
|
|
|
//水平表头显示信息
|
|
|
switch (role) {
|
|
|
case Qt::DisplayRole:
|
|
|
if(orientation==Qt::Horizontal && section>=0 && section <= columnCount())
|
|
|
return m_headData.at(section);
|
|
|
break;
|
|
|
default:
|
|
|
break;
|
|
|
}
|
|
|
return QAbstractItemModel::headerData(section,orientation,role);
|
|
|
}
|
|
|
|
|
|
//编辑相关函数
|
|
|
Qt::ItemFlags BindRouteTableModel::flags(const QModelIndex &index) const
|
|
|
{
|
|
|
if (!index.isValid())
|
|
|
{
|
|
|
return Qt::ItemIsEnabled;
|
|
|
}
|
|
|
if(index.column()==4) //设置仅高度列可编辑
|
|
|
{
|
|
|
return QAbstractItemModel::flags(index) | Qt::ItemIsEditable;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
return Qt::ItemIsEnabled;
|
|
|
}
|
|
|
|
|
|
}
|