Example #1
0
    def setQuery(self, query):
        """
        Assigns the query for this widget, loading the query builder tree with
        the pertinent information.
        
        :param      query | <Query> || <QueryCompound> || None
        """
        tree = self.uiQueryTREE
        tree.blockSignals(True)
        tree.setUpdatesEnabled(False)

        tree.clear()

        # assign a top level query item
        if (Q.typecheck(query) and not query.isNull()):
            XQueryItem(tree, query)

        # assign a top level query group
        elif (QueryCompound.typecheck(query) and not query.isNull()):
            op_name = QueryCompound.Op[query.operatorType()].lower()

            for i, sub_query in enumerate(query.queries()):
                if (i):
                    XJoinItem(tree, op_name)

                XQueryItem(tree, sub_query)

        tree.resizeToContents()
        tree.setUpdatesEnabled(True)
        tree.blockSignals(False)
 def setQuery( self, query ):
     """
     Assigns the query for this widget, loading the query builder tree with
     the pertinent information.
     
     :param      query | <Query> || <QueryCompound> || None
     """
     tree = self.uiQueryTREE
     tree.blockSignals(True)
     tree.setUpdatesEnabled(False)
     
     tree.clear()
     
     # assign a top level query item
     if ( Q.typecheck(query) and not query.isNull() ):
         XQueryItem(tree, query)
     
     # assign a top level query group
     elif ( QueryCompound.typecheck(query) and not query.isNull() ):
         op_name = QueryCompound.Op[query.operatorType()].lower()
         
         for i, sub_query in enumerate(query.queries()):
             if ( i ):
                 XJoinItem(tree, op_name)
             
             XQueryItem(tree, sub_query)
         
     tree.resizeToContents()
     tree.setUpdatesEnabled(True)
     tree.blockSignals(False)
 def query(self):
     """
     Returns the query instance for this widget.
     
     :return     <orb.Query> || <orb.QueryCompound>
     """
     queryWidget = self.queryWidget()
     
     # check to see if there is an active container for this widget
     container = queryWidget.containerFor(self)
     if container:
         return container.query()
     
     elif QueryCompound.typecheck(self._query):
         return self._query
     
     # generate a new query from the editor
     column = self.uiColumnDDL.currentSchemaPath()
     plugin = self.currentPlugin()
     editor = self.editor()
     op     = self.uiOperatorDDL.currentText()
     
     if column and plugin:
         query = Query(column)
         plugin.setupQuery(query, op, editor)
         return query
     else:
         return Query()
 def refreshButtons(self):
     """
     Refreshes the buttons for building this sql query.
     """
     last = self._last
     first = self._first
     
     joiner = self._containerWidget.currentJoiner()
     
     # the first button set can contain the toggle options
     if first:
         self.uiJoinSBTN.setActionTexts(['AND', 'OR'])
     elif joiner == QueryCompound.Op.And:
         self.uiJoinSBTN.setActionTexts(['AND'])
     else:
         self.uiJoinSBTN.setActionTexts(['OR'])
     
     # the last option should not show an active action
     if last:
         self.uiJoinSBTN.setCurrentAction(None)
     
     # otherwise, highlight the proper action
     else:
         act = self.uiJoinSBTN.findAction(QueryCompound.Op[joiner].upper())
         self.uiJoinSBTN.setCurrentAction(act)
     
     enable = QueryCompound.typecheck(self._query) or self.isChecked()
     self.uiEnterBTN.setEnabled(enable)
    def refreshButtons(self):
        """
        Refreshes the buttons for building this sql query.
        """
        last = self._last
        first = self._first

        joiner = self._containerWidget.currentJoiner()

        # the first button set can contain the toggle options
        if first:
            self.uiJoinSBTN.setActionTexts(['AND', 'OR'])
        elif joiner == QueryCompound.Op.And:
            self.uiJoinSBTN.setActionTexts(['AND'])
        else:
            self.uiJoinSBTN.setActionTexts(['OR'])

        # the last option should not show an active action
        if last:
            self.uiJoinSBTN.setCurrentAction(None)

        # otherwise, highlight the proper action
        else:
            act = self.uiJoinSBTN.findAction(QueryCompound.Op[joiner].upper())
            self.uiJoinSBTN.setCurrentAction(act)

        enable = QueryCompound.typecheck(self._query) or self.isChecked()
        self.uiEnterBTN.setEnabled(enable)
    def query(self):
        """
        Returns the query instance for this widget.
        
        :return     <orb.Query> || <orb.QueryCompound>
        """
        queryWidget = self.queryWidget()

        # check to see if there is an active container for this widget
        container = queryWidget.containerFor(self)
        if container:
            return container.query()

        elif QueryCompound.typecheck(self._query):
            return self._query

        # generate a new query from the editor
        column = self.uiColumnDDL.currentSchemaPath()
        plugin = self.currentPlugin()
        editor = self.editor()
        op = self.uiOperatorDDL.currentText()

        if column and plugin:
            query = Query(column)
            plugin.setupQuery(query, op, editor)
            return query
        else:
            return Query()
 def enterCompound(self, entry, query):
     # enter an existing compound
     if QueryCompound.typecheck(query):
         self.enterCompoundRequested.emit(entry, query)
     
     # create a new compound from the checked entries
     else:
         self.createCompoundFromChecked()
Example #8
0
    def enterCompound(self, entry, query):
        # enter an existing compound
        if QueryCompound.typecheck(query):
            self.enterCompoundRequested.emit(entry, query)

        # create a new compound from the checked entries
        else:
            self.createCompoundFromChecked()
 def setChecked(self, state):
     self._checked = state
     if state:
         self.setBackgroundRole(QPalette.Highlight)
         self.setAutoFillBackground(True)
     else:
         self.setBackgroundRole(QPalette.Window)
         self.setAutoFillBackground(False)
     
     enable = QueryCompound.typecheck(self._query) or self.isChecked()
     self.uiEnterBTN.setEnabled(enable)
    def setChecked(self, state):
        self._checked = state
        if state:
            self.setBackgroundRole(QPalette.Highlight)
            self.setAutoFillBackground(True)
        else:
            self.setBackgroundRole(QPalette.Window)
            self.setAutoFillBackground(False)

        enable = QueryCompound.typecheck(self._query) or self.isChecked()
        self.uiEnterBTN.setEnabled(enable)
 def setQuery(self, query):
     """
     Sets the query for this wigdet to the inputed query instance.
     
     :param      query | <orb.Query> || <orb.QueryCompound>
     """
     if not self.isNull() and hash(query) == hash(self.query()):
         return
     
     # add entries
     table = self.tableType()
     
     self.setUpdatesEnabled(False)
     self.blockSignals(True)
     self.clear()
     
     if query is None or table is None:
         self.setEnabled(False)
         self.setUpdatesEnabled(True)
         self.blockSignals(False)
         return
     else:
         self.setEnabled(True)
     
     # load the queries for this item
     if QueryCompound.typecheck(query):
         queries = query.queries()
         self.setCurrentJoiner(query.operatorType())
     else:
         queries = [query]
     
     self.uiNameTXT.setText(query.name())
     
     layout = self._entryWidget.layout()
     for index, query in enumerate(queries):
         widget = self.addEntry(query)
         widget.setFirst(index == 0)
         widget.setLast(index == (len(queries) - 1))
         widget.setJoiner(self.currentJoiner())
     
     self.setUpdatesEnabled(True)
     self.blockSignals(False)
 def setQuery(self, query):
     """
     Sets the query instance for this widget to the inputed query.
     
     :param      query | <orb.Query> || <orb.QueryCompound>
     """
     if not query.isNull() and hash(query) == hash(self._query):
         return
     
     self._query = query
     
     if QueryCompound.typecheck(query):
         self.uiColumnDDL.hide()
         self.uiOperatorDDL.hide()
         
         # setup the compound editor
         editor = XLineEdit(self)
         editor.setReadOnly(True)
         editor.setText(query.name() + ' %s' % nativestring(query))
         editor.setHint(nativestring(query))
         
         self.setEditor(editor)
     
     else:
         self.uiColumnDDL.show()
         self.uiOperatorDDL.show()
         
         text = query.columnName()
         self.uiColumnDDL.setCurrentSchemaPath(nativestring(text))
         
         self.uiOperatorDDL.blockSignals(True)
         plug = self.currentPlugin()
         if plug:
             op = plug.operator(query.operatorType(), query.value())
             
             index = self.uiOperatorDDL.findText(op)
             if index != -1:
                 self.uiOperatorDDL.setCurrentIndex(index)
         
         self.uiOperatorDDL.blockSignals(False)
     
     self.refreshButtons()
Example #13
0
    def setQuery(self, query):
        """
        Sets the query for this wigdet to the inputed query instance.
        
        :param      query | <orb.Query> || <orb.QueryCompound>
        """
        if not self.isNull() and hash(query) == hash(self.query()):
            return

        # add entries
        table = self.tableType()

        self.setUpdatesEnabled(False)
        self.blockSignals(True)
        self.clear()

        if query is None or table is None:
            self.setEnabled(False)
            self.setUpdatesEnabled(True)
            self.blockSignals(False)
            return
        else:
            self.setEnabled(True)

        # load the queries for this item
        if QueryCompound.typecheck(query):
            queries = query.queries()
            self.setCurrentJoiner(query.operatorType())
        else:
            queries = [query]

        self.uiNameTXT.setText(query.name())

        layout = self._entryWidget.layout()
        for index, query in enumerate(queries):
            widget = self.addEntry(query)
            widget.setFirst(index == 0)
            widget.setLast(index == (len(queries) - 1))
            widget.setJoiner(self.currentJoiner())

        self.setUpdatesEnabled(True)
        self.blockSignals(False)
    def setQuery(self, query):
        """
        Sets the query instance for this widget to the inputed query.
        
        :param      query | <orb.Query> || <orb.QueryCompound>
        """
        if hash(query) == hash(self._query):
            return

        self._query = query

        if QueryCompound.typecheck(query):
            self.uiColumnDDL.hide()
            self.uiOperatorDDL.hide()

            # setup the compound editor
            editor = XLineEdit(self)
            editor.setReadOnly(True)
            editor.setText(query.name() + ' %s' % str(query))
            editor.setHint(str(query))

            self.setEditor(editor)

        else:
            self.uiColumnDDL.show()
            self.uiOperatorDDL.show()

            text = query.columnName()
            self.uiColumnDDL.setCurrentSchemaPath(str(text))

            self.uiOperatorDDL.blockSignals(True)
            plug = self.currentPlugin()
            if plug:
                op = plug.operator(query.operatorType(), query.value())

                index = self.uiOperatorDDL.findText(op)
                if index != -1:
                    self.uiOperatorDDL.setCurrentIndex(index)

            self.uiOperatorDDL.blockSignals(False)

        self.refreshButtons()
Example #15
0
    def createCompoundFromChecked(self):
        """
        Creates a new compound query from the checked entry list.
        
        :return     <orb.QueryCompound>
        """
        checked_entries = self.checkedEntries()

        if len(checked_entries) <= 1:
            return QueryCompound()

        self.setUpdatesEnabled(False)
        joiner = self.currentJoiner()
        query = Query()
        for entry in checked_entries:
            if joiner == QueryCompound.Op.And:
                query &= entry.query()
            else:
                query |= entry.query()

        # clear out the existing containers
        first = checked_entries[0]
        first.setQuery(query)
        first.setChecked(False)

        layout = self._entryWidget.layout()
        for i in range(len(checked_entries) - 1, 0, -1):
            w = checked_entries[i]
            layout.takeAt(layout.indexOf(w))
            w.close()

        self.refreshEntries()
        self.setUpdatesEnabled(True)

        if not self.signalsBlocked():
            self.enterCompound(first, query)