- Timestamp:
- Dec 7, 2016 3:08:28 PM (8 years ago)
- Location:
- trunk/src/VBox/Frontends/VirtualBox/src
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/src/settings/global/UIGlobalSettingsPortForwardingDlg.cpp
r62493 r64803 74 74 } 75 75 76 const UIPortForwardingDataList &UIGlobalSettingsPortForwardingDlg::ipv4rules() const76 const UIPortForwardingDataList UIGlobalSettingsPortForwardingDlg::ipv4rules() const 77 77 { 78 78 return m_pIPv4Table->rules(); 79 79 } 80 80 81 const UIPortForwardingDataList &UIGlobalSettingsPortForwardingDlg::ipv6rules() const81 const UIPortForwardingDataList UIGlobalSettingsPortForwardingDlg::ipv6rules() const 82 82 { 83 83 return m_pIPv6Table->rules(); -
trunk/src/VBox/Frontends/VirtualBox/src/settings/global/UIGlobalSettingsPortForwardingDlg.h
r62493 r64803 41 41 42 42 /* API: Rules stuff: */ 43 const UIPortForwardingDataList &ipv4rules() const;44 const UIPortForwardingDataList &ipv6rules() const;43 const UIPortForwardingDataList ipv4rules() const; 44 const UIPortForwardingDataList ipv6rules() const; 45 45 46 46 private slots: -
trunk/src/VBox/Frontends/VirtualBox/src/settings/machine/UIMachineSettingsPortForwardingDlg.cpp
r62493 r64803 63 63 } 64 64 65 const UIPortForwardingDataList &UIMachineSettingsPortForwardingDlg::rules() const65 const UIPortForwardingDataList UIMachineSettingsPortForwardingDlg::rules() const 66 66 { 67 67 return m_pTable->rules(); -
trunk/src/VBox/Frontends/VirtualBox/src/settings/machine/UIMachineSettingsPortForwardingDlg.h
r62493 r64803 38 38 39 39 /* API: Rules stuff: */ 40 const UIPortForwardingDataList &rules() const;40 const UIPortForwardingDataList rules() const; 41 41 42 42 private slots: -
trunk/src/VBox/Frontends/VirtualBox/src/widgets/UIPortForwardingTable.cpp
r64802 r64803 285 285 286 286 287 /** QITableViewCell extension used as Port Forwarding table-view cell. */ 288 class UIPortForwardingCell : public QITableViewCell 289 { 290 Q_OBJECT; 291 292 public: 293 294 /** Constructs table cell passing @a pParent to the base-class. 295 * @param strName Brings the name. */ 296 UIPortForwardingCell(QITableViewRow *pParent, const NameData &strName) 297 : QITableViewCell(pParent) 298 , m_strText(strName) 299 {} 300 301 /** Constructs table cell passing @a pParent to the base-class. 302 * @param enmProtocol Brings the protocol type. */ 303 UIPortForwardingCell(QITableViewRow *pParent, KNATProtocol enmProtocol) 304 : QITableViewCell(pParent) 305 , m_strText(gpConverter->toString(enmProtocol)) 306 {} 307 308 /** Constructs table cell passing @a pParent to the base-class. 309 * @param strIp Brings the IP address. */ 310 UIPortForwardingCell(QITableViewRow *pParent, const IpData &strIP) 311 : QITableViewCell(pParent) 312 , m_strText(strIP) 313 {} 314 315 /** Constructs table cell passing @a pParent to the base-class. 316 * @param uHostPort Brings the port. */ 317 UIPortForwardingCell(QITableViewRow *pParent, PortData uPort) 318 : QITableViewCell(pParent) 319 , m_strText(QString::number(uPort.value())) 320 {} 321 322 /** Returns the cell text. */ 323 virtual QString text() const /* override */ { return m_strText; } 324 325 private: 326 327 /** Holds the cell text. */ 328 QString m_strText; 329 }; 330 331 332 /** QITableViewRow extension used as Port Forwarding table-view row. */ 333 class UIPortForwardingRow : public QITableViewRow 334 { 335 Q_OBJECT; 336 337 public: 338 339 /** Constructs table row passing @a pParent to the base-class. 340 * @param strName Brings the unique rule name. 341 * @param enmProtocol Brings the rule protocol type. 342 * @param strHostIp Brings the rule host IP address. 343 * @param uHostPort Brings the rule host port. 344 * @param strGuestIp Brings the rule guest IP address. 345 * @param uGuestPort Brings the rule guest port. */ 346 UIPortForwardingRow(QITableView *pParent, 347 const NameData &strName, KNATProtocol enmProtocol, 348 const IpData &strHostIp, PortData uHostPort, 349 const IpData &strGuestIp, PortData uGuestPort) 350 : QITableViewRow(pParent) 351 , m_strName(strName), m_enmProtocol(enmProtocol) 352 , m_strHostIp(strHostIp), m_uHostPort(uHostPort) 353 , m_strGuestIp(strGuestIp), m_uGuestPort(uGuestPort) 354 { 355 /* Create cells: */ 356 createCells(); 357 } 358 359 /** Destructs table row. */ 360 ~UIPortForwardingRow() 361 { 362 /* Destroy cells: */ 363 destroyCells(); 364 } 365 366 /** Returns the unique rule name. */ 367 NameData name() const { return m_strName; } 368 /** Defines the unique rule name. */ 369 void setName(const NameData &strName) 370 { 371 m_strName = strName; 372 delete m_cells[UIPortForwardingDataType_Name]; 373 m_cells[UIPortForwardingDataType_Name] = new UIPortForwardingCell(this, m_strName); 374 } 375 376 /** Returns the rule protocol type. */ 377 KNATProtocol protocol() const { return m_enmProtocol; } 378 /** Defines the rule protocol type. */ 379 void setProtocol(KNATProtocol enmProtocol) 380 { 381 m_enmProtocol = enmProtocol; 382 delete m_cells[UIPortForwardingDataType_Protocol]; 383 m_cells[UIPortForwardingDataType_Protocol] = new UIPortForwardingCell(this, m_enmProtocol); 384 } 385 386 /** Returns the rule host IP address. */ 387 IpData hostIp() const { return m_strHostIp; } 388 /** Defines the rule host IP address. */ 389 void setHostIp(const IpData &strHostIp) 390 { 391 m_strHostIp = strHostIp; 392 delete m_cells[UIPortForwardingDataType_HostIp]; 393 m_cells[UIPortForwardingDataType_HostIp] = new UIPortForwardingCell(this, m_strHostIp); 394 } 395 396 /** Returns the rule host port. */ 397 PortData hostPort() const { return m_uHostPort; } 398 /** Defines the rule host port. */ 399 void setHostPort(PortData uHostPort) 400 { 401 m_uHostPort = uHostPort; 402 delete m_cells[UIPortForwardingDataType_HostPort]; 403 m_cells[UIPortForwardingDataType_HostPort] = new UIPortForwardingCell(this, m_uHostPort); 404 } 405 406 /** Returns the rule guest IP address. */ 407 IpData guestIp() const { return m_strGuestIp; } 408 /** Defines the rule guest IP address. */ 409 void setGuestIp(const IpData &strGuestIp) 410 { 411 m_strGuestIp = strGuestIp; 412 delete m_cells[UIPortForwardingDataType_GuestIp]; 413 m_cells[UIPortForwardingDataType_GuestIp] = new UIPortForwardingCell(this, m_strGuestIp); 414 } 415 416 /** Returns the rule guest port. */ 417 PortData guestPort() const { return m_uGuestPort; } 418 /** Defines the rule guest port. */ 419 void setGuestPort(PortData uGuestPort) 420 { 421 m_uGuestPort = uGuestPort; 422 delete m_cells[UIPortForwardingDataType_GuestPort]; 423 m_cells[UIPortForwardingDataType_GuestPort] = new UIPortForwardingCell(this, m_uGuestPort); 424 } 425 426 protected: 427 428 /** Returns the number of children. */ 429 virtual int childCount() const /* override */ 430 { 431 /* Return cell count: */ 432 return UIPortForwardingDataType_Max; 433 } 434 435 /** Returns the child item with @a iIndex. */ 436 virtual QITableViewCell *childItem(int iIndex) const /* override */ 437 { 438 /* Make sure index within the bounds: */ 439 AssertReturn(iIndex >= 0 && iIndex < m_cells.size(), 0); 440 /* Return corresponding cell: */ 441 return m_cells[iIndex]; 442 } 443 444 private: 445 446 /** Creates cells. */ 447 void createCells() 448 { 449 /* Create cells on the basis of variables we have: */ 450 m_cells.resize(UIPortForwardingDataType_Max); 451 m_cells[UIPortForwardingDataType_Name] = new UIPortForwardingCell(this, m_strName); 452 m_cells[UIPortForwardingDataType_Protocol] = new UIPortForwardingCell(this, m_enmProtocol); 453 m_cells[UIPortForwardingDataType_HostIp] = new UIPortForwardingCell(this, m_strHostIp); 454 m_cells[UIPortForwardingDataType_HostPort] = new UIPortForwardingCell(this, m_uHostPort); 455 m_cells[UIPortForwardingDataType_GuestIp] = new UIPortForwardingCell(this, m_strGuestIp); 456 m_cells[UIPortForwardingDataType_GuestPort] = new UIPortForwardingCell(this, m_uGuestPort); 457 } 458 459 /** Destroys cells. */ 460 void destroyCells() 461 { 462 /* Destroy cells: */ 463 qDeleteAll(m_cells); 464 m_cells.clear(); 465 } 466 467 /** Holds the unique rule name. */ 468 NameData m_strName; 469 /** Holds the rule protocol type. */ 470 KNATProtocol m_enmProtocol; 471 /** Holds the rule host IP address. */ 472 IpData m_strHostIp; 473 /** Holds the rule host port. */ 474 PortData m_uHostPort; 475 /** Holds the rule guest IP address. */ 476 IpData m_strGuestIp; 477 /** Holds the rule guest port. */ 478 PortData m_uGuestPort; 479 480 /** Holds the cell instances. */ 481 QVector<UIPortForwardingCell*> m_cells; 482 }; 483 484 287 485 /* Port forwarding data model: */ 288 486 class UIPortForwardingModel : public QAbstractTableModel … … 294 492 /** Constructs Port Forwarding model passing @a pParent to the base-class. 295 493 * @param rules Brings the list of port forwarding rules to load initially. */ 296 UIPortForwardingModel(QITableView *pParent, const UIPortForwardingDataList &rules = UIPortForwardingDataList()) 297 : QAbstractTableModel(pParent)298 , m_dataList(rules) {}494 UIPortForwardingModel(QITableView *pParent, const UIPortForwardingDataList &rules = UIPortForwardingDataList()); 495 /** Destructs Port Forwarding model. */ 496 ~UIPortForwardingModel(); 299 497 300 498 /* API: Rule stuff: */ 301 const UIPortForwardingDataList & rules() const { return m_dataList; }499 const UIPortForwardingDataList rules() const; 302 500 void addRule(const QModelIndex &index); 303 501 void delRule(const QModelIndex &index); … … 325 523 326 524 /* Variable: Data stuff: */ 327 UIPortForwardingDataListm_dataList;525 QList<UIPortForwardingRow*> m_dataList; 328 526 }; 329 527 … … 332 530 * Class UIPortForwardingModel implementation. * 333 531 *********************************************************************************************************************************/ 532 533 UIPortForwardingModel::UIPortForwardingModel(QITableView *pParent, const UIPortForwardingDataList &rules /* = UIPortForwardingDataList() */) 534 : QAbstractTableModel(pParent) 535 { 536 /* Fetch the incoming data: */ 537 foreach (const UIPortForwardingData &rule, rules) 538 m_dataList << new UIPortForwardingRow(pParent, 539 rule.name, rule.protocol, 540 rule.hostIp, rule.hostPort, 541 rule.guestIp, rule.guestPort); 542 } 543 544 UIPortForwardingModel::~UIPortForwardingModel() 545 { 546 /* Delete the cached data: */ 547 qDeleteAll(m_dataList); 548 m_dataList.clear(); 549 } 550 551 const UIPortForwardingDataList UIPortForwardingModel::rules() const 552 { 553 /* Return the cached data: */ 554 UIPortForwardingDataList data; 555 foreach (const UIPortForwardingRow *pRow, m_dataList) 556 data << UIPortForwardingData(pRow->name(), pRow->protocol(), 557 pRow->hostIp(), pRow->hostPort(), 558 pRow->guestIp(), pRow->guestPort()); 559 return data; 560 } 334 561 335 562 void UIPortForwardingModel::addRule(const QModelIndex &index) … … 341 568 QRegExp regExp(strTemplate.arg("(\\d+)")); 342 569 for (int i = 0; i < m_dataList.size(); ++i) 343 if (regExp.indexIn(m_dataList[i] .name) > -1)570 if (regExp.indexIn(m_dataList[i]->name()) > -1) 344 571 uMaxIndex = regExp.cap(1).toUInt() > uMaxIndex ? regExp.cap(1).toUInt() : uMaxIndex; 345 572 /* If index is valid => copy data: */ 346 573 if (index.isValid()) 347 m_dataList << UIPortForwardingData(strTemplate.arg(++uMaxIndex), m_dataList[index.row()].protocol, 348 m_dataList[index.row()].hostIp, m_dataList[index.row()].hostPort, 349 m_dataList[index.row()].guestIp, m_dataList[index.row()].guestPort); 574 m_dataList << new UIPortForwardingRow(parentTable(), 575 strTemplate.arg(++uMaxIndex), m_dataList[index.row()]->protocol(), 576 m_dataList[index.row()]->hostIp(), m_dataList[index.row()]->hostPort(), 577 m_dataList[index.row()]->guestIp(), m_dataList[index.row()]->guestPort()); 350 578 /* If index is NOT valid => use default values: */ 351 579 else 352 m_dataList << UIPortForwardingData(strTemplate.arg(++uMaxIndex), KNATProtocol_TCP, 353 QString(""), 0, QString(""), 0); 580 m_dataList << new UIPortForwardingRow(parentTable(), 581 strTemplate.arg(++uMaxIndex), KNATProtocol_TCP, 582 QString(""), 0, QString(""), 0); 354 583 endInsertRows(); 355 584 } … … 360 589 return; 361 590 beginRemoveRows(QModelIndex(), index.row(), index.row()); 591 delete m_dataList.at(index.row()); 362 592 m_dataList.removeAt(index.row()); 363 593 endRemoveRows(); … … 418 648 switch (index.column()) 419 649 { 420 case UIPortForwardingDataType_Name: return m_dataList[index.row()] .name;421 case UIPortForwardingDataType_Protocol: return gpConverter->toString(m_dataList[index.row()] .protocol);422 case UIPortForwardingDataType_HostIp: return m_dataList[index.row()] .hostIp;423 case UIPortForwardingDataType_HostPort: return m_dataList[index.row()] .hostPort.value();424 case UIPortForwardingDataType_GuestIp: return m_dataList[index.row()] .guestIp;425 case UIPortForwardingDataType_GuestPort: return m_dataList[index.row()] .guestPort.value();650 case UIPortForwardingDataType_Name: return m_dataList[index.row()]->name(); 651 case UIPortForwardingDataType_Protocol: return gpConverter->toString(m_dataList[index.row()]->protocol()); 652 case UIPortForwardingDataType_HostIp: return m_dataList[index.row()]->hostIp(); 653 case UIPortForwardingDataType_HostPort: return m_dataList[index.row()]->hostPort().value(); 654 case UIPortForwardingDataType_GuestIp: return m_dataList[index.row()]->guestIp(); 655 case UIPortForwardingDataType_GuestPort: return m_dataList[index.row()]->guestPort().value(); 426 656 default: return QVariant(); 427 657 } … … 433 663 switch (index.column()) 434 664 { 435 case UIPortForwardingDataType_Name: return QVariant::fromValue(m_dataList[index.row()] .name);436 case UIPortForwardingDataType_Protocol: return QVariant::fromValue(m_dataList[index.row()] .protocol);437 case UIPortForwardingDataType_HostIp: return QVariant::fromValue(m_dataList[index.row()] .hostIp);438 case UIPortForwardingDataType_HostPort: return QVariant::fromValue(m_dataList[index.row()] .hostPort);439 case UIPortForwardingDataType_GuestIp: return QVariant::fromValue(m_dataList[index.row()] .guestIp);440 case UIPortForwardingDataType_GuestPort: return QVariant::fromValue(m_dataList[index.row()] .guestPort);665 case UIPortForwardingDataType_Name: return QVariant::fromValue(m_dataList[index.row()]->name()); 666 case UIPortForwardingDataType_Protocol: return QVariant::fromValue(m_dataList[index.row()]->protocol()); 667 case UIPortForwardingDataType_HostIp: return QVariant::fromValue(m_dataList[index.row()]->hostIp()); 668 case UIPortForwardingDataType_HostPort: return QVariant::fromValue(m_dataList[index.row()]->hostPort()); 669 case UIPortForwardingDataType_GuestIp: return QVariant::fromValue(m_dataList[index.row()]->guestIp()); 670 case UIPortForwardingDataType_GuestPort: return QVariant::fromValue(m_dataList[index.row()]->guestPort()); 441 671 default: return QVariant(); 442 672 } … … 485 715 { 486 716 case UIPortForwardingDataType_Name: 487 m_dataList[index.row()] .name = value.value<NameData>();717 m_dataList[index.row()]->setName(value.value<NameData>()); 488 718 emit dataChanged(index, index); 489 719 return true; 490 720 case UIPortForwardingDataType_Protocol: 491 m_dataList[index.row()] .protocol = value.value<KNATProtocol>();721 m_dataList[index.row()]->setProtocol(value.value<KNATProtocol>()); 492 722 emit dataChanged(index, index); 493 723 return true; 494 724 case UIPortForwardingDataType_HostIp: 495 m_dataList[index.row()] .hostIp = value.value<IpData>();725 m_dataList[index.row()]->setHostIp(value.value<IpData>()); 496 726 emit dataChanged(index, index); 497 727 return true; 498 728 case UIPortForwardingDataType_HostPort: 499 m_dataList[index.row()] .hostPort = value.value<PortData>();729 m_dataList[index.row()]->setHostPort(value.value<PortData>()); 500 730 emit dataChanged(index, index); 501 731 return true; 502 732 case UIPortForwardingDataType_GuestIp: 503 m_dataList[index.row()] .guestIp = value.value<IpData>();733 m_dataList[index.row()]->setGuestIp(value.value<IpData>()); 504 734 emit dataChanged(index, index); 505 735 return true; 506 736 case UIPortForwardingDataType_GuestPort: 507 m_dataList[index.row()] .guestPort = value.value<PortData>();737 m_dataList[index.row()]->setGuestPort(value.value<PortData>()); 508 738 emit dataChanged(index, index); 509 739 return true; … … 658 888 } 659 889 660 const UIPortForwardingDataList &UIPortForwardingTable::rules() const890 const UIPortForwardingDataList UIPortForwardingTable::rules() const 661 891 { 662 892 return m_pModel->rules(); -
trunk/src/VBox/Frontends/VirtualBox/src/widgets/UIPortForwardingTable.h
r62493 r64803 133 133 134 134 /* API: Rules stuff: */ 135 const UIPortForwardingDataList &rules() const;135 const UIPortForwardingDataList rules() const; 136 136 bool validate() const; 137 137
Note:
See TracChangeset
for help on using the changeset viewer.