Changeset c6fb57c in sasview for src/sas


Ignore:
Timestamp:
Nov 22, 2017 7:49:06 AM (7 years ago)
Author:
Piotr Rozyczko <rozyczko@…>
Branches:
ESS_GUI, ESS_GUI_Docs, ESS_GUI_batch_fitting, ESS_GUI_bumps_abstraction, ESS_GUI_iss1116, ESS_GUI_iss879, ESS_GUI_iss959, ESS_GUI_opencl, ESS_GUI_ordering, ESS_GUI_sync_sascalc
Children:
cb4d219
Parents:
0580c77
Message:

Add "delete" to the data explorer context menu

Location:
src/sas/qtgui/MainWindow
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • src/sas/qtgui/MainWindow/DataExplorer.py

    r6a3e1fe rc6fb57c  
    858858        self.context_menu.addAction(self.actionQuick3DPlot) 
    859859        self.context_menu.addAction(self.actionEditMask) 
     860        self.context_menu.addSeparator() 
     861        self.context_menu.addAction(self.actionDelete) 
     862 
    860863 
    861864        # Define the callbacks 
     
    865868        self.actionQuick3DPlot.triggered.connect(self.quickData3DPlot) 
    866869        self.actionEditMask.triggered.connect(self.showEditDataMask) 
     870        self.actionDelete.triggered.connect(self.deleteItem) 
    867871 
    868872    def onCustomContextMenu(self, position): 
     
    9961000        mask_editor.exec_() 
    9971001 
     1002    def deleteItem(self): 
     1003        """ 
     1004        Delete the current item 
     1005        """ 
     1006        # Assure this is indeed wanted 
     1007        delete_msg = "This operation will delete the selected data sets." +\ 
     1008                     "\nDo you want to continue?" 
     1009        reply = QtWidgets.QMessageBox.question(self, 
     1010                                           'Warning', 
     1011                                           delete_msg, 
     1012                                           QtWidgets.QMessageBox.Yes, 
     1013                                           QtWidgets.QMessageBox.No) 
     1014 
     1015        if reply == QtWidgets.QMessageBox.No: 
     1016            return 
     1017 
     1018        indices = self.current_view.selectedIndexes() 
     1019        proxy = self.current_view.model() 
     1020        model = proxy.sourceModel() 
     1021 
     1022        for index in indices: 
     1023            row_index = proxy.mapToSource(index) 
     1024            item_to_delete = model.itemFromIndex(row_index) 
     1025            if item_to_delete.isCheckable(): 
     1026                row = row_index.row() 
     1027                if item_to_delete.parent(): 
     1028                    # We have a child item - delete from it 
     1029                    item_to_delete.parent().removeRow(row) 
     1030                else: 
     1031                    # delete directly from model 
     1032                    model.removeRow(row) 
     1033        pass 
     1034 
    9981035    def loadComplete(self, output): 
    9991036        """ 
  • src/sas/qtgui/MainWindow/UI/DataExplorerUI.ui

    r61a92d4 rc6fb57c  
    499499   </property> 
    500500  </action> 
     501  <action name="actionDelete"> 
     502   <property name="text"> 
     503    <string>Delete</string> 
     504   </property> 
     505  </action> 
    501506 </widget> 
    502507 <resources/> 
  • src/sas/qtgui/MainWindow/UnitTesting/DataExplorerTest.py

    • Property mode changed from 100755 to 100644
    r53c771e rc6fb57c  
    2626import sas.qtgui.Plotting.PlotHelper as PlotHelper 
    2727 
    28 if not QApplication.instance(): 
    29     app = QApplication(sys.argv) 
     28#if not QApplication.instance(): 
     29app = QApplication(sys.argv) 
    3030 
    3131class DataExplorerTest(unittest.TestCase): 
     
    684684        self.form.treeView.customContextMenuRequested.emit(rect) 
    685685 
    686         # app.exec_() # debug 
    687  
    688686        # See that the menu has been shown 
    689687        self.form.context_menu.exec_.assert_called_once() 
     
    805803        pass 
    806804 
     805    def notestDeleteItem(self): 
     806        """ 
     807        Delete selected item from data explorer 
     808        """ 
     809 
     810        # Mock the confirmation dialog with return=No 
     811        QMessageBox.question = MagicMock(return_value=QMessageBox.No) 
     812 
     813        # Populate the model 
     814        filename = ["cyl_400_20.txt", "cyl_400_20.txt", "cyl_400_20.txt"] 
     815        self.form.readData(filename) 
     816 
     817        # Assure the model contains three items 
     818        self.assertEqual(self.form.model.rowCount(), 3) 
     819 
     820        # Add an item to first file item 
     821        item1 = QtGui.QStandardItem("test") 
     822        item1.setCheckable(True) 
     823        self.form.model.item(0).appendRow(item1) 
     824 
     825        # Check the new item is in 
     826 
     827        self.assertTrue(self.form.model.item(0).hasChildren()) 
     828 
     829        #select_item = self.form.model.item(0).child(3) 
     830        select_item = self.form.model.item(0) 
     831        select_index = self.form.model.indexFromItem(select_item) 
     832 
     833        # Open up items 
     834        self.form.current_view.expandAll() 
     835 
     836        # Select the newly created item 
     837        self.form.current_view.selectionModel().select(select_index, QtCore.QItemSelectionModel.Rows) 
     838 
     839        # Attempt at deleting 
     840        self.form.deleteItem() 
     841 
     842        # Test the warning dialog called once 
     843        self.assertTrue(QMessageBox.question.called) 
     844 
     845        # Assure the model still contains the items 
     846        self.assertEqual(self.form.model.rowCount(), 3) 
     847 
     848        # Now, mock the confirmation dialog with return=Yes 
     849        QMessageBox.question = MagicMock(return_value=QMessageBox.Yes) 
     850 
     851        # Select the newly created item 
     852        self.form.current_view.selectionModel().select(select_index, QtCore.QItemSelectionModel.Rows) 
     853        # delete it. now for good 
     854        self.form.deleteItem() 
     855 
     856        # Test the warning dialog called once 
     857        self.assertTrue(QMessageBox.question.called) 
     858 
     859        # Assure the model contains no items 
     860        self.assertEqual(self.form.model.rowCount(), 3) 
     861 
    807862 
    808863if __name__ == "__main__": 
Note: See TracChangeset for help on using the changeset viewer.