From a30aac5f5b729a6d1f0162052ee6b9be8ac2e965 Mon Sep 17 00:00:00 2001 From: Salvo 'LtWorf' Tomaselli Date: Sat, 2 Jan 2016 15:28:17 +0100 Subject: [PATCH] Remove result text box It was not really easy to write the name for the result in a separate box, and it would create a lot of garbage results, by creating a new one per every query. Now single lines queries can contain assignments, and if not a default relation named 'last_' is used to hold the last result. --- relational_gui/guihandler.py | 34 +++----- relational_gui/maingui.ui | 161 +++++++++++++++-------------------- 2 files changed, 82 insertions(+), 113 deletions(-) diff --git a/relational_gui/guihandler.py b/relational_gui/guihandler.py index 5eeec66..2c4a252 100644 --- a/relational_gui/guihandler.py +++ b/relational_gui/guihandler.py @@ -37,7 +37,6 @@ class relForm(QtWidgets.QMainWindow): self.undo = None # UndoQueue for queries self.selectedRelation = None self.ui = maingui.Ui_MainWindow() - self.qcounter = 1 # Query counter self.user_interface = UserInterface() self.history_current_line = None @@ -79,8 +78,7 @@ class relForm(QtWidgets.QMainWindow): def next_history(self): if self.ui.lstHistory.currentRow() + 1 == self.ui.lstHistory.count() and self.history_current_line: - self.ui.txtResult.setText(self.history_current_line[0]) - self.ui.txtQuery.setText(self.history_current_line[1]) + self.ui.txtQuery.setText(self.history_current_line) self.history_current_line = None elif self.history_current_line: self.ui.lstHistory.setCurrentRow(self.ui.lstHistory.currentRow()+1) @@ -88,11 +86,13 @@ class relForm(QtWidgets.QMainWindow): def prev_history(self): if self.history_current_line is None: - self.history_current_line = (self.ui.txtResult.text(), self.ui.txtQuery.text()) - self.resumeHistory(self.ui.lstHistory.currentItem()) + self.history_current_line = self.ui.txtQuery.text() + + if not self.ui.lstHistory.currentItem().text() != self.ui.txtQuery.text(): + self.ui.lstHistory.setCurrentRow(self.ui.lstHistory.currentRow()-1) elif self.ui.lstHistory.currentRow() > 0: self.ui.lstHistory.setCurrentRow(self.ui.lstHistory.currentRow()-1) - self.resumeHistory(self.ui.lstHistory.currentItem()) + self.resumeHistory(self.ui.lstHistory.currentItem()) def add_shortcuts(self, shortcuts): for widget,shortcut,slot in shortcuts: @@ -143,10 +143,12 @@ class relForm(QtWidgets.QMainWindow): '''Performs all the possible optimizations on the query''' self.undo = self.ui.txtQuery.text() # Storing the query in undo list - query = self.ui.txtQuery.text() + res_rel,query = self.user_interface.split_query(self.ui.txtQuery.text(),None) try: result = optimizer.optimize_all( query, self.user_interface.relations) + if res_rel: + result = '%s = %s' % (res_rel, result) self.ui.txtQuery.setText(result) except Exception as e: self.error(e) @@ -154,9 +156,8 @@ class relForm(QtWidgets.QMainWindow): def resumeHistory(self, item): if item is None: return - itm = item.text().split(' = ', 1) - self.ui.txtResult.setText(itm[0]) - self.ui.txtQuery.setText(itm[1]) + itm = item.text() + self.ui.txtQuery.setText(itm) def _run_multiline(self): query = self.ui.txtMultiQuery.toPlainText() @@ -182,8 +183,7 @@ class relForm(QtWidgets.QMainWindow): return self._run_multiline() # Single line query - query = self.ui.txtQuery.text() - res_rel = self.ui.txtResult.text() # result relation's name + res_rel,query = self.user_interface.split_query(self.ui.txtQuery.text()) try: self.selectedRelation = self.user_interface.execute(query, res_rel) @@ -193,18 +193,10 @@ class relForm(QtWidgets.QMainWindow): return self.error(e) # Adds to history - item = u'%s = %s' % ( - self.ui.txtResult.text(), - self.ui.txtQuery.text() - ) hitem = QtWidgets.QListWidgetItem(None, 0) - hitem.setText(item) + hitem.setText(self.ui.txtQuery.text()) self.ui.lstHistory.addItem(hitem) self.ui.lstHistory.setCurrentItem(hitem) - - self.qcounter += 1 - # Sets the result relation name to none - self.ui.txtResult.setText(u"_last%d" % self.qcounter) finally: self.setMultiline(self.multiline) diff --git a/relational_gui/maingui.ui b/relational_gui/maingui.ui index 82516b5..e89a429 100644 --- a/relational_gui/maingui.ui +++ b/relational_gui/maingui.ui @@ -261,29 +261,6 @@ 0 - - - - - 0 - 0 - - - - _last1 - - - - - - - = - - - txtQuery - - - @@ -1161,8 +1138,8 @@ showAbout() - 97 - 74 + 95 + 444 79 @@ -1178,7 +1155,7 @@ 78 - 132 + 484 99 @@ -1193,8 +1170,8 @@ unloadRelation() - 677 - 396 + 516 + 490 773 @@ -1209,8 +1186,8 @@ saveRelation() - 783 - 322 + 631 + 422 760 @@ -1225,8 +1202,8 @@ loadRelation() - 677 - 322 + 516 + 422 753 @@ -1241,8 +1218,8 @@ printRelation(QListWidgetItem*) - 708 - 110 + 633 + 328 643 @@ -1257,8 +1234,8 @@ showAttributes(QListWidgetItem*) - 615 - 182 + 633 + 384 510 @@ -1353,8 +1330,8 @@ editRelation() - 783 - 359 + 631 + 456 399 @@ -1385,8 +1362,8 @@ newRelation() - 677 - 359 + 516 + 456 399 @@ -1449,12 +1426,12 @@ clear() - 556 - 608 + 251 + 256 - 432 - 578 + 221 + 286 @@ -1465,8 +1442,8 @@ execute() - 556 - 646 + 251 + 256 795 @@ -1481,12 +1458,12 @@ clear() - 696 - 700 + 310 + 491 - 606 - 699 + 260 + 490 @@ -1497,12 +1474,12 @@ clear() - 556 - 556 + 394 + 453 - 490 - 481 + 395 + 418 @@ -1513,8 +1490,8 @@ optimize() - 263 - 556 + 186 + 453 130 @@ -1529,8 +1506,8 @@ undoOptimize() - 409 - 556 + 296 + 453 544 @@ -1545,8 +1522,8 @@ execute() - 786 - 700 + 394 + 491 797 @@ -1561,8 +1538,8 @@ execute() - 606 - 699 + 260 + 490 796 @@ -1577,8 +1554,8 @@ resumeHistory(QListWidgetItem*) - 282 - 465 + 384 + 418 297 @@ -1593,8 +1570,8 @@ addProduct() - 67 - 183 + 46 + 87 399 @@ -1609,8 +1586,8 @@ addDifference() - 67 - 220 + 90 + 87 399 @@ -1625,8 +1602,8 @@ addUnion() - 67 - 257 + 46 + 121 399 @@ -1641,8 +1618,8 @@ addIntersection() - 67 - 294 + 90 + 121 399 @@ -1657,8 +1634,8 @@ addDivision() - 67 - 331 + 46 + 223 399 @@ -1673,8 +1650,8 @@ addOuter() - 67 - 479 + 90 + 155 399 @@ -1689,8 +1666,8 @@ addOLeft() - 67 - 405 + 46 + 189 399 @@ -1705,8 +1682,8 @@ addORight() - 67 - 442 + 90 + 189 399 @@ -1721,8 +1698,8 @@ addJoin() - 67 - 368 + 46 + 155 399 @@ -1737,8 +1714,8 @@ addProjection() - 67 - 516 + 90 + 257 399 @@ -1753,8 +1730,8 @@ addSelection() - 67 - 553 + 46 + 257 399 @@ -1769,8 +1746,8 @@ addRename() - 67 - 590 + 46 + 291 399 @@ -1785,8 +1762,8 @@ addArrow() - 67 - 627 + 90 + 291 399 @@ -1801,8 +1778,8 @@ newSession() - 736 - 378 + 631 + 490 796