优化合并单元格的json属性加载方法
This commit is contained in:
parent
4fb6c50b53
commit
2e55985bc8
|
|
@ -276,11 +276,35 @@ void FormHead::updateJsonInfo(QJsonObject headObjInfo)
|
|||
//展示所有单元格
|
||||
void FormHead::DisplayItems(QJsonArray itemsArray)
|
||||
{
|
||||
QMap<int, int> mapItems;
|
||||
|
||||
int id = 0;
|
||||
int iCount = itemsArray.size();
|
||||
for(int i=0; i<iCount; i++)
|
||||
{
|
||||
QJsonValue itemValue = itemsArray[i];
|
||||
|
||||
QJsonObject itemObj = itemValue.toObject();
|
||||
//
|
||||
if (itemObj.contains("id"))
|
||||
{
|
||||
QJsonValue value = itemObj.value("id");
|
||||
if (value.isDouble()) {
|
||||
id = value.toInt();
|
||||
qDebug() << "id:" << QString::number(id);
|
||||
//
|
||||
mapItems.insert(id, i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for(int id=0; id<iCount; id++)
|
||||
{
|
||||
if(mapItems.contains(id))
|
||||
{
|
||||
int iNum = mapItems.value(id);
|
||||
QJsonValue itemValue = itemsArray[iNum];
|
||||
|
||||
QJsonObject itemObj = itemValue.toObject();
|
||||
int col=-1;
|
||||
int row=-1;
|
||||
|
|
@ -406,6 +430,41 @@ void FormHead::DisplayItems(QJsonArray itemsArray)
|
|||
ChangHeadItemProperty(row, col, imagePath, colWidth_Img*g_dPixelPerCm, rowHeight_Img*g_dPixelPerCm);
|
||||
}
|
||||
|
||||
//合并单元格
|
||||
int rowSpan = 1;
|
||||
int colSpan = 1;
|
||||
if (itemObj.contains("rowSpan"))
|
||||
{
|
||||
QJsonValue value = itemObj.value("rowSpan");
|
||||
if (value.isDouble()) {
|
||||
rowSpan = value.toInt();
|
||||
qDebug() << "rowSpan:" << QString::number(rowSpan);
|
||||
}
|
||||
}
|
||||
if (itemObj.contains("columnSpan"))
|
||||
{
|
||||
QJsonValue value = itemObj.value("columnSpan");
|
||||
if (value.isDouble()) {
|
||||
colSpan = value.toInt();
|
||||
qDebug() << "colSpan:" << QString::number(colSpan);
|
||||
}
|
||||
}
|
||||
if(rowSpan > 1 || colSpan > 1)
|
||||
{
|
||||
int rowSpanCurrent = 0;
|
||||
int columnSpanCurrent = 0;
|
||||
rowSpanCurrent = ui->tableWidget->rowSpan(row, col);
|
||||
columnSpanCurrent = ui->tableWidget->columnSpan(row, col);
|
||||
if(rowSpanCurrent > 1 || columnSpanCurrent > 1)
|
||||
{
|
||||
//已经合并过,不再合并
|
||||
}
|
||||
else {
|
||||
//合并单元格
|
||||
ui->tableWidget->setSpan(row, col, rowSpan, colSpan);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -474,6 +533,7 @@ QJsonObject FormHead::makeJson()
|
|||
rootObj["iRows"] = rowCount;
|
||||
rootObj["iCols"] = columnCount;
|
||||
//
|
||||
int id=0;
|
||||
QJsonArray subcaseArray;
|
||||
for(int col=0; col<columnCount; col++)
|
||||
{
|
||||
|
|
@ -482,18 +542,20 @@ QJsonObject FormHead::makeJson()
|
|||
QTableWidgetItem* item = ui->tableWidget->item(row, col);
|
||||
|
||||
QJsonObject formHeadObj;
|
||||
formHeadObj["id"] = id;
|
||||
formHeadObj["row"] = row;
|
||||
formHeadObj["col"] = col;
|
||||
id++;
|
||||
if(item)
|
||||
{
|
||||
//图例
|
||||
QString imagePath = "";
|
||||
//图头, 图例宽高
|
||||
double m_colWidth_Img = 1;
|
||||
double m_rowHeight_Img = 1;
|
||||
double my_colWidth_Img = 1;
|
||||
double my_rowHeight_Img = 1;
|
||||
//图头, 行高、列宽
|
||||
double m_colWidth = 1;
|
||||
double m_rowHeight = 1;
|
||||
double my_colWidth = 1;
|
||||
double my_rowHeight = 1;
|
||||
|
||||
QVariant bgData = item->data(Qt::UserRole+1); // 我们约定用这个角色存储图片路径
|
||||
if (bgData.isValid()) {
|
||||
|
|
@ -502,28 +564,36 @@ QJsonObject FormHead::makeJson()
|
|||
//图例宽
|
||||
QVariant colWidth_Img = item->data(Qt::UserRole+2);
|
||||
if (colWidth_Img.isValid()) {
|
||||
m_colWidth_Img = colWidth_Img.toDouble();
|
||||
my_colWidth_Img = colWidth_Img.toDouble();
|
||||
}
|
||||
//图例高
|
||||
QVariant rowHeight_Img = item->data(Qt::UserRole+3);
|
||||
if (rowHeight_Img.isValid()) {
|
||||
m_rowHeight_Img = rowHeight_Img.toDouble();
|
||||
my_rowHeight_Img = rowHeight_Img.toDouble();
|
||||
}
|
||||
|
||||
//行高、列宽
|
||||
m_colWidth = ui->tableWidget->columnWidth(col)/g_dPixelPerCm;
|
||||
m_rowHeight = ui->tableWidget->rowHeight(row)/g_dPixelPerCm;
|
||||
my_colWidth = ui->tableWidget->columnWidth(col)/g_dPixelPerCm;
|
||||
my_rowHeight = ui->tableWidget->rowHeight(row)/g_dPixelPerCm;
|
||||
|
||||
int rowSpan = 0;
|
||||
int columnSpan = 0;
|
||||
rowSpan = ui->tableWidget->rowSpan(row, col);
|
||||
columnSpan = ui->tableWidget->columnSpan(row, col);
|
||||
|
||||
//----------------
|
||||
formHeadObj["imagePath"] = imagePath;
|
||||
formHeadObj["colWidth_Img"] = m_colWidth_Img;
|
||||
formHeadObj["rowHeight_Img"] = m_rowHeight_Img;
|
||||
formHeadObj["colWidth_Img"] = my_colWidth_Img;
|
||||
formHeadObj["rowHeight_Img"] = my_rowHeight_Img;
|
||||
formHeadObj["backColor"] = item->background().color().name();//背景颜色
|
||||
formHeadObj["text"] = item->text();
|
||||
formHeadObj["Font"] = item->font().toString();
|
||||
formHeadObj["FontColor"] = item->foreground().color().name();
|
||||
formHeadObj["colWidth"] = m_colWidth;
|
||||
formHeadObj["rowHeight"] = m_rowHeight;
|
||||
formHeadObj["colWidth"] = my_colWidth;
|
||||
formHeadObj["rowHeight"] = my_rowHeight;
|
||||
formHeadObj["rowSpan"] = rowSpan;
|
||||
formHeadObj["columnSpan"] = columnSpan;
|
||||
|
||||
}
|
||||
subcaseArray.append(formHeadObj);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user