| 656 | } |
| 657 | |
| 658 | QWidget *DevicePropertiesDialog::buildResourcesTab() { |
| 659 | auto *w = new QWidget; |
| 660 | auto *v = new QVBoxLayout(w); |
| 661 | v->setContentsMargins(8, 8, 8, 8); |
| 662 | v->setSpacing(0); |
| 663 | |
| 664 | v->addWidget(deviceHeader(m_info.name, m_info.iconName)); |
| 665 | |
| 666 | v->addWidget(new QLabel("Resource settings:")); |
| 667 | v->addSpacing(3); |
| 668 | |
| 669 | auto *tree = new QTreeWidget; |
| 670 | tree->setColumnCount(2); |
| 671 | tree->setHeaderLabels({"Resource type", "Setting"}); |
| 672 | tree->setRootIsDecorated(false); |
| 673 | tree->setSelectionMode(QAbstractItemView::SingleSelection); |
| 674 | tree->setAlternatingRowColors(false); |
| 675 | tree->header()->setDefaultAlignment(Qt::AlignLeft); |
| 676 | tree->header()->setSectionResizeMode(0, QHeaderView::ResizeToContents); |
| 677 | tree->header()->setSectionResizeMode(1, QHeaderView::Stretch); |
| 678 | tree->setFixedHeight(130); |
| 679 | v->addWidget(tree); |
| 680 | |
| 681 | auto makeIcon = [](const QColor &color) -> QIcon { |
| 682 | QPixmap pm(14, 14); |
| 683 | pm.fill(Qt::transparent); |
| 684 | QPainter p(&pm); |
| 685 | p.setPen(QColor(60, 60, 60)); |
| 686 | p.setBrush(color); |
| 687 | p.drawRect(1, 1, 11, 11); |
| 688 | return QIcon(pm); |
| 689 | }; |
| 690 | |
| 691 | auto fmtAddr = [](quint64 val) -> QString { |
| 692 | if (val > 0xFFFFFFFFULL) |
| 693 | return QString("%1").arg(val, 16, 16, QChar('0')).toUpper(); |
| 694 | if (val > 0xFFFFULL) |
| 695 | return QString("%1").arg(val, 8, 16, QChar('0')).toUpper(); |
| 696 | return QString("%1").arg(val, 4, 16, QChar('0')).toUpper(); |
| 697 | }; |
| 698 | |
| 699 | const QIcon memIcon = makeIcon(QColor(100, 80, 180)); |
| 700 | const QIcon ioIcon = makeIcon(QColor(40, 140, 40)); |
| 701 | const QIcon irqIcon = makeIcon(QColor(210, 160, 20)); |
| 702 | |
| 703 | auto resourceType = [](quint64 flags) -> QString { |
| 704 | if (flags == 0) return {}; |
| 705 | if (flags & 0x200) return "I/O Range"; |
| 706 | return "Memory Range"; |
| 707 | }; |
| 708 | |
| 709 | if (!m_info.sysfsPciPath.isEmpty()) { |
| 710 | QFile irqFile(m_info.sysfsPciPath + "/irq"); |
| 711 | if (irqFile.open(QIODevice::ReadOnly | QIODevice::Text)) { |
| 712 | QString irq = QString::fromUtf8(irqFile.read(1024)).trimmed(); |
| 713 | if (!irq.isEmpty() && irq != "0") { |
| 714 | auto *item = new QTreeWidgetItem(tree); |
| 715 | item->setIcon(0, irqIcon); |
nothing calls this directly
no test coverage detected