代码宏定义

下面一段相同的代码:仅m_pParameterStructInfo、ParameterStruct不同

		if (nullptr != m_pParameterStructInfo)
		{
			int row = 0;
			m_tableWidget->setRowCount(m_pParameterStructInfo->_infoSet.size());
			for (std::map<QString, ParameterStruct>::iterator iterator = m_pParameterStructInfo->_infoSet.begin(); iterator != m_pParameterStructInfo->_infoSet.end(); ++iterator,++row)
			{
				m_tableWidget->setItem(row, 0, new QTableWidgetItem(QString(iterator->second._Name)));
				m_tableWidget->setItem(row, 1, new QTableWidgetItem(QString(iterator->second._Version)));
				m_tableWidget->setItem(row, 2, new QTableWidgetItem(QString(QDateTime::fromSecsSinceEpoch(iterator->second._revised).toString("dd-MM-yyyy"))));
				m_tableWidget->setItem(row, 3, new QTableWidgetItem(QString(iterator->second._Classification)));
			}
		}

宏定义写法,使用## ##搭配替换不同的部分

#define UPDATETABLEDATA(type)\
if (m_p##type##Info)\
{\
	int row = 0;\
	m_tableWidget->setRowCount(m_p##type##Info->_infoSet.size());\
	for (std::map<QString, type>::iterator iterator = m_p##type##Info->_infoSet.begin(); iterator != m_p##type##Info->_infoSet.end(); ++iterator, ++row)\
	{\
		m_tableWidget->setItem(row, 0, new QTableWidgetItem(QString(iterator->second._Name)));\
		m_tableWidget->setItem(row, 1, new QTableWidgetItem(QString(iterator->second._Version)));\
		m_tableWidget->setItem(row, 2, new QTableWidgetItem(QDateTime::fromSecsSinceEpoch(iterator->second._revised).toString("dd-MM-yyyy")));\
		m_tableWidget->setItem(row, 3, new QTableWidgetItem(QString(iterator->second._Classification)));\
	}\
}\

使用方法:
UPDATETABLEDATA(ParameterStruct);

你可能感兴趣的:(项目学习笔记,qt,c++)