Changeset 58377 in vbox for trunk/src/VBox
- Timestamp:
- Oct 22, 2015 12:29:26 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/src/extradata/UIExtraDataManager.cpp
r57591 r58377 682 682 /* If 'changed value' is NOT empty => UPDATE item: */ 683 683 else 684 { 685 m_pModelSourceOfData->itemFromIndex(dataKeyIndex(iPosition))->setData(strKey, Qt::UserRole); 684 686 m_pModelSourceOfData->itemFromIndex(dataValueIndex(iPosition))->setText(strValue); 687 } 685 688 } 686 689 /* Else if 'changed value' is NOT empty: */ … … 758 761 void UIExtraDataManagerWindow::sltDataHandleItemChanged(QStandardItem *pItem) 759 762 { 760 /* Value-data index: */ 761 const QModelIndex valueIndex = m_pModelSourceOfData->indexFromItem(pItem); 762 const int iRow = valueIndex.row(); 763 const int iColumn = valueIndex.column(); 764 AssertMsgReturnVoid(iColumn == 1, ("Only 2nd column can be changed!\n")); 765 766 /* Key-data index: */ 767 const QModelIndex keyIndex = dataKeyIndex(iRow); 768 769 /* Update extra-data: */ 770 gEDataManager->setExtraDataString(keyIndex.data().toString(), 771 valueIndex.data().toString(), 772 currentChooserID()); 763 /* Make sure passed item is valid: */ 764 AssertPtrReturnVoid(pItem); 765 766 /* Item-data index: */ 767 const QModelIndex itemIndex = m_pModelSourceOfData->indexFromItem(pItem); 768 const int iRow = itemIndex.row(); 769 const int iColumn = itemIndex.column(); 770 771 /* Key-data is changed: */ 772 if (iColumn == 0) 773 { 774 /* Should we replace changed key? */ 775 bool fReplace = true; 776 777 /* List of 'known keys': */ 778 QStringList knownKeys; 779 for (int iKeyRow = 0; iKeyRow < m_pModelSourceOfData->rowCount(); ++iKeyRow) 780 { 781 /* Do not consider the row we are changing as Qt's model is not yet updated: */ 782 if (iKeyRow != iRow) 783 knownKeys << dataKey(iKeyRow); 784 } 785 786 /* If changed key exists: */ 787 if (knownKeys.contains(itemIndex.data().toString())) 788 { 789 /* Show warning and ask for overwriting approval: */ 790 if (!msgCenter().questionBinary(this, MessageType_Question, 791 QString("Overwriting already existing key, Continue?"), 792 0 /* auto-confirm id */, 793 QString("Overwrite") /* ok button text */, 794 QString() /* cancel button text */, 795 false /* ok button by default? */)) 796 { 797 /* Cancel the operation, restore the original extra-data key: */ 798 pItem->setData(itemIndex.data(Qt::UserRole).toString(), Qt::DisplayRole); 799 fReplace = false; 800 } 801 else 802 { 803 /* Delete previous extra-data key: */ 804 gEDataManager->setExtraDataString(itemIndex.data().toString(), 805 QString(), 806 currentChooserID()); 807 } 808 } 809 810 /* Replace changed extra-data key if necessary: */ 811 if (fReplace) 812 { 813 gEDataManager->setExtraDataString(itemIndex.data(Qt::UserRole).toString(), 814 QString(), 815 currentChooserID()); 816 gEDataManager->setExtraDataString(itemIndex.data().toString(), 817 dataValue(iRow), 818 currentChooserID()); 819 } 820 } 821 /* Value-data is changed: */ 822 else 823 { 824 /* Key-data index: */ 825 const QModelIndex keyIndex = dataKeyIndex(iRow); 826 /* Update extra-data: */ 827 gEDataManager->setExtraDataString(keyIndex.data().toString(), 828 itemIndex.data().toString(), 829 currentChooserID()); 830 } 773 831 } 774 832 … … 908 966 if (pInputDialog->exec() == QDialog::Accepted) 909 967 { 910 gEDataManager->setExtraDataString(pInputDialog->property("Key").toString(), 911 pInputDialog->property("Value").toString(), 912 currentChooserID()); 968 /* Should we add new key? */ 969 bool fAdd = true; 970 971 /* List of 'known keys': */ 972 QStringList knownKeys; 973 for (int iKeyRow = 0; iKeyRow < m_pModelSourceOfData->rowCount(); ++iKeyRow) 974 knownKeys << dataKey(iKeyRow); 975 976 /* If new key exists: */ 977 if (knownKeys.contains(pInputDialog->property("Key").toString())) 978 { 979 /* Show warning and ask for overwriting approval: */ 980 if (!msgCenter().questionBinary(this, MessageType_Question, 981 QString("Overwriting already existing key, Continue?"), 982 0 /* auto-confirm id */, 983 QString("Overwrite") /* ok button text */, 984 QString() /* cancel button text */, 985 false /* ok button by default? */)) 986 { 987 /* Cancel the operation: */ 988 fAdd = false; 989 } 990 } 991 992 /* Add new extra-data key if necessary: */ 993 if (fAdd) 994 gEDataManager->setExtraDataString(pInputDialog->property("Key").toString(), 995 pInputDialog->property("Value").toString(), 996 currentChooserID()); 913 997 } 914 998 … … 1703 1787 /* Create key item: */ 1704 1788 items << new QStandardItem(strKey); 1705 items.last()->set Editable(false);1789 items.last()->setData(strKey, Qt::UserRole); 1706 1790 AssertPtrReturnVoid(items.last()); 1707 1791 /* Create value item: */
Note:
See TracChangeset
for help on using the changeset viewer.