VirtualBox

Changeset 80341 in vbox


Ignore:
Timestamp:
Aug 19, 2019 11:11:27 AM (6 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
132802
Message:

FE/Qt: bugref:9510: Adding a QTableWidget which will replace all model/view magic.

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

Legend:

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

    r77594 r80341  
    1616 */
    1717
     18/* COM includes: */
     19
    1820/* Qt includes: */
     21#include <QApplication>
     22#include <QHeaderView>
     23#include <QTableWidget>
    1924#include <QVBoxLayout>
    20 #include <QApplication>
    2125
    2226/* GUI includes: */
     27#include "UICommon.h"
     28#include "UIExtraDataManager.h"
     29#include "UIIconPool.h"
    2330#include "UIInformationConfiguration.h"
    2431#include "UIInformationDataItem.h"
    2532#include "UIInformationItem.h"
    2633#include "UIInformationView.h"
    27 #include "UIExtraDataManager.h"
    2834#include "UIInformationModel.h"
    2935
    3036
     37const unsigned iColumCount = 3;
     38
     39class UIInformationTableRow
     40{
     41public:
     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
     49private:
     50
     51    QList<QTableWidgetItem*> m_items;
     52    UIInformationConfiguration::TableRow m_enmRow;
     53};
     54
     55UIInformationTableRow::UIInformationTableRow(UIInformationConfiguration::TableRow enmRow)
     56    : m_enmRow(enmRow)
     57{
     58    m_items.reserve(iColumCount);
     59}
     60
     61UIInformationTableRow::~UIInformationTableRow()
     62{
     63    for (int i = 0; i < m_items.size(); ++i)
     64        delete m_items[i];
     65    m_items.clear();
     66}
     67
     68
     69QTableWidgetItem *UIInformationTableRow::addItem(unsigned iColumn, const QIcon &icon, const QString &strText)
     70{
     71    if (iColumn >= iColumCount)
     72        return 0;
     73    /* Deallocate first if we have something on the column already: */
     74    if (m_items.size() > (int)iColumn && m_items[iColumn])
     75        delete m_items[iColumn];
     76    QTableWidgetItem *pItem = new QTableWidgetItem(icon, strText);
     77    m_items.insert(iColumn, pItem);
     78    return pItem;
     79}
     80
     81QTableWidgetItem *UIInformationTableRow::addItem(unsigned iColumn, const QString &strText)
     82{
     83    if (iColumn >= iColumCount)
     84        return 0;
     85    /* Deallocate first if we have something on the column already: */
     86    if (m_items.size() > (int)iColumn && m_items[iColumn])
     87        delete m_items[iColumn];
     88    QTableWidgetItem *pItem = new QTableWidgetItem(strText);
     89    m_items.insert(iColumn, pItem);
     90    return pItem;
     91}
     92
    3193UIInformationConfiguration::UIInformationConfiguration(QWidget *pParent, const CMachine &machine, const CConsole &console)
    32     : QWidget(pParent)
     94    : QIWithRetranslateUI<QWidget>(pParent)
    3395    , m_machine(machine)
    3496    , m_console(console)
     
    3698    , m_pModel(0)
    3799    , m_pView(0)
    38 {
    39     /* Prepare layout: */
    40     prepareLayout();
    41 
     100    , m_pTableWidget(0)
     101{
    42102    /* Prepare model: */
    43103    prepareModel();
    44104
    45105    /* Prepare view: */
    46     prepareView();
    47 }
    48 
    49 void UIInformationConfiguration::prepareLayout()
    50 {
    51     /* Create layout: */
    52     m_pMainLayout = new QVBoxLayout(this);
    53     AssertPtrReturnVoid(m_pMainLayout);
    54     {
    55         /* Configure layout: */
    56         m_pMainLayout->setSpacing(0);
    57     }
     106    prepareObjects();
     107    retranslateUi();
     108    createTableItems();
     109}
     110
     111UIInformationConfiguration::~UIInformationConfiguration()
     112{
     113    qDeleteAll(m_rows);
     114    m_rows.clear();
     115}
     116
     117void UIInformationConfiguration::retranslateUi()
     118{
     119    m_strGeneralTitle = QApplication::translate("UIVMInformationDialog", "General");
     120    m_strGeneralName = QApplication::translate("UIVMInformationDialog", "Name");
     121    m_strGeneralOSType = QApplication::translate("UIVMInformationDialog", "Operating System");
     122    m_strSystemTitle = QApplication::translate("UIVMInformationDialog", "System");
     123    m_strError = QApplication::translate("UIVMInformationDialog", "Not Detected");
    58124}
    59125
     
    138204}
    139205
    140 void UIInformationConfiguration::prepareView()
    141 {
     206void UIInformationConfiguration::prepareObjects()
     207{
     208    /* Create layout: */
     209    m_pMainLayout = new QVBoxLayout(this);
     210    if (!m_pMainLayout)
     211        return;
     212    m_pMainLayout->setSpacing(0);
     213
     214
    142215    /* Create information-view: */
    143216    m_pView = new UIInformationView;
     
    162235        m_pMainLayout->addWidget(m_pView);
    163236    }
    164 }
     237
     238    m_pTableWidget = new QTableWidget;
     239
     240    if (m_pTableWidget)
     241    {
     242        /* Configure the table by hiding the headers etc.: */
     243        m_pTableWidget->setRowCount(TableRow_Max);
     244        m_pTableWidget->setColumnCount(3);
     245        m_pTableWidget->verticalHeader()->hide();
     246        m_pTableWidget->horizontalHeader()->hide();
     247        //m_pTableWidget->setShowGrid(false);
     248        m_pMainLayout->addWidget(m_pTableWidget);
     249        m_pTableWidget->hide();
     250    }
     251}
     252
     253void UIInformationConfiguration::updateTable()
     254{
     255}
     256
     257void UIInformationConfiguration::createTableItems()
     258{
     259    if (!m_pTableWidget)
     260        return;
     261    QFontMetrics fontMetrics(m_pTableWidget->font());
     262
     263    int iMaxColumn1Length = 0;
     264
     265    /* General Section: */
     266    insertTitleRow(TableRow_General_Title, m_strGeneralTitle, UIIconPool::iconSet(":/machine_16px.png"));
     267    QString strMachineName = m_machine.isNull() ? m_strError : m_machine.GetName();
     268    insertInfoRow(TableRow_General_Name, m_strGeneralName, strMachineName, fontMetrics, iMaxColumn1Length);
     269    QString strOSTypeName;
     270    if (!m_console.isNull())
     271    {
     272        CGuest comGuest = m_console.GetGuest();
     273        if (!comGuest.isNull())
     274            strOSTypeName = uiCommon().vmGuestOSTypeDescription(comGuest.GetOSTypeId());
     275    }
     276    if (strOSTypeName.isEmpty())
     277        strOSTypeName = m_strError;
     278    insertInfoRow(TableRow_General_OSType, m_strGeneralOSType, strOSTypeName, fontMetrics, iMaxColumn1Length);
     279    insertTitleRow(TableRow_System_Title, m_strSystemTitle, UIIconPool::iconSet(":/chipset_16px.png"));
     280
     281
     282    m_pTableWidget->resizeColumnToContents(0);
     283    //m_pTableWidget->resizeColumnToContents(1);
     284    m_pTableWidget->setColumnWidth(1, 1.5 * iMaxColumn1Length);
     285    m_pTableWidget->resizeColumnToContents(2);
     286
     287}
     288
     289void UIInformationConfiguration::insertTitleRow(TableRow enmRow, const QString &strTitle, const QIcon &icon)
     290{
     291    UIInformationTableRow *pRow = new UIInformationTableRow(enmRow);
     292    m_rows.insert(enmRow, pRow);
     293    m_pTableWidget->setItem(enmRow, 0, pRow->addItem(0, icon, ""));
     294    QTableWidgetItem *pItem = pRow->addItem(1, strTitle);
     295    QFont font = pItem->font();
     296    font.setBold(true);
     297    pItem->setFont(font);
     298    m_pTableWidget->setItem(enmRow, 1, pItem);
     299}
     300
     301void UIInformationConfiguration::insertInfoRow(TableRow enmRow, const QString &strColumn1, const QString &strColumn2,
     302                                               QFontMetrics &fontMetrics, int &iMaxColumn1Length)
     303{
     304    UIInformationTableRow *pRow = new UIInformationTableRow(enmRow);
     305    m_rows.insert(enmRow, pRow);
     306    m_pTableWidget->setItem(enmRow, 1, pRow->addItem(1, strColumn1));
     307    m_pTableWidget->setItem(enmRow, 2, pRow->addItem(1, strColumn2));
     308    iMaxColumn1Length = qMax(iMaxColumn1Length, fontMetrics.width(strColumn1));
     309}
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/information/UIInformationConfiguration.h

    r76581 r80341  
    2727/* COM includes: */
    2828#include "COMEnums.h"
     29#include "CGuest.h"
     30
    2931#include "CMachine.h"
    3032#include "CConsole.h"
     33
     34/* GUI includes: */
     35#include "QIWithRetranslateUI.h"
    3136
    3237/* Forward declarations: */
     
    3439class UIInformationView;
    3540class UIInformationModel;
    36 
     41class QTableWidget;
     42class QTableWidgetItem;
     43class UIInformationTableRow;
    3744
    3845/** QWidget extension
    3946  * providing GUI with configuration-information tab in session-information window. */
    40 class UIInformationConfiguration : public QWidget
     47class UIInformationConfiguration : public QIWithRetranslateUI<QWidget>
    4148{
    4249    Q_OBJECT;
     
    4451public:
    4552
     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    };
     61
    4662    /** Constructs information-tab passing @a pParent to the QWidget base-class constructor.
    4763      * @param machine is machine reference.
    4864      * @param console is machine console reference. */
    4965    UIInformationConfiguration(QWidget *pParent, const CMachine &machine, const CConsole &console);
     66    ~UIInformationConfiguration();
     67
     68protected:
     69
     70    void retranslateUi() /* override */;
    5071
    5172private:
    52 
    53     /** Prepares layout. */
    54     void prepareLayout();
    55 
    5673    /** Prepares model. */
    5774    void prepareModel();
     75    void prepareObjects();
     76    void createTableItems();
    5877
    59     /** Prepares view. */
    60     void prepareView();
     78    void updateTable();
     79    void insertTitleRow(TableRow enmRow, const QString &strTitle, const QIcon &icon);
     80    void insertInfoRow(TableRow enmRow, const QString &strColumn1, const QString &strColumn2,
     81                       QFontMetrics &fontMetrics, int &iMaxColumn1Length);
    6182
    6283    /** Holds the machine instance. */
     
    7091    /** Holds the instance of view we create. */
    7192    UIInformationView *m_pView;
     93    QTableWidget *m_pTableWidget;
     94    QMap<TableRow, UIInformationTableRow*> m_rows;
     95
     96   /** @name Cached translated string.
     97      * @{ */
     98        QString m_strError;
     99
     100        /** General section. */
     101        QString m_strGeneralTitle;
     102        QString m_strGeneralName;
     103        QString m_strGeneralOSType;
     104        /** System section. */
     105        QString m_strSystemTitle;
     106
     107    /** @} */
     108
    72109};
    73110
    74111#endif /* !FEQT_INCLUDED_SRC_runtime_information_UIInformationConfiguration_h */
    75 
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/information/UIPerformanceMonitor.h

    r80330 r80341  
    139139    /** @} */
    140140
    141     /** @name These metric names are used for map keys to identify metrics.
     141    /** @name Cached translated string.
    142142      * @{ */
    143143        /** CPU info label strings. */
  • trunk/src/VBox/Frontends/VirtualBox/src/runtime/information/UIVMInformationDialog.cpp

    r80162 r80341  
    271271
    272272        /* Set Runtime Information tab as default: */
    273         m_pTabWidget->setCurrentIndex(1);
     273        m_pTabWidget->setCurrentIndex(0);
    274274
    275275        /* Assign tab-widget page change handler: */
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