File indexing completed on 2024-04-28 05:48:20
0001 #include "AsmViewModel.h" 0002 0003 #include <QColor> 0004 0005 AsmViewModel::AsmViewModel(QObject *parent) 0006 : QAbstractTableModel(parent) 0007 { 0008 } 0009 0010 QVariant AsmViewModel::data(const QModelIndex &index, int role) const 0011 { 0012 const int row = index.row(); 0013 switch (role) { 0014 case Qt::DisplayRole: 0015 if (index.column() == Column_LineNo) 0016 return QString::number(row + 1); 0017 else if (index.column() == Column_Text) 0018 return m_rows.at(row).text; 0019 else 0020 Q_UNREACHABLE(); 0021 case Qt::FontRole: 0022 return m_font; 0023 case Qt::BackgroundRole: 0024 if (index.column() == Column_Text) { 0025 if (m_hoveredLine != -1) { 0026 const auto &sourcePos = m_rows.at(row).source; 0027 if (sourcePos.file.isEmpty() && sourcePos.line == m_hoveredLine + 1) { 0028 return QColor(17, 90, 130); // Dark bluish, probably need better logic and colors 0029 } 0030 } 0031 } 0032 break; 0033 case Roles::RowLabels: 0034 if (index.column() == Column_Text) { 0035 return QVariant::fromValue(m_rows.at(row).labels); 0036 } 0037 } 0038 return {}; 0039 } 0040 0041 void AsmViewModel::setDataFromCE(std::vector<AsmRow> text, QHash<SourcePos, CodeGenLines> sourceToAsm, QHash<QString, int> labelToAsmLines) 0042 { 0043 beginResetModel(); 0044 m_rows = std::move(text); 0045 endResetModel(); 0046 0047 m_sourceToAsm = std::move(sourceToAsm); 0048 m_labelToAsmLine = std::move(labelToAsmLines); 0049 } 0050 0051 void AsmViewModel::clear() 0052 { 0053 beginResetModel(); 0054 m_rows.clear(); 0055 endResetModel(); 0056 m_sourceToAsm.clear(); 0057 } 0058 0059 void AsmViewModel::highlightLinkedAsm(int line) 0060 { 0061 m_hoveredLine = line; 0062 } 0063 0064 #include "moc_AsmViewModel.cpp"