#include "ccsiteminterface.h" #include "ccscell.h" #include "common_types.h" #include "ccsdatabind.h" #include "QFont" namespace CCS_Report{ CCSCell::CCSCell(int rownum,int colnum,QObject *parent):CCSItemInterface(new CCSCellPrivate(rownum,colnum),parent) { } CCSCell::CCSCell(QObject *parent):CCSItemInterface(new CCSCellPrivate,parent) { } CCSCell::CCSCell(CCSCellPrivate *dd, QObject * parent) :CCSItemInterface(dd, parent) { } CCSCell::~CCSCell() { } CCSBaseItemInterface *CCSCell::createInstance(QObject * parent) const { return new CCSCell(parent); } CCSBaseItemInterface *CCSCell::clone(bool withChildren, bool init) const { CCSCell * newCell = qobject_cast(itemClone()); //newCell->setReportCore(this->reportCore()); if (withChildren) { foreach (CCSBaseItemInterface* item, findChildren(QString(),Qt::FindDirectChildrenOnly)) { if (item->parent() != this) continue; CCSBaseItemInterface * itemCopy = item->clone(true, false); //itemCopy->setReportCore(item->reportCore()); itemCopy->setParent(newCell); itemCopy->setObjectName(item->objectName()); } } return newCell; } void CCSCell::exeFunction(ReportFunPara& arg) { if (arg.strArgName.count()==0) return; foreach (CCS_Report::CCSBaseItemInterface* item, paragraphs()) { item->exeFunction(arg); } } void CCSCell::SetPostion(int row,int col) { Q_D(CCSCell); d->m_iRowindex = row; d->m_iColindex = col; } int CCSCell::rowindex() const { Q_D(const CCSCell); return d->m_iRowindex; } void CCSCell::SetRowindex(const int &index) { Q_D(CCSCell); d->m_iRowindex = index; } int CCSCell::colindex() const { Q_D(const CCSCell); return d->m_iColindex; } void CCSCell::SetColindex(const int &index) { Q_D(CCSCell); d->m_iColindex = index; } int CCSCell::rowspan() const { Q_D(const CCSCell); return d->m_iRowspan; } void CCSCell::SetRowspan(const int &span) { Q_D(CCSCell); d->m_iRowspan = span; } int CCSCell::colspan() const { Q_D(const CCSCell); return d->m_iColspan; } void CCSCell::SetColspan(const int &span) { Q_D(CCSCell); d->m_iColspan = span; } bool CCSCell::dynamic() const { Q_D(const CCSCell); return d->m_bDynamic; } void CCSCell::SetDynamic(const bool& dyn) { Q_D(CCSCell); d->m_bDynamic = dyn; } bool CCSCell::tranrow() const { Q_D(const CCSCell); return d->m_bTranRow; } void CCSCell::SetTranrow(const bool& bFlag) { Q_D(CCSCell); d->m_bTranRow = bFlag; } bool CCSCell::group() const { Q_D(const CCSCell); return d->m_bGroup; } void CCSCell::SetGroup(const bool& bFlag) { Q_D(CCSCell); d->m_bGroup = bFlag; } int CCSCell::cellframe() const { Q_D(const CCSCell); return d->m_cellframe; } void CCSCell::SetCellFrame(const int& bFlag) { Q_D(CCSCell); d->m_cellframe = bFlag; } qreal CCSCell::padding() const { Q_D(const CCSCell); return d->m_qPadding; } void CCSCell::SetPadding(const qreal& value) { Q_D(CCSCell); d->m_qPadding = value; } CCS_Report::CCSBaseItemInterface* CCSCell::paragraph() { return findChild(QString(),Qt::FindDirectChildrenOnly); } QList CCSCell::paragraphs() { return findChildren(QString(),Qt::FindDirectChildrenOnly); } CCSBaseItemInterface * CCSCell::itemClone() const { Q_D(const CCSCell); return new CCSCell(new CCSCellPrivate(*d), parent()); // CCSCell* cell = new CCSCell(); // cell->setParent(this->parent()); // cell->setReportCore(this->reportCore()); // foreach (CCS_Report::CCSBaseItemInterface* item, findChildren(QString(),Qt::FindDirectChildrenOnly)) { // CCS_Report::CCSBaseItemInterface* hh = item->clone(); // hh->setParent(cell); // } // return cell; // CCSBaseItemInterface * CCSCell::itemClone() const //{ // Q_D(const CCSCell); // return new CCSCell(new CCSCellPrivate(*d), parent()); //} } void CCSCell::SetValue(const QString &text,int iPos) { foreach (CCS_Report::CCSBaseItemInterface* item,findChildren(QString(),Qt::FindDirectChildrenOnly)) { item->SetValue(text); } } QString CCSCell::GetFieldNameByTable(QString tablename) { //ReportFunPara para(FieldName); ReportFunPara para("fieldname"); QList listpara; if (!(tablename.isEmpty())) listpara.append(tablename); para.listPara = listpara; exeFunction(para); QString strField = para.listRtn.at(0); return strField; } void CCSCell::FillDynamicCell(QList table, QMap>>& mapBindDataMergeInfo, QMap mapColumnMerge) { #ifdef Report_LOG QLOG_INFO() < listBindData = CCS_Report::CCSDataBind::GetDataByFieldT(table, strField); #ifdef Report_LOG QLOG_INFO() < listValue, QMap>>& mapBindDataMergeInfo, QMap mapColumnMerge) { //获取此cell中定义的表的字段名 QString strField = GetFieldNameByTable(); #ifdef Report_LOG QString str = "FillDynamicCell: table count:" + QString::number(listValue.count()) + " Field: " + strField; QLOG_INFO() < listBindData, QMap>>& mapBindDataMergeInfo, QMap mapColumnMerge) { #ifdef Report_LOG QString str = "FillCell: data count:" + QString::number(listBindData.count()) + " Field: " + strField; QLOG_INFO() << str; #endif QList listCell; listCell.clear(); listCell.append(this); int iColIndex = this->colindex(); QMap> mapBindData; //判断当前的column是否为关键值列,且合并 if ((mapColumnMerge.contains(iColIndex)) && (mapColumnMerge[iColIndex] == true)) { //查找前一列定义的关键值列和 合并标识 int iBeforeColIndex = iColIndex; QMap> mapTempMergeInfo; QMap>>::const_iterator iter; for (iter = mapBindDataMergeInfo.cbegin(); iter != mapBindDataMergeInfo.cend(); ++iter) { if (iter.key() < iColIndex) { iBeforeColIndex = iter.key(); } else { break; } //qDebug() << "for ==number==" << iter.key() << " name==" << iter.value(); } if (iBeforeColIndex < iColIndex) { mapTempMergeInfo = mapBindDataMergeInfo[iBeforeColIndex]; } bool bEndFlag = false; int iIndex = 0; //行索引 int iEqualCount = 1; //相同个数 QString strValue = listBindData.at(0); if (mapTempMergeInfo.count() > 0) { iIndex = 0; //行索引 int iLastIndex = 1; int iLastCount = 0; int iTempIndex = 0; QMap>::const_iterator iter; for (iter = mapTempMergeInfo.cbegin(); iter != mapTempMergeInfo.cend(); ++iter) { bEndFlag = false; iEqualCount = 1; //相同个数 iIndex = iTempIndex; strValue = listBindData.at(iTempIndex ); iLastCount += iter.value().first; for (iTempIndex = iLastIndex; iTempIndex < iLastCount; iTempIndex++) { if (strValue == listBindData.at(iTempIndex)) { iEqualCount++; bEndFlag =false; } else { QPair pairValue(iEqualCount,strValue); mapBindData.insert(iIndex, pairValue); iIndex = iTempIndex; iEqualCount = 1; bEndFlag = true; strValue = listBindData.at(iTempIndex); } } iLastIndex = iTempIndex +1; QPair pairValue(iEqualCount, strValue); mapBindData.insert(iIndex, pairValue); } mapBindDataMergeInfo.insert(iColIndex, mapBindData); } else { int i = 0; for (i = 1; i < listBindData.count(); i++) { if (strValue == listBindData.at(i)) { iEqualCount++; bEndFlag =false; } else { QPair pairValue(iEqualCount,strValue); mapBindData.insert(iIndex, pairValue); iIndex = i; iEqualCount = 1; bEndFlag = true; strValue = listBindData.at(i); } } QPair pairValue(iEqualCount, strValue); mapBindData.insert(iIndex, pairValue); mapBindDataMergeInfo.insert(iColIndex, mapBindData); } QList listRows = mapBindData.keys(); this->SetRowspan(mapBindData[listRows.at(0)].first); //复制相同的Cell for (int i = 1; i < listRows.count(); i++) { CCSCell* cell = qobject_cast(clone()); cell->SetRowindex(listRows.at(i)); cell->SetRowspan(mapBindData[listRows.at(i)].first); listCell.append(cell); } //给cell中的字段赋值 ReportFunPara para; para.strArgName = Set_Value; QList> listpairvalue; for (int i = 0; i < listRows.count(); i++) { listpairvalue.clear(); QPair pairvalue(strField, mapBindData[listRows.at(i)].second); listpairvalue.append(pairvalue); para.para = listpairvalue; listCell.at(i)->exeFunction(para); } } else { //复制相同的Cell for (int i = 1; i < listBindData.count(); i++) { CCSCell* cell = qobject_cast(clone()); cell->SetRowindex(i); listCell.append(cell); } //给cell中的字段赋值 ReportFunPara para; para.strArgName = Set_Value; if (listBindData.count() == listCell.count()) { QList> listpairvalue; for (int i = 0; i < listBindData.count(); i++) { listpairvalue.clear(); QPair pairvalue(strField, listBindData.at(i)); listpairvalue.append(pairvalue); para.para = listpairvalue; listCell.at(i)->exeFunction(para); } } } } void CCSCell::AddCellColumnIndex(int iAdd) { SetColindex(colindex() + iAdd); } }