Support multi-line editing mode

This mode supports the insertion of multiple queries in one shot,
assign them to variables and reuse them.

Basically a program. Less interactive mode but better for more
complicated queries.
master
Salvo 'LtWorf' Tomaselli 2015-06-01 00:00:59 +07:00
parent 2341f93cf6
commit f3af25f132
2 changed files with 411 additions and 255 deletions

@ -61,6 +61,14 @@ class relForm(QtWidgets.QMainWindow):
QtWidgets.QMessageBox.information( QtWidgets.QMessageBox.information(
self, QtWidgets.QApplication.translate("Form", "Version"), r) self, QtWidgets.QApplication.translate("Form", "Version"), r)
def setMultiline(self, multiline):
self.multiline = multiline
self.settings.setValue('multiline', multiline)
self.ui.lineExpressionFrame.setVisible(not multiline)
self.ui.frmOptimizations.setVisible(not multiline)
self.ui.frmMultiLine.setVisible(multiline)
self.ui.actionMulti_line_mode.setChecked(multiline)
def load_query(self, *index): def load_query(self, *index):
self.ui.txtQuery.setText(self.savedQ.itemData(index[0]).toString()) self.ui.txtQuery.setText(self.savedQ.itemData(index[0]).toString())
@ -88,7 +96,37 @@ class relForm(QtWidgets.QMainWindow):
def execute(self): def execute(self):
'''Executes the query''' '''Executes the query'''
if self.multiline:
query = compatibility.get_py_str(self.ui.txtMultiQuery.toPlainText())
queries = query.split('\n')
for query in queries:
if query.strip() == '':
continue
parts = query.split('=', 1)
parts[0] = parts[0].strip()
if len(parts) > 1 and rtypes.is_valid_relation_name(parts[0].strip()):
relname = parts[0].strip()
query = parts[1]
else:
relname = 'last_'
try:
expr = parser.parse(query)
result = eval(expr, self.relations)
self.relations[relname] = result
self.updateRelations() # update the list
self.selectedRelation = result
self.showRelation(self.selectedRelation)
except Exception as e:
print(str(e))
QtWidgets.QMessageBox.information(None, QtWidgets.QApplication.translate("Form", "Error"), u"%s\n%s" %
(QtWidgets.QApplication.translate("Form", "Check your query!"), str(e)))
return
#Single line query
query = compatibility.get_py_str(self.ui.txtQuery.text()) query = compatibility.get_py_str(self.ui.txtQuery.text())
res_rel = compatibility.get_py_str( res_rel = compatibility.get_py_str(
self.ui.txtResult.text()) # result relation's name self.ui.txtResult.text()) # result relation's name
@ -238,7 +276,7 @@ class relForm(QtWidgets.QMainWindow):
def restore_settings(self): def restore_settings(self):
# self.settings.value('session_name','default').toString() # self.settings.value('session_name','default').toString()
pass self.setMultiline(self.settings.value('multiline','false')=='true')
def showSurvey(self): def showSurvey(self):
if self.Survey == None: if self.Survey == None:
@ -343,5 +381,9 @@ class relForm(QtWidgets.QMainWindow):
self.addSymbolInQuery(parser.ARROW) self.addSymbolInQuery(parser.ARROW)
def addSymbolInQuery(self, symbol): def addSymbolInQuery(self, symbol):
if self.multiline:
self.ui.txtMultiQuery.insertPlainText(symbol)
self.ui.txtMultiQuery.setFocus()
else:
self.ui.txtQuery.insert(symbol) self.ui.txtQuery.insert(symbol)
self.ui.txtQuery.setFocus() self.ui.txtQuery.setFocus()

@ -8,7 +8,7 @@
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>800</width> <width>800</width>
<height>612</height> <height>669</height>
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
@ -232,6 +232,18 @@
<property name="sizeConstraint"> <property name="sizeConstraint">
<enum>QLayout::SetMinimumSize</enum> <enum>QLayout::SetMinimumSize</enum>
</property> </property>
<item>
<widget class="QFrame" name="frmOptimizations">
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Plain</enum>
</property>
<property name="lineWidth">
<number>0</number>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item> <item>
<widget class="QListWidget" name="lstHistory"> <widget class="QListWidget" name="lstHistory">
<property name="sizePolicy"> <property name="sizePolicy">
@ -281,6 +293,67 @@
</item> </item>
</layout> </layout>
</widget> </widget>
</item>
<item>
<widget class="QFrame" name="frmMultiLine">
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Plain</enum>
</property>
<property name="lineWidth">
<number>0</number>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QPlainTextEdit" name="txtMultiQuery">
<property name="font">
<font>
<family>DejaVu Sans</family>
<pointsize>11</pointsize>
<weight>50</weight>
<italic>false</italic>
<bold>false</bold>
<underline>false</underline>
<strikeout>false</strikeout>
<kerning>true</kerning>
</font>
</property>
<property name="plainText">
<string/>
</property>
</widget>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout_4">
<item>
<widget class="QPushButton" name="cmdClearMultilineQuery">
<property name="text">
<string>⌫</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="cmdExecuteMultiline">
<property name="text">
<string>Execute</string>
</property>
<property name="autoDefault">
<bool>false</bool>
</property>
<property name="default">
<bool>false</bool>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
</widget> </widget>
<widget class="QSplitter" name="splitter"> <widget class="QSplitter" name="splitter">
<property name="orientation"> <property name="orientation">
@ -399,7 +472,17 @@
</widget> </widget>
</item> </item>
<item> <item>
<layout class="QHBoxLayout" name="horizontalLayout_2"> <widget class="QFrame" name="lineExpressionFrame">
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Plain</enum>
</property>
<property name="lineWidth">
<number>0</number>
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<item> <item>
<widget class="QLineEdit" name="txtResult"> <widget class="QLineEdit" name="txtResult">
<property name="sizePolicy"> <property name="sizePolicy">
@ -438,9 +521,16 @@
<property name="text"> <property name="text">
<string>Execute</string> <string>Execute</string>
</property> </property>
<property name="autoDefault">
<bool>true</bool>
</property>
<property name="default">
<bool>true</bool>
</property>
</widget> </widget>
</item> </item>
</layout> </layout>
</widget>
</item> </item>
</layout> </layout>
</widget> </widget>
@ -478,8 +568,15 @@
<addaction name="actionEdit_relation"/> <addaction name="actionEdit_relation"/>
<addaction name="actionUnload_relation"/> <addaction name="actionUnload_relation"/>
</widget> </widget>
<widget class="QMenu" name="menuSettings">
<property name="title">
<string>Settings</string>
</property>
<addaction name="actionMulti_line_mode"/>
</widget>
<addaction name="menuFile"/> <addaction name="menuFile"/>
<addaction name="menuRelations"/> <addaction name="menuRelations"/>
<addaction name="menuSettings"/>
<addaction name="menuAbout"/> <addaction name="menuAbout"/>
</widget> </widget>
<action name="actionAbout"> <action name="actionAbout">
@ -561,6 +658,17 @@
<string>Unload relation</string> <string>Unload relation</string>
</property> </property>
</action> </action>
<action name="actionMulti_line_mode">
<property name="checkable">
<bool>true</bool>
</property>
<property name="text">
<string>Multi-line mode</string>
</property>
<property name="shortcut">
<string>Ctrl+L</string>
</property>
</action>
</widget> </widget>
<tabstops> <tabstops>
<tabstop>cmdAbout</tabstop> <tabstop>cmdAbout</tabstop>
@ -583,9 +691,14 @@
<tabstop>cmdOptimize</tabstop> <tabstop>cmdOptimize</tabstop>
<tabstop>cmdUndoOptimize</tabstop> <tabstop>cmdUndoOptimize</tabstop>
<tabstop>cmdClearHistory</tabstop> <tabstop>cmdClearHistory</tabstop>
<tabstop>txtMultiQuery</tabstop>
<tabstop>cmdClearMultilineQuery</tabstop>
<tabstop>cmdExecuteMultiline</tabstop>
<tabstop>lstRelations</tabstop> <tabstop>lstRelations</tabstop>
<tabstop>cmdNew</tabstop>
<tabstop>cmdLoad</tabstop> <tabstop>cmdLoad</tabstop>
<tabstop>cmdSave</tabstop> <tabstop>cmdSave</tabstop>
<tabstop>cmdEdit</tabstop>
<tabstop>cmdUnload</tabstop> <tabstop>cmdUnload</tabstop>
<tabstop>lstAttributes</tabstop> <tabstop>lstAttributes</tabstop>
<tabstop>txtResult</tabstop> <tabstop>txtResult</tabstop>
@ -595,70 +708,6 @@
</tabstops> </tabstops>
<resources/> <resources/>
<connections> <connections>
<connection>
<sender>cmdClearQuery</sender>
<signal>clicked()</signal>
<receiver>txtQuery</receiver>
<slot>clear()</slot>
<hints>
<hint type="sourcelabel">
<x>686</x>
<y>591</y>
</hint>
<hint type="destinationlabel">
<x>206</x>
<y>591</y>
</hint>
</hints>
</connection>
<connection>
<sender>cmdClearHistory</sender>
<signal>clicked()</signal>
<receiver>lstHistory</receiver>
<slot>clear()</slot>
<hints>
<hint type="sourcelabel">
<x>490</x>
<y>563</y>
</hint>
<hint type="destinationlabel">
<x>397</x>
<y>525</y>
</hint>
</hints>
</connection>
<connection>
<sender>txtQuery</sender>
<signal>returnPressed()</signal>
<receiver>MainWindow</receiver>
<slot>execute()</slot>
<hints>
<hint type="sourcelabel">
<x>450</x>
<y>599</y>
</hint>
<hint type="destinationlabel">
<x>438</x>
<y>611</y>
</hint>
</hints>
</connection>
<connection>
<sender>cmdExecute</sender>
<signal>clicked()</signal>
<receiver>MainWindow</receiver>
<slot>execute()</slot>
<hints>
<hint type="sourcelabel">
<x>732</x>
<y>592</y>
</hint>
<hint type="destinationlabel">
<x>592</x>
<y>611</y>
</hint>
</hints>
</connection>
<connection> <connection>
<sender>cmdAbout</sender> <sender>cmdAbout</sender>
<signal>clicked()</signal> <signal>clicked()</signal>
@ -666,8 +715,8 @@
<slot>showAbout()</slot> <slot>showAbout()</slot>
<hints> <hints>
<hint type="sourcelabel"> <hint type="sourcelabel">
<x>82</x> <x>97</x>
<y>75</y> <y>74</y>
</hint> </hint>
<hint type="destinationlabel"> <hint type="destinationlabel">
<x>79</x> <x>79</x>
@ -730,8 +779,8 @@
<slot>addArrow()</slot> <slot>addArrow()</slot>
<hints> <hints>
<hint type="sourcelabel"> <hint type="sourcelabel">
<x>107</x> <x>101</x>
<y>490</y> <y>538</y>
</hint> </hint>
<hint type="destinationlabel"> <hint type="destinationlabel">
<x>58</x> <x>58</x>
@ -746,8 +795,8 @@
<slot>addRename()</slot> <slot>addRename()</slot>
<hints> <hints>
<hint type="sourcelabel"> <hint type="sourcelabel">
<x>54</x> <x>69</x>
<y>463</y> <y>507</y>
</hint> </hint>
<hint type="destinationlabel"> <hint type="destinationlabel">
<x>111</x> <x>111</x>
@ -762,8 +811,8 @@
<slot>addSelection()</slot> <slot>addSelection()</slot>
<hints> <hints>
<hint type="sourcelabel"> <hint type="sourcelabel">
<x>84</x> <x>99</x>
<y>436</y> <y>476</y>
</hint> </hint>
<hint type="destinationlabel"> <hint type="destinationlabel">
<x>16</x> <x>16</x>
@ -778,8 +827,8 @@
<slot>addProjection()</slot> <slot>addProjection()</slot>
<hints> <hints>
<hint type="sourcelabel"> <hint type="sourcelabel">
<x>107</x> <x>101</x>
<y>409</y> <y>445</y>
</hint> </hint>
<hint type="destinationlabel"> <hint type="destinationlabel">
<x>91</x> <x>91</x>
@ -794,8 +843,8 @@
<slot>unloadRelation()</slot> <slot>unloadRelation()</slot>
<hints> <hints>
<hint type="sourcelabel"> <hint type="sourcelabel">
<x>788</x> <x>785</x>
<y>280</y> <y>387</y>
</hint> </hint>
<hint type="destinationlabel"> <hint type="destinationlabel">
<x>773</x> <x>773</x>
@ -810,8 +859,8 @@
<slot>saveRelation()</slot> <slot>saveRelation()</slot>
<hints> <hints>
<hint type="sourcelabel"> <hint type="sourcelabel">
<x>788</x> <x>785</x>
<y>253</y> <y>325</y>
</hint> </hint>
<hint type="destinationlabel"> <hint type="destinationlabel">
<x>760</x> <x>760</x>
@ -826,8 +875,8 @@
<slot>loadRelation()</slot> <slot>loadRelation()</slot>
<hints> <hints>
<hint type="sourcelabel"> <hint type="sourcelabel">
<x>788</x> <x>785</x>
<y>226</y> <y>294</y>
</hint> </hint>
<hint type="destinationlabel"> <hint type="destinationlabel">
<x>753</x> <x>753</x>
@ -835,54 +884,6 @@
</hint> </hint>
</hints> </hints>
</connection> </connection>
<connection>
<sender>cmdOptimize</sender>
<signal>clicked()</signal>
<receiver>MainWindow</receiver>
<slot>optimize()</slot>
<hints>
<hint type="sourcelabel">
<x>245</x>
<y>554</y>
</hint>
<hint type="destinationlabel">
<x>684</x>
<y>611</y>
</hint>
</hints>
</connection>
<connection>
<sender>cmdUndoOptimize</sender>
<signal>clicked()</signal>
<receiver>MainWindow</receiver>
<slot>undoOptimize()</slot>
<hints>
<hint type="sourcelabel">
<x>336</x>
<y>560</y>
</hint>
<hint type="destinationlabel">
<x>652</x>
<y>604</y>
</hint>
</hints>
</connection>
<connection>
<sender>txtResult</sender>
<signal>returnPressed()</signal>
<receiver>txtQuery</receiver>
<slot>setFocus()</slot>
<hints>
<hint type="sourcelabel">
<x>87</x>
<y>590</y>
</hint>
<hint type="destinationlabel">
<x>182</x>
<y>590</y>
</hint>
</hints>
</connection>
<connection> <connection>
<sender>cmdOuterRight</sender> <sender>cmdOuterRight</sender>
<signal>clicked()</signal> <signal>clicked()</signal>
@ -890,8 +891,8 @@
<slot>addORight()</slot> <slot>addORight()</slot>
<hints> <hints>
<hint type="sourcelabel"> <hint type="sourcelabel">
<x>102</x> <x>101</x>
<y>355</y> <y>383</y>
</hint> </hint>
<hint type="destinationlabel"> <hint type="destinationlabel">
<x>58</x> <x>58</x>
@ -906,8 +907,8 @@
<slot>addOuter()</slot> <slot>addOuter()</slot>
<hints> <hints>
<hint type="sourcelabel"> <hint type="sourcelabel">
<x>46</x> <x>61</x>
<y>382</y> <y>414</y>
</hint> </hint>
<hint type="destinationlabel"> <hint type="destinationlabel">
<x>86</x> <x>86</x>
@ -938,8 +939,8 @@
<slot>addJoin()</slot> <slot>addJoin()</slot>
<hints> <hints>
<hint type="sourcelabel"> <hint type="sourcelabel">
<x>107</x> <x>101</x>
<y>301</y> <y>321</y>
</hint> </hint>
<hint type="destinationlabel"> <hint type="destinationlabel">
<x>147</x> <x>147</x>
@ -1027,38 +1028,6 @@
</hint> </hint>
</hints> </hints>
</connection> </connection>
<connection>
<sender>cmdClearQuery</sender>
<signal>clicked()</signal>
<receiver>txtQuery</receiver>
<slot>setFocus()</slot>
<hints>
<hint type="sourcelabel">
<x>693</x>
<y>599</y>
</hint>
<hint type="destinationlabel">
<x>588</x>
<y>597</y>
</hint>
</hints>
</connection>
<connection>
<sender>lstHistory</sender>
<signal>itemDoubleClicked(QListWidgetItem*)</signal>
<receiver>MainWindow</receiver>
<slot>resumeHistory(QListWidgetItem*)</slot>
<hints>
<hint type="sourcelabel">
<x>349</x>
<y>492</y>
</hint>
<hint type="destinationlabel">
<x>399</x>
<y>305</y>
</hint>
</hints>
</connection>
<connection> <connection>
<sender>actionAbout</sender> <sender>actionAbout</sender>
<signal>triggered()</signal> <signal>triggered()</signal>
@ -1146,8 +1115,8 @@
<slot>editRelation()</slot> <slot>editRelation()</slot>
<hints> <hints>
<hint type="sourcelabel"> <hint type="sourcelabel">
<x>683</x> <x>785</x>
<y>323</y> <y>356</y>
</hint> </hint>
<hint type="destinationlabel"> <hint type="destinationlabel">
<x>399</x> <x>399</x>
@ -1178,8 +1147,8 @@
<slot>newRelation()</slot> <slot>newRelation()</slot>
<hints> <hints>
<hint type="sourcelabel"> <hint type="sourcelabel">
<x>683</x> <x>785</x>
<y>296</y> <y>263</y>
</hint> </hint>
<hint type="destinationlabel"> <hint type="destinationlabel">
<x>399</x> <x>399</x>
@ -1219,6 +1188,150 @@
</hint> </hint>
</hints> </hints>
</connection> </connection>
<connection>
<sender>actionMulti_line_mode</sender>
<signal>toggled(bool)</signal>
<receiver>MainWindow</receiver>
<slot>setMultiline(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>-1</x>
<y>-1</y>
</hint>
<hint type="destinationlabel">
<x>399</x>
<y>305</y>
</hint>
</hints>
</connection>
<connection>
<sender>cmdClearMultilineQuery</sender>
<signal>clicked()</signal>
<receiver>txtMultiQuery</receiver>
<slot>clear()</slot>
<hints>
<hint type="sourcelabel">
<x>518</x>
<y>564</y>
</hint>
<hint type="destinationlabel">
<x>432</x>
<y>578</y>
</hint>
</hints>
</connection>
<connection>
<sender>cmdExecuteMultiline</sender>
<signal>clicked()</signal>
<receiver>MainWindow</receiver>
<slot>execute()</slot>
<hints>
<hint type="sourcelabel">
<x>550</x>
<y>596</y>
</hint>
<hint type="destinationlabel">
<x>795</x>
<y>650</y>
</hint>
</hints>
</connection>
<connection>
<sender>cmdClearQuery</sender>
<signal>clicked()</signal>
<receiver>txtQuery</receiver>
<slot>clear()</slot>
<hints>
<hint type="sourcelabel">
<x>674</x>
<y>639</y>
</hint>
<hint type="destinationlabel">
<x>590</x>
<y>644</y>
</hint>
</hints>
</connection>
<connection>
<sender>cmdClearHistory</sender>
<signal>clicked()</signal>
<receiver>lstHistory</receiver>
<slot>clear()</slot>
<hints>
<hint type="sourcelabel">
<x>492</x>
<y>511</y>
</hint>
<hint type="destinationlabel">
<x>490</x>
<y>481</y>
</hint>
</hints>
</connection>
<connection>
<sender>cmdOptimize</sender>
<signal>clicked()</signal>
<receiver>MainWindow</receiver>
<slot>optimize()</slot>
<hints>
<hint type="sourcelabel">
<x>161</x>
<y>517</y>
</hint>
<hint type="destinationlabel">
<x>130</x>
<y>623</y>
</hint>
</hints>
</connection>
<connection>
<sender>cmdUndoOptimize</sender>
<signal>clicked()</signal>
<receiver>MainWindow</receiver>
<slot>undoOptimize()</slot>
<hints>
<hint type="sourcelabel">
<x>369</x>
<y>509</y>
</hint>
<hint type="destinationlabel">
<x>544</x>
<y>624</y>
</hint>
</hints>
</connection>
<connection>
<sender>cmdExecute</sender>
<signal>clicked()</signal>
<receiver>MainWindow</receiver>
<slot>execute()</slot>
<hints>
<hint type="sourcelabel">
<x>740</x>
<y>636</y>
</hint>
<hint type="destinationlabel">
<x>797</x>
<y>627</y>
</hint>
</hints>
</connection>
<connection>
<sender>txtQuery</sender>
<signal>returnPressed()</signal>
<receiver>MainWindow</receiver>
<slot>execute()</slot>
<hints>
<hint type="sourcelabel">
<x>484</x>
<y>642</y>
</hint>
<hint type="destinationlabel">
<x>796</x>
<y>514</y>
</hint>
</hints>
</connection>
</connections> </connections>
<slots> <slots>
<slot>execute()</slot> <slot>execute()</slot>
@ -1254,5 +1367,6 @@
<slot>newSession()</slot> <slot>newSession()</slot>
<slot>saveSessionAs()</slot> <slot>saveSessionAs()</slot>
<slot>manageSessions()</slot> <slot>manageSessions()</slot>
<slot>setMultiline(bool)</slot>
</slots> </slots>
</ui> </ui>