Better code style

master
Salvo 'LtWorf' Tomaselli 2016-01-03 19:43:38 +07:00
parent 5563e1cafd
commit ce348149f1
2 changed files with 8 additions and 7 deletions

@ -70,13 +70,13 @@ def optimize_all(expression, rels, specific=True, general=True, debug=None):
for i in optimizations.specific_optimizations: for i in optimizations.specific_optimizations:
res = i(n, rels) # Performs the optimization res = i(n, rels) # Performs the optimization
if res != 0 and dbg: if res != 0 and dbg:
debug.append(n.__str__()) debug.append(str(n))
total += res total += res
if general: if general:
for i in optimizations.general_optimizations: for i in optimizations.general_optimizations:
res = i(n) # Performs the optimization res = i(n) # Performs the optimization
if res != 0 and dbg: if res != 0 and dbg:
debug.append(n.__str__()) debug.append(str(n))
total += res total += res
return n.__str__() return n.__str__()

@ -154,7 +154,9 @@ class relForm(QtWidgets.QMainWindow):
res_rel,query = self.user_interface.split_query(self.ui.txtQuery.text(),None) 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: if res_rel:
result = '%s = %s' % (res_rel, result) result = '%s = %s' % (res_rel, result)
self.ui.txtQuery.setText(result) self.ui.txtQuery.setText(result)
@ -217,15 +219,14 @@ class relForm(QtWidgets.QMainWindow):
# Set content # Set content
for i in rel.content: for i in rel.content:
item = QtWidgets.QTreeWidgetItem() item = QtWidgets.QTreeWidgetItem()
for j in range(len(i)): for j,k in enumerate(i):
item.setText(j, i[j]) item.setText(j, k)
self.ui.table.addTopLevelItem(item) self.ui.table.addTopLevelItem(item)
# Sets columns # Sets columns
for i, attr in enumerate(rel.header): for i, attr in enumerate(rel.header):
self.ui.table.headerItem().setText(i, attr) self.ui.table.headerItem().setText(i, attr)
self.ui.table.resizeColumnToContents( self.ui.table.resizeColumnToContents(i)
i) # Must be done in order to avoid too small columns
def printRelation(self, item): def printRelation(self, item):
self.selectedRelation = self.user_interface.relations[item.text()] self.selectedRelation = self.user_interface.relations[item.text()]