VirtualBox

Changeset 105029 in vbox


Ignore:
Timestamp:
Jun 26, 2024 10:58:38 AM (5 months ago)
Author:
vboxsync
Message:

FE/Qt: bugref:10681: UIPortForwardingTable: Moving the rest of table sub-class stuff from parent into appropriate place.

Location:
trunk/src/VBox/Frontends/VirtualBox/src/widgets
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/widgets/UIPortForwardingTable.cpp

    r105027 r105029  
    507507    virtual ~UIPortForwardingView();
    508508
     509protected:
     510
     511    /** Handles any Qt @a pEvent. */
     512    virtual bool event(QEvent *pEvent) RT_OVERRIDE;
     513
     514protected slots:
     515
     516    /** Handles rows being inserted.
     517      * @param  parent  Brings the parent under which new rows being inserted.
     518      * @param  iStart  Brings the starting position (inclusive).
     519      * @param  iStart  Brings the end position (inclusive). */
     520    virtual void rowsInserted(const QModelIndex &parent, int iStart, int iEnd) RT_OVERRIDE;
     521
     522    /** Handles rows being removed.
     523      * @param  parent  Brings the parent for which rows being removed.
     524      * @param  iStart  Brings the starting position (inclusive).
     525      * @param  iStart  Brings the end position (inclusive). */
     526    virtual void rowsAboutToBeRemoved(const QModelIndex &parent, int iStart, int iEnd) RT_OVERRIDE;
     527
    509528private:
    510529
     
    513532    /** Cleanups everything. */
    514533    void cleanup();
     534
     535    /** Adjusts table contents. */
     536    void adjust();
    515537
    516538    /** Holds whether this view contains IPv6 rules, not IPv4. */
     
    810832}
    811833
     834bool UIPortForwardingView::event(QEvent *pEvent)
     835{
     836    /* Process different event-types: */
     837    switch (pEvent->type())
     838    {
     839        /* Adjust table on show/resize events: */
     840        case QEvent::Show:
     841        case QEvent::Resize:
     842        {
     843            // WORKAROUND:
     844            // Make sure layout requests really processed first of all;
     845            // This is required for the 1st show event but let it be ..
     846            QCoreApplication::sendPostedEvents(0, QEvent::LayoutRequest);
     847            adjust();
     848            break;
     849        }
     850        default:
     851            break;
     852    }
     853
     854    /* Call to base-class: */
     855    return QITableView::event(pEvent);
     856}
     857
     858void UIPortForwardingView::rowsInserted(const QModelIndex &parent, int iStart, int iEnd)
     859{
     860    /* Call to base-class: */
     861    QITableView::rowsInserted(parent, iStart, iEnd);
     862    /* Adjust table on rows being inserted: */
     863    adjust();
     864}
     865
     866void UIPortForwardingView::rowsAboutToBeRemoved(const QModelIndex &parent, int start, int end)
     867{
     868    /* Call to base-class: */
     869    QITableView::rowsAboutToBeRemoved(parent, start, end);
     870    /* Adjust table on rows being removed: */
     871    adjust();
     872}
     873
    812874void UIPortForwardingView::prepare()
    813875{
     
    881943
    882944
     945void UIPortForwardingView::adjust()
     946{
     947    horizontalHeader()->setStretchLastSection(false);
     948    /* If table is NOT empty: */
     949    if (model()->rowCount())
     950    {
     951        /* Resize table to contents size-hint and emit a spare place for first column: */
     952        resizeColumnsToContents();
     953        uint uFullWidth = viewport()->width();
     954        for (uint u = 1; u < UIPortForwardingDataType_Max; ++u)
     955            uFullWidth -= horizontalHeader()->sectionSize(u);
     956        horizontalHeader()->resizeSection(UIPortForwardingDataType_Name, uFullWidth);
     957    }
     958    /* If table is empty: */
     959    else
     960    {
     961        /* Resize table columns to be equal in size: */
     962        uint uFullWidth = viewport()->width();
     963        for (uint u = 0; u < UIPortForwardingDataType_Max; ++u)
     964            horizontalHeader()->resizeSection(u, uFullWidth / UIPortForwardingDataType_Max);
     965    }
     966    horizontalHeader()->setStretchLastSection(true);
     967}
     968
    883969/*********************************************************************************************************************************
    884970*   Class UIPortForwardingTable implementation.                                                                                  *
     
    9281014    m_rules = newRules;
    9291015    m_pTableModel->setRules(m_rules);
    930     sltAdjustTable();
    9311016
    9321017    /* Restore last chosen item: */
     
    10101095}
    10111096
    1012 bool UIPortForwardingTable::eventFilter(QObject *pObject, QEvent *pEvent)
    1013 {
    1014     /* Process table: */
    1015     if (pObject == m_pTableView)
    1016     {
    1017         /* Process different event-types: */
    1018         switch (pEvent->type())
    1019         {
    1020             case QEvent::Show:
    1021             case QEvent::Resize:
    1022             {
    1023                 /* Make sure layout requests really processed first of all: */
    1024                 QCoreApplication::sendPostedEvents(0, QEvent::LayoutRequest);
    1025                 /* Adjust table: */
    1026                 sltAdjustTable();
    1027                 break;
    1028             }
    1029             default:
    1030                 break;
    1031         }
    1032     }
    1033     /* Call to base-class: */
    1034     return QWidget::eventFilter(pObject, pEvent);
    1035 }
    1036 
    10371097void UIPortForwardingTable::sltRetranslateUI()
    10381098{
     
    10601120    m_pTableView->setCurrentIndex(m_pTableModel->index(m_pTableModel->rowCount() - 1, 0));
    10611121    sltUpdateActions();
    1062     sltAdjustTable();
    10631122}
    10641123
     
    10691128    m_pTableView->setCurrentIndex(m_pTableModel->index(m_pTableModel->rowCount() - 1, 0));
    10701129    sltUpdateActions();
    1071     sltAdjustTable();
    10721130}
    10731131
     
    10771135    m_pTableView->setFocus();
    10781136    sltUpdateActions();
    1079     sltAdjustTable();
    10801137}
    10811138
     
    11041161        menu.addAction(m_pActionAdd);
    11051162    menu.exec(m_pTableView->viewport()->mapToGlobal(pos));
    1106 }
    1107 
    1108 void UIPortForwardingTable::sltAdjustTable()
    1109 {
    1110     /* If table is NOT empty: */
    1111     if (m_pTableModel->rowCount())
    1112     {
    1113         /* Resize table to contents size-hint and emit a spare place for first column: */
    1114         m_pTableView->resizeColumnsToContents();
    1115         uint uFullWidth = m_pTableView->viewport()->width();
    1116         for (uint u = 1; u < UIPortForwardingDataType_Max; ++u)
    1117             uFullWidth -= m_pTableView->horizontalHeader()->sectionSize(u);
    1118         m_pTableView->horizontalHeader()->resizeSection(UIPortForwardingDataType_Name, uFullWidth);
    1119     }
    1120     /* If table is empty: */
    1121     else
    1122     {
    1123         /* Resize table columns to be equal in size: */
    1124         uint uFullWidth = m_pTableView->viewport()->width();
    1125         for (uint u = 0; u < UIPortForwardingDataType_Max; ++u)
    1126             m_pTableView->horizontalHeader()->resizeSection(u, uFullWidth / UIPortForwardingDataType_Max);
    1127     }
    11281163}
    11291164
     
    12491284        m_pLayout->addWidget(m_pToolBar);
    12501285    }
     1286
     1287    /* Update actions finally: */
     1288    sltUpdateActions();
    12511289}
    12521290
  • trunk/src/VBox/Frontends/VirtualBox/src/widgets/UIPortForwardingTable.h

    r105021 r105029  
    243243    void makeSureEditorDataCommitted();
    244244
    245 protected:
    246 
    247     /** Preprocesses any Qt @a pEvent for passed @a pObject. */
    248     virtual bool eventFilter(QObject *pObject, QEvent *pEvent) RT_OVERRIDE;
    249 
    250245private slots:
    251246
     
    267262    /** Handles request to show context-menu in certain @a position. */
    268263    void sltShowTableContexMenu(const QPoint &position);
    269 
    270     /** Adjusts table column sizes. */
    271     void sltAdjustTable();
    272264
    273265private:
Note: See TracChangeset for help on using the changeset viewer.

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