VirtualBox

Ignore:
Timestamp:
Aug 19, 2019 2:11:04 PM (6 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
132804
Message:

FE/Qt: bugref:9510: Some clean ups.

Location:
trunk/src/VBox/Frontends/VirtualBox/src/runtime/information
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/information/UIInformationConfiguration.cpp

    r80342 r80343  
    2222#include <QHeaderView>
    2323#include <QTableWidget>
     24#include <QTextDocument>
    2425#include <QVBoxLayout>
    2526
    2627/* GUI includes: */
     28#include "UIDetailsGenerator.h"
    2729#include "UICommon.h"
    2830#include "UIExtraDataManager.h"
     
    3739const unsigned iColumCount = 3;
    3840
    39 class UIInformationTableRow
    40 {
    41 public:
    42 
    43     UIInformationTableRow(UIInformationConfiguration::TableRow row);
    44     ~UIInformationTableRow();
    45 
    46     QTableWidgetItem *addItem(unsigned iColumn, const QIcon &icon, const QString &strText);
    47     QTableWidgetItem *addItem(unsigned iColumn, const QString &strText);
    48 
    49     UIInformationConfiguration::TableRow row() const;
    50 
    51 private:
    52 
    53     QList<QTableWidgetItem*> m_items;
    54     UIInformationConfiguration::TableRow m_enmRow;
    55 };
    56 
    57 UIInformationTableRow::UIInformationTableRow(UIInformationConfiguration::TableRow enmRow)
    58 : m_enmRow(enmRow)
    59 {
    60     m_items.reserve(iColumCount);
    61 }
    62 
    63 UIInformationTableRow::~UIInformationTableRow()
    64 {
    65     for (int i = 0; i < m_items.size(); ++i)
    66         delete m_items[i];
    67     m_items.clear();
    68 }
    69 
    70 UIInformationConfiguration::TableRow UIInformationTableRow::row() const
    71 {
    72     return m_enmRow;
    73 }
    74 
    75 QTableWidgetItem *UIInformationTableRow::addItem(unsigned iColumn, const QIcon &icon, const QString &strText)
    76 {
    77     if (iColumn >= iColumCount)
    78         return 0;
    79     /* Deallocate first if we have something on the column already: */
    80     if (m_items.size() > (int)iColumn && m_items[iColumn])
    81         delete m_items[iColumn];
    82     QTableWidgetItem *pItem = new QTableWidgetItem(icon, strText);
    83     m_items.insert(iColumn, pItem);
    84     return pItem;
    85 }
    86 
    87 QTableWidgetItem *UIInformationTableRow::addItem(unsigned iColumn, const QString &strText)
    88 {
    89     if (iColumn >= iColumCount)
    90         return 0;
    91     /* Deallocate first if we have something on the column already: */
    92     if (m_items.size() > (int)iColumn && m_items[iColumn])
    93         delete m_items[iColumn];
    94     QTableWidgetItem *pItem = new QTableWidgetItem(strText);
    95     m_items.insert(iColumn, pItem);
    96     return pItem;
    97 }
    98 
    9941UIInformationConfiguration::UIInformationConfiguration(QWidget *pParent, const CMachine &machine, const CConsole &console)
    10042    : QIWithRetranslateUI<QWidget>(pParent)
     
    11759UIInformationConfiguration::~UIInformationConfiguration()
    11860{
    119     qDeleteAll(m_rows);
    120     m_rows.clear();
     61    qDeleteAll(m_tableItems);
     62    m_tableItems.clear();
    12163}
    12264
     
    247189    {
    248190        /* Configure the table by hiding the headers etc.: */
    249         m_pTableWidget->setRowCount(TableRow_Max);
     191        m_pTableWidget->setRowCount(20);
    250192        m_pTableWidget->setColumnCount(3);
    251193        m_pTableWidget->verticalHeader()->hide();
     
    253195        //m_pTableWidget->setShowGrid(false);
    254196        m_pMainLayout->addWidget(m_pTableWidget);
    255         m_pTableWidget->hide();
    256197    }
    257198}
     
    269210    int iMaxColumn1Length = 0;
    270211
    271     /* General Section: */
    272     insertTitleRow(TableRow_General_Title, m_strGeneralTitle, UIIconPool::iconSet(":/machine_16px.png"));
    273     QString strMachineName = m_machine.isNull() ? m_strError : m_machine.GetName();
    274     insertInfoRow(TableRow_General_Name, m_strGeneralName, strMachineName, fontMetrics, iMaxColumn1Length);
    275     QString strOSTypeName;
    276     if (!m_console.isNull())
    277     {
    278         CGuest comGuest = m_console.GetGuest();
    279         if (!comGuest.isNull())
    280             strOSTypeName = uiCommon().vmGuestOSTypeDescription(comGuest.GetOSTypeId());
    281     }
    282     if (strOSTypeName.isEmpty())
    283         strOSTypeName = m_strError;
    284     insertInfoRow(TableRow_General_OSType, m_strGeneralOSType, strOSTypeName, fontMetrics, iMaxColumn1Length);
    285     insertTitleRow(TableRow_System_Title, m_strSystemTitle, UIIconPool::iconSet(":/chipset_16px.png"));
    286 
     212
     213
     214    insertTitleRow(0, m_strGeneralTitle, UIIconPool::iconSet(":/machine_16px.png"));
     215
     216    UITextTable generalTextTable = UIDetailsGenerator::generateMachineInformationGeneral(m_machine,
     217                                                                                         UIExtraDataMetaDefs::DetailsElementOptionTypeGeneral_Default);
     218
     219    int iTableRow = 1;
     220    QTextDocument textDocument;
     221    foreach (const UITextTableLine &line, generalTextTable)
     222    {
     223        textDocument.setHtml(line.string2());
     224        insertInfoRow(iTableRow, line.string1(), textDocument.toRawText(), fontMetrics, iMaxColumn1Length);
     225        ++iTableRow;
     226    }
    287227
    288228    m_pTableWidget->resizeColumnToContents(0);
    289     //m_pTableWidget->resizeColumnToContents(1);
    290229    m_pTableWidget->setColumnWidth(1, 1.5 * iMaxColumn1Length);
    291230    m_pTableWidget->resizeColumnToContents(2);
     
    293232}
    294233
    295 void UIInformationConfiguration::insertTitleRow(TableRow enmRow, const QString &strTitle, const QIcon &icon)
    296 {
    297     UIInformationTableRow *pRow = new UIInformationTableRow(enmRow);
    298     m_rows.insert(enmRow, pRow);
    299     m_pTableWidget->setItem(enmRow, 0, pRow->addItem(0, icon, ""));
    300     QTableWidgetItem *pItem = pRow->addItem(1, strTitle);
    301     QFont font = pItem->font();
     234void UIInformationConfiguration::insertTitleRow(int iRow, const QString &strTitle, const QIcon &icon)
     235{
     236    QTableWidgetItem *pIconItem = new QTableWidgetItem(icon, "");
     237    m_pTableWidget->setItem(iRow, 0, pIconItem);
     238    QTableWidgetItem *pTitleItem = new QTableWidgetItem(strTitle);
     239    QFont font = pTitleItem->font();
    302240    font.setBold(true);
    303     pItem->setFont(font);
    304     m_pTableWidget->setItem(enmRow, 1, pItem);
    305 }
    306 
    307 void UIInformationConfiguration::insertInfoRow(TableRow enmRow, const QString &strColumn1, const QString &strColumn2,
     241    pTitleItem->setFont(font);
     242    m_pTableWidget->setItem(iRow, 1, pTitleItem);
     243    m_tableItems << pIconItem;
     244    m_tableItems << pTitleItem;
     245}
     246
     247void UIInformationConfiguration::insertInfoRow(int iRow, const QString strText1, const QString &strText2,
    308248                                               QFontMetrics &fontMetrics, int &iMaxColumn1Length)
    309249{
    310     UIInformationTableRow *pRow = new UIInformationTableRow(enmRow);
    311     m_rows.insert(enmRow, pRow);
    312     m_pTableWidget->setItem(enmRow, 1, pRow->addItem(1, strColumn1));
    313     m_pTableWidget->setItem(enmRow, 2, pRow->addItem(1, strColumn2));
    314     iMaxColumn1Length = qMax(iMaxColumn1Length, fontMetrics.width(strColumn1));
    315 }
     250    iMaxColumn1Length = qMax(iMaxColumn1Length, fontMetrics.width(strText1));
     251    QTableWidgetItem *pCol1 = new QTableWidgetItem(strText1);
     252    QTableWidgetItem *pCol2 = new QTableWidgetItem(strText2);
     253    m_tableItems << pCol1;
     254    m_tableItems << pCol2;
     255    m_pTableWidget->setItem(iRow, 1, pCol1);
     256    m_pTableWidget->setItem(iRow, 2, pCol2);
     257}
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/information/UIInformationConfiguration.h

    r80341 r80343  
    4141class QTableWidget;
    4242class QTableWidgetItem;
    43 class UIInformationTableRow;
     43class UITextTableLine;
    4444
    4545/** QWidget extension
     
    5050
    5151public:
    52 
    53     enum TableRow
    54     {
    55         TableRow_General_Title = 0,
    56         TableRow_General_Name,
    57         TableRow_General_OSType,
    58         TableRow_System_Title,
    59         TableRow_Max
    60     };
    6152
    6253    /** Constructs information-tab passing @a pParent to the QWidget base-class constructor.
     
    7768
    7869    void updateTable();
    79     void insertTitleRow(TableRow enmRow, const QString &strTitle, const QIcon &icon);
    80     void insertInfoRow(TableRow enmRow, const QString &strColumn1, const QString &strColumn2,
     70    void insertTitleRow(int iRow, const QString &strTitle, const QIcon &icon);
     71    void insertInfoRow(int iRow, const QString strText1, const QString &strText2,
    8172                       QFontMetrics &fontMetrics, int &iMaxColumn1Length);
    8273
     
    9283    UIInformationView *m_pView;
    9384    QTableWidget *m_pTableWidget;
    94     QMap<TableRow, UIInformationTableRow*> m_rows;
    95 
     85    //QMap<TableRow, UIInformationTableRow*> m_rows;
     86    QList<QTableWidgetItem*> m_tableItems;
    9687   /** @name Cached translated string.
    9788      * @{ */
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette