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.
master
Salvo 'LtWorf' Tomaselli 2016-01-02 15:28:17 +07:00
parent fd1e4610fa
commit a30aac5f5b
2 changed files with 82 additions and 113 deletions

@ -37,7 +37,6 @@ class relForm(QtWidgets.QMainWindow):
self.undo = None # UndoQueue for queries self.undo = None # UndoQueue for queries
self.selectedRelation = None self.selectedRelation = None
self.ui = maingui.Ui_MainWindow() self.ui = maingui.Ui_MainWindow()
self.qcounter = 1 # Query counter
self.user_interface = UserInterface() self.user_interface = UserInterface()
self.history_current_line = None self.history_current_line = None
@ -79,8 +78,7 @@ class relForm(QtWidgets.QMainWindow):
def next_history(self): def next_history(self):
if self.ui.lstHistory.currentRow() + 1 == self.ui.lstHistory.count() and self.history_current_line: 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)
self.ui.txtQuery.setText(self.history_current_line[1])
self.history_current_line = None self.history_current_line = None
elif self.history_current_line: elif self.history_current_line:
self.ui.lstHistory.setCurrentRow(self.ui.lstHistory.currentRow()+1) self.ui.lstHistory.setCurrentRow(self.ui.lstHistory.currentRow()+1)
@ -88,8 +86,10 @@ class relForm(QtWidgets.QMainWindow):
def prev_history(self): def prev_history(self):
if self.history_current_line is None: if self.history_current_line is None:
self.history_current_line = (self.ui.txtResult.text(), self.ui.txtQuery.text()) self.history_current_line = self.ui.txtQuery.text()
self.resumeHistory(self.ui.lstHistory.currentItem())
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: elif self.ui.lstHistory.currentRow() > 0:
self.ui.lstHistory.setCurrentRow(self.ui.lstHistory.currentRow()-1) self.ui.lstHistory.setCurrentRow(self.ui.lstHistory.currentRow()-1)
self.resumeHistory(self.ui.lstHistory.currentItem()) self.resumeHistory(self.ui.lstHistory.currentItem())
@ -143,10 +143,12 @@ class relForm(QtWidgets.QMainWindow):
'''Performs all the possible optimizations on the query''' '''Performs all the possible optimizations on the query'''
self.undo = self.ui.txtQuery.text() # Storing the query in undo list 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: try:
result = optimizer.optimize_all( result = optimizer.optimize_all(
query, self.user_interface.relations) query, self.user_interface.relations)
if res_rel:
result = '%s = %s' % (res_rel, result)
self.ui.txtQuery.setText(result) self.ui.txtQuery.setText(result)
except Exception as e: except Exception as e:
self.error(e) self.error(e)
@ -154,9 +156,8 @@ class relForm(QtWidgets.QMainWindow):
def resumeHistory(self, item): def resumeHistory(self, item):
if item is None: if item is None:
return return
itm = item.text().split(' = ', 1) itm = item.text()
self.ui.txtResult.setText(itm[0]) self.ui.txtQuery.setText(itm)
self.ui.txtQuery.setText(itm[1])
def _run_multiline(self): def _run_multiline(self):
query = self.ui.txtMultiQuery.toPlainText() query = self.ui.txtMultiQuery.toPlainText()
@ -182,8 +183,7 @@ class relForm(QtWidgets.QMainWindow):
return self._run_multiline() return self._run_multiline()
# Single line query # Single line query
query = self.ui.txtQuery.text() res_rel,query = self.user_interface.split_query(self.ui.txtQuery.text())
res_rel = self.ui.txtResult.text() # result relation's name
try: try:
self.selectedRelation = self.user_interface.execute(query, res_rel) self.selectedRelation = self.user_interface.execute(query, res_rel)
@ -193,18 +193,10 @@ class relForm(QtWidgets.QMainWindow):
return self.error(e) return self.error(e)
# Adds to history # Adds to history
item = u'%s = %s' % (
self.ui.txtResult.text(),
self.ui.txtQuery.text()
)
hitem = QtWidgets.QListWidgetItem(None, 0) hitem = QtWidgets.QListWidgetItem(None, 0)
hitem.setText(item) hitem.setText(self.ui.txtQuery.text())
self.ui.lstHistory.addItem(hitem) self.ui.lstHistory.addItem(hitem)
self.ui.lstHistory.setCurrentItem(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: finally:
self.setMultiline(self.multiline) self.setMultiline(self.multiline)

@ -261,29 +261,6 @@
<property name="spacing"> <property name="spacing">
<number>0</number> <number>0</number>
</property> </property>
<item>
<widget class="QLineEdit" name="txtResult">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>_last1</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>=</string>
</property>
<property name="buddy">
<cstring>txtQuery</cstring>
</property>
</widget>
</item>
<item> <item>
<widget class="QLineEdit" name="txtQuery"/> <widget class="QLineEdit" name="txtQuery"/>
</item> </item>
@ -1161,8 +1138,8 @@
<slot>showAbout()</slot> <slot>showAbout()</slot>
<hints> <hints>
<hint type="sourcelabel"> <hint type="sourcelabel">
<x>97</x> <x>95</x>
<y>74</y> <y>444</y>
</hint> </hint>
<hint type="destinationlabel"> <hint type="destinationlabel">
<x>79</x> <x>79</x>
@ -1178,7 +1155,7 @@
<hints> <hints>
<hint type="sourcelabel"> <hint type="sourcelabel">
<x>78</x> <x>78</x>
<y>132</y> <y>484</y>
</hint> </hint>
<hint type="destinationlabel"> <hint type="destinationlabel">
<x>99</x> <x>99</x>
@ -1193,8 +1170,8 @@
<slot>unloadRelation()</slot> <slot>unloadRelation()</slot>
<hints> <hints>
<hint type="sourcelabel"> <hint type="sourcelabel">
<x>677</x> <x>516</x>
<y>396</y> <y>490</y>
</hint> </hint>
<hint type="destinationlabel"> <hint type="destinationlabel">
<x>773</x> <x>773</x>
@ -1209,8 +1186,8 @@
<slot>saveRelation()</slot> <slot>saveRelation()</slot>
<hints> <hints>
<hint type="sourcelabel"> <hint type="sourcelabel">
<x>783</x> <x>631</x>
<y>322</y> <y>422</y>
</hint> </hint>
<hint type="destinationlabel"> <hint type="destinationlabel">
<x>760</x> <x>760</x>
@ -1225,8 +1202,8 @@
<slot>loadRelation()</slot> <slot>loadRelation()</slot>
<hints> <hints>
<hint type="sourcelabel"> <hint type="sourcelabel">
<x>677</x> <x>516</x>
<y>322</y> <y>422</y>
</hint> </hint>
<hint type="destinationlabel"> <hint type="destinationlabel">
<x>753</x> <x>753</x>
@ -1241,8 +1218,8 @@
<slot>printRelation(QListWidgetItem*)</slot> <slot>printRelation(QListWidgetItem*)</slot>
<hints> <hints>
<hint type="sourcelabel"> <hint type="sourcelabel">
<x>708</x> <x>633</x>
<y>110</y> <y>328</y>
</hint> </hint>
<hint type="destinationlabel"> <hint type="destinationlabel">
<x>643</x> <x>643</x>
@ -1257,8 +1234,8 @@
<slot>showAttributes(QListWidgetItem*)</slot> <slot>showAttributes(QListWidgetItem*)</slot>
<hints> <hints>
<hint type="sourcelabel"> <hint type="sourcelabel">
<x>615</x> <x>633</x>
<y>182</y> <y>384</y>
</hint> </hint>
<hint type="destinationlabel"> <hint type="destinationlabel">
<x>510</x> <x>510</x>
@ -1353,8 +1330,8 @@
<slot>editRelation()</slot> <slot>editRelation()</slot>
<hints> <hints>
<hint type="sourcelabel"> <hint type="sourcelabel">
<x>783</x> <x>631</x>
<y>359</y> <y>456</y>
</hint> </hint>
<hint type="destinationlabel"> <hint type="destinationlabel">
<x>399</x> <x>399</x>
@ -1385,8 +1362,8 @@
<slot>newRelation()</slot> <slot>newRelation()</slot>
<hints> <hints>
<hint type="sourcelabel"> <hint type="sourcelabel">
<x>677</x> <x>516</x>
<y>359</y> <y>456</y>
</hint> </hint>
<hint type="destinationlabel"> <hint type="destinationlabel">
<x>399</x> <x>399</x>
@ -1449,12 +1426,12 @@
<slot>clear()</slot> <slot>clear()</slot>
<hints> <hints>
<hint type="sourcelabel"> <hint type="sourcelabel">
<x>556</x> <x>251</x>
<y>608</y> <y>256</y>
</hint> </hint>
<hint type="destinationlabel"> <hint type="destinationlabel">
<x>432</x> <x>221</x>
<y>578</y> <y>286</y>
</hint> </hint>
</hints> </hints>
</connection> </connection>
@ -1465,8 +1442,8 @@
<slot>execute()</slot> <slot>execute()</slot>
<hints> <hints>
<hint type="sourcelabel"> <hint type="sourcelabel">
<x>556</x> <x>251</x>
<y>646</y> <y>256</y>
</hint> </hint>
<hint type="destinationlabel"> <hint type="destinationlabel">
<x>795</x> <x>795</x>
@ -1481,12 +1458,12 @@
<slot>clear()</slot> <slot>clear()</slot>
<hints> <hints>
<hint type="sourcelabel"> <hint type="sourcelabel">
<x>696</x> <x>310</x>
<y>700</y> <y>491</y>
</hint> </hint>
<hint type="destinationlabel"> <hint type="destinationlabel">
<x>606</x> <x>260</x>
<y>699</y> <y>490</y>
</hint> </hint>
</hints> </hints>
</connection> </connection>
@ -1497,12 +1474,12 @@
<slot>clear()</slot> <slot>clear()</slot>
<hints> <hints>
<hint type="sourcelabel"> <hint type="sourcelabel">
<x>556</x> <x>394</x>
<y>556</y> <y>453</y>
</hint> </hint>
<hint type="destinationlabel"> <hint type="destinationlabel">
<x>490</x> <x>395</x>
<y>481</y> <y>418</y>
</hint> </hint>
</hints> </hints>
</connection> </connection>
@ -1513,8 +1490,8 @@
<slot>optimize()</slot> <slot>optimize()</slot>
<hints> <hints>
<hint type="sourcelabel"> <hint type="sourcelabel">
<x>263</x> <x>186</x>
<y>556</y> <y>453</y>
</hint> </hint>
<hint type="destinationlabel"> <hint type="destinationlabel">
<x>130</x> <x>130</x>
@ -1529,8 +1506,8 @@
<slot>undoOptimize()</slot> <slot>undoOptimize()</slot>
<hints> <hints>
<hint type="sourcelabel"> <hint type="sourcelabel">
<x>409</x> <x>296</x>
<y>556</y> <y>453</y>
</hint> </hint>
<hint type="destinationlabel"> <hint type="destinationlabel">
<x>544</x> <x>544</x>
@ -1545,8 +1522,8 @@
<slot>execute()</slot> <slot>execute()</slot>
<hints> <hints>
<hint type="sourcelabel"> <hint type="sourcelabel">
<x>786</x> <x>394</x>
<y>700</y> <y>491</y>
</hint> </hint>
<hint type="destinationlabel"> <hint type="destinationlabel">
<x>797</x> <x>797</x>
@ -1561,8 +1538,8 @@
<slot>execute()</slot> <slot>execute()</slot>
<hints> <hints>
<hint type="sourcelabel"> <hint type="sourcelabel">
<x>606</x> <x>260</x>
<y>699</y> <y>490</y>
</hint> </hint>
<hint type="destinationlabel"> <hint type="destinationlabel">
<x>796</x> <x>796</x>
@ -1577,8 +1554,8 @@
<slot>resumeHistory(QListWidgetItem*)</slot> <slot>resumeHistory(QListWidgetItem*)</slot>
<hints> <hints>
<hint type="sourcelabel"> <hint type="sourcelabel">
<x>282</x> <x>384</x>
<y>465</y> <y>418</y>
</hint> </hint>
<hint type="destinationlabel"> <hint type="destinationlabel">
<x>297</x> <x>297</x>
@ -1593,8 +1570,8 @@
<slot>addProduct()</slot> <slot>addProduct()</slot>
<hints> <hints>
<hint type="sourcelabel"> <hint type="sourcelabel">
<x>67</x> <x>46</x>
<y>183</y> <y>87</y>
</hint> </hint>
<hint type="destinationlabel"> <hint type="destinationlabel">
<x>399</x> <x>399</x>
@ -1609,8 +1586,8 @@
<slot>addDifference()</slot> <slot>addDifference()</slot>
<hints> <hints>
<hint type="sourcelabel"> <hint type="sourcelabel">
<x>67</x> <x>90</x>
<y>220</y> <y>87</y>
</hint> </hint>
<hint type="destinationlabel"> <hint type="destinationlabel">
<x>399</x> <x>399</x>
@ -1625,8 +1602,8 @@
<slot>addUnion()</slot> <slot>addUnion()</slot>
<hints> <hints>
<hint type="sourcelabel"> <hint type="sourcelabel">
<x>67</x> <x>46</x>
<y>257</y> <y>121</y>
</hint> </hint>
<hint type="destinationlabel"> <hint type="destinationlabel">
<x>399</x> <x>399</x>
@ -1641,8 +1618,8 @@
<slot>addIntersection()</slot> <slot>addIntersection()</slot>
<hints> <hints>
<hint type="sourcelabel"> <hint type="sourcelabel">
<x>67</x> <x>90</x>
<y>294</y> <y>121</y>
</hint> </hint>
<hint type="destinationlabel"> <hint type="destinationlabel">
<x>399</x> <x>399</x>
@ -1657,8 +1634,8 @@
<slot>addDivision()</slot> <slot>addDivision()</slot>
<hints> <hints>
<hint type="sourcelabel"> <hint type="sourcelabel">
<x>67</x> <x>46</x>
<y>331</y> <y>223</y>
</hint> </hint>
<hint type="destinationlabel"> <hint type="destinationlabel">
<x>399</x> <x>399</x>
@ -1673,8 +1650,8 @@
<slot>addOuter()</slot> <slot>addOuter()</slot>
<hints> <hints>
<hint type="sourcelabel"> <hint type="sourcelabel">
<x>67</x> <x>90</x>
<y>479</y> <y>155</y>
</hint> </hint>
<hint type="destinationlabel"> <hint type="destinationlabel">
<x>399</x> <x>399</x>
@ -1689,8 +1666,8 @@
<slot>addOLeft()</slot> <slot>addOLeft()</slot>
<hints> <hints>
<hint type="sourcelabel"> <hint type="sourcelabel">
<x>67</x> <x>46</x>
<y>405</y> <y>189</y>
</hint> </hint>
<hint type="destinationlabel"> <hint type="destinationlabel">
<x>399</x> <x>399</x>
@ -1705,8 +1682,8 @@
<slot>addORight()</slot> <slot>addORight()</slot>
<hints> <hints>
<hint type="sourcelabel"> <hint type="sourcelabel">
<x>67</x> <x>90</x>
<y>442</y> <y>189</y>
</hint> </hint>
<hint type="destinationlabel"> <hint type="destinationlabel">
<x>399</x> <x>399</x>
@ -1721,8 +1698,8 @@
<slot>addJoin()</slot> <slot>addJoin()</slot>
<hints> <hints>
<hint type="sourcelabel"> <hint type="sourcelabel">
<x>67</x> <x>46</x>
<y>368</y> <y>155</y>
</hint> </hint>
<hint type="destinationlabel"> <hint type="destinationlabel">
<x>399</x> <x>399</x>
@ -1737,8 +1714,8 @@
<slot>addProjection()</slot> <slot>addProjection()</slot>
<hints> <hints>
<hint type="sourcelabel"> <hint type="sourcelabel">
<x>67</x> <x>90</x>
<y>516</y> <y>257</y>
</hint> </hint>
<hint type="destinationlabel"> <hint type="destinationlabel">
<x>399</x> <x>399</x>
@ -1753,8 +1730,8 @@
<slot>addSelection()</slot> <slot>addSelection()</slot>
<hints> <hints>
<hint type="sourcelabel"> <hint type="sourcelabel">
<x>67</x> <x>46</x>
<y>553</y> <y>257</y>
</hint> </hint>
<hint type="destinationlabel"> <hint type="destinationlabel">
<x>399</x> <x>399</x>
@ -1769,8 +1746,8 @@
<slot>addRename()</slot> <slot>addRename()</slot>
<hints> <hints>
<hint type="sourcelabel"> <hint type="sourcelabel">
<x>67</x> <x>46</x>
<y>590</y> <y>291</y>
</hint> </hint>
<hint type="destinationlabel"> <hint type="destinationlabel">
<x>399</x> <x>399</x>
@ -1785,8 +1762,8 @@
<slot>addArrow()</slot> <slot>addArrow()</slot>
<hints> <hints>
<hint type="sourcelabel"> <hint type="sourcelabel">
<x>67</x> <x>90</x>
<y>627</y> <y>291</y>
</hint> </hint>
<hint type="destinationlabel"> <hint type="destinationlabel">
<x>399</x> <x>399</x>
@ -1801,8 +1778,8 @@
<slot>newSession()</slot> <slot>newSession()</slot>
<hints> <hints>
<hint type="sourcelabel"> <hint type="sourcelabel">
<x>736</x> <x>631</x>
<y>378</y> <y>490</y>
</hint> </hint>
<hint type="destinationlabel"> <hint type="destinationlabel">
<x>796</x> <x>796</x>