void ShotGraphicsLayer::setShotModel(ShotModel * shotModel){
emit this->loadProgress(0);
layerRect.
setSize(QSize(1,
1));
int nlocs = 0, xColumn,yColumn,zColumn, lineCol;
int swathCol;
float x_min, x_max,y_min, y_max;
float y_value, x_value;
//float z_value,z_min, z_max;
// get column numbers
xColumn = shotModel->fieldIndex("x");
yColumn = shotModel->fieldIndex("y");
zColumn = shotModel->fieldIndex("z");
lineCol = shotModel->fieldIndex("line");
swathCol = shotModel->fieldIndex("swname");
// copy data
QModelIndex sgi_ndx, temp_y_ndx,row_ndx, line_ndx, swath_ndx;
int progress;
for (int ndx=0; ndx < nlocs; ++ndx) {
progress = (ndx*100)/nlocs;
if(progress%5==0){
emit loadProgress(progress);
}
temp_y_ndx
= shotModel
->index
(ndx,yColumn,
QModelIndex());
line_ndx
= shotModel
->index
(ndx,lineCol,
QModelIndex());
swath_ndx
= shotModel
->index
(ndx,swathCol,
QModelIndex());
x_value = shotModel->data(sgi_ndx,Qt::DisplayRole).toDouble();
y_value = shotModel->data(temp_y_ndx,Qt::DisplayRole).toDouble();
lineVal = shotModel->data(line_ndx,Qt::DisplayRole).toString();
swathVal = shotModel->data(swath_ndx,Qt::DisplayRole).toString();
//z_values[ndx] = shotModel->data(sgi_ndx,Qt::DisplayRole).toDouble();
ShotGraphicsItem * sgi = new ShotGraphicsItem(this);
sgi->setIndex(row_ndx);
sgi->setPos(x_value,y_value);
ShotGroup temp;
temp.insert(lineVal,sgi);
lineGroup.insert(lineVal,sgi);
if (swathGroup.contains(swathVal)) // if old group, add new multimap to old one.
swathGroup[swathVal] += temp;
else
swathGroup.insert(swathVal,temp);
this->setNumber(ndx+1);
sgi
->setToolTip
(QString("Shot %1").
arg(number
));
if (ndx == 0) {
x_max = x_value;
x_min = x_value;
y_max = y_value;
y_min = y_value;
} else {
x_min = std::min(x_min,x_value);
y_min = std::min(y_min,y_value);
x_max = std::max(x_max,x_value);
y_max = std::max(y_max,y_value);
}
sgi->setRect(rect);
if (ndx == 0)
layerRect.setRect(rect.x(),rect.y(),rect.width(),rect.height());
}
layerRect.setRect(x_min,y_min,fabs(x_max-x_min),fabs(y_max-y_min));
emit this->loadProgress(100);
}
void ShotGraphicsLayer::setShotModel(ShotModel * shotModel){
emit this->loadProgress(0);
layerRect.setSize(QSize(1,1));
int nlocs = 0, xColumn,yColumn,zColumn, lineCol;
int swathCol;
QString swathVal, lineVal;
float x_min, x_max,y_min, y_max;
float y_value, x_value;
//float z_value,z_min, z_max;
nlocs = shotModel->rowCount(QModelIndex());
// get column numbers
xColumn = shotModel->fieldIndex("x");
yColumn = shotModel->fieldIndex("y");
zColumn = shotModel->fieldIndex("z");
lineCol = shotModel->fieldIndex("line");
swathCol = shotModel->fieldIndex("swname");
// copy data
QModelIndex sgi_ndx, temp_y_ndx,row_ndx, line_ndx, swath_ndx;
int progress;
for (int ndx=0; ndx < nlocs; ++ndx) {
progress = (ndx*100)/nlocs;
if(progress%5==0){
emit loadProgress(progress);
}
row_ndx = shotModel->index(ndx,0,QModelIndex());
sgi_ndx = shotModel->index(ndx,xColumn,QModelIndex());
temp_y_ndx = shotModel->index(ndx,yColumn,QModelIndex());
line_ndx = shotModel->index(ndx,lineCol,QModelIndex());
swath_ndx = shotModel->index(ndx,swathCol,QModelIndex());
x_value = shotModel->data(sgi_ndx,Qt::DisplayRole).toDouble();
y_value = shotModel->data(temp_y_ndx,Qt::DisplayRole).toDouble();
lineVal = shotModel->data(line_ndx,Qt::DisplayRole).toString();
swathVal = shotModel->data(swath_ndx,Qt::DisplayRole).toString();
//z_values[ndx] = shotModel->data(sgi_ndx,Qt::DisplayRole).toDouble();
ShotGraphicsItem * sgi = new ShotGraphicsItem(this);
sgi->setIndex(row_ndx);
sgi->setPos(x_value,y_value);
ShotGroup temp;
temp.insert(lineVal,sgi);
lineGroup.insert(lineVal,sgi);
if (swathGroup.contains(swathVal)) // if old group, add new multimap to old one.
swathGroup[swathVal] += temp;
else
swathGroup.insert(swathVal,temp);
this->setNumber(ndx+1);
sgi->setToolTip(QString("Shot %1").arg(number));
if (ndx == 0) {
x_max = x_value;
x_min = x_value;
y_max = y_value;
y_min = y_value;
} else {
x_min = std::min(x_min,x_value);
y_min = std::min(y_min,y_value);
x_max = std::max(x_max,x_value);
y_max = std::max(y_max,y_value);
}
QRectF rect(0,0,25,25);
sgi->setRect(rect);
if (ndx == 0)
layerRect.setRect(rect.x(),rect.y(),rect.width(),rect.height());
}
layerRect.setRect(x_min,y_min,fabs(x_max-x_min),fabs(y_max-y_min));
emit this->loadProgress(100);
}
To copy to clipboard, switch view to plain text mode
Bookmarks