Ejemplo n.º 1
0
 def setQuery(self,  str,  db=None):
     if db == None:
         self.query = QSqlQuery(str)
     else:
         self.query = str
     QSqlQueryModel.setQuery(self,  str)
     del self.data
     self.data = []
     self.rCount = QSqlQueryModel.rowCount(self)
     if self.rCount > 10000:
         self.rCount = 10000
     self.cCount = QSqlQueryModel.columnCount(self)
     for i in range(self.rCount ):
         row = []
         for j in range(self.cCount):
             row.append(QSqlQueryModel.data(self, QSqlQueryModel.index(self, i, j)))
         self.data.append(row)
     self.clear()
     print self.rowCount(), self.columnCount()
Ejemplo n.º 2
0
 def setQuery(self, str, db=None):
     if db == None:
         self.query = QSqlQuery(str)
     else:
         self.query = str
     QSqlQueryModel.setQuery(self, str)
     del self.data
     self.data = []
     self.rCount = QSqlQueryModel.rowCount(self)
     if self.rCount > 10000:
         self.rCount = 10000
     self.cCount = QSqlQueryModel.columnCount(self)
     for i in range(self.rCount):
         row = []
         for j in range(self.cCount):
             row.append(
                 QSqlQueryModel.data(self, QSqlQueryModel.index(self, i,
                                                                j)))
         self.data.append(row)
     self.clear()
     print self.rowCount(), self.columnCount()
 def check_start_end(self, tol):
     # set the feature counter to 0
     count = 0
     # initialises two virtual objects points (start and end point)
     start_point = self.start_point
     end_point = self.end_point
     # uses the qgis python api to access the ESU Graphic Layer
     esu_layer = self.esu_layer
     # runs the query number 8 to retrieve all streets from the Database
     streets_model = QSqlQueryModel()
     streets_model.setQuery(self.queries[8])
     while streets_model.canFetchMore():
         streets_model.fetchMore()
     n_columns = streets_model.columnCount()
     n_rows = streets_model.rowCount()
     i = 0
     j = 0
     # first loop start (for each street):
     start_end_content = []
     while i <= n_rows - 1:
         self.progress_win.setLabelText("Checking start-end Coordinates...")
         # initialises the state of the checks booleans both to false
         start_ok = False
         end_ok = False
         col_info = []
         while j <= n_columns - 1:
             model_index = streets_model.createIndex(i, j)
             if j == 0:
                 data = model_index.data()
                 col_info.append(data)
             if j == 1:
                 data = model_index.data()
                 col_info.append(data)
             if j == 2:
                 data = model_index.data()
                 col_info.append(data)
             if j >= 3:
                 data = model_index.data()
                 col_info.append(data)
             j += 1
         usrn = col_info[0]
         ref_type = col_info[2]
         desc = col_info[1]
         start_point.set(float(col_info[3]), float(col_info[4]))
         end_point.set(float(col_info[5]), float(col_info[6]))
         # filter the layer "ESU Graphic" for the ESUs Ids returned from the list
         # deal just with the arcs part of multi arcs street
         esus_list = self.get_linked_esu_list(usrn)
         feat_filter = self.build_layer_filter(esus_list)
         feat_request = QgsFeatureRequest()
         feat_request.setFilterExpression(feat_filter)
         # second loop starts (for each arc (ESU) composing the street)
         # iterate through all filtered features and their proximity with the start and end of the street
         features = self.esu_layer.getFeatures(feat_request)
         features.rewind()
         # iterates through features
         for feat in features:
             # check start end points for each of the only if none of the start end points of
             # a ESU on each street is not already matched
             if (start_ok is not True) or (end_ok is not True):
                 result = self.start_end_proximity(start_point, end_point,
                                                   feat, tol)
                 # both dist are ok
                 if result == 3:
                     start_ok = True
                     end_ok = True
                 # just end dist is ok
                 elif result == 2:
                     end_ok = True
                 # just start dist is ok
                 elif result == 1:
                     start_ok = True
             else:
                 break
         # in case of problems
         if not start_ok or not end_ok:
             count += 1
             start_end_item = [str(col_info[0]) + ","]
             # handles the creation of the report on a text file
             if not start_ok and not end_ok:
                 start_end_item.append("(both),")
             if not start_ok and end_ok:
                 start_end_item.append("(start),")
             if start_ok and not end_ok:
                 start_end_item.append("(end),")
             start_end_item.append(str(ref_type) + ",")
             start_end_item.append(str(desc) + "\n")
             start_end_content.append(start_end_item)
         j = 0
         i += 1
     if count == 0:
         self.progress_win.setValue(7)
         return
     else:
         start_end_content.insert(0, self.column_names[5])
         self.progress_win.setValue(7)
         return self.content_to_screen(content_list=start_end_content,
                                       query_model=None,
                                       columns_name_id=None,
                                       no_content_id=8)
Ejemplo n.º 4
0
    def createHtmlReport(self):
        homepath = expanduser('~')
        filePath = self.chooseSaveFile(os.path.join(homepath, 'report.html'), 'html')
        if not filePath:
            return
        editor = QtGui.QTextDocument()
        cursor = QtGui.QTextCursor(editor)
        cursor.beginEditBlock()
        cursor.insertHtml(u"<B>ПРИМЕР ОТЧЕТА №1 от %s</B><BR>" % datetime.datetime.now().strftime('%Y-%m-%d'))
        cursor.insertHtml(u"Дополнительная строка  %s от %s" % ('_' * 3, '_' * 10))

        clientQuery = QSqlQueryModel()
        clientQuery.setQuery(
            "SELECT Surname, Name, Midname, birthdate, sex, snils FROM Client where id=%s" % self.clientId)
        tableFormat = QtGui.QTextTableFormat()
        constraints = [QtGui.QTextLength(QtGui.QTextLength.PercentageLength, 14),
                       QtGui.QTextLength(QtGui.QTextLength.PercentageLength, 14)]

        tableFormat.setBorder(0)
        tableFormat.setCellPadding(2)
        tableFormat.setCellSpacing(0)
        tableFormat.setColumnWidthConstraints(constraints)
        tableFormat.setHeaderRowCount(10)

        table = cursor.insertTable(4, 2, tableFormat)
        paramMap = {}
        paramMap[0] = [u'ФИО пациента:', clientQuery.record(0).value("Surname").toString() + " " +
                       clientQuery.record(0).value("Name").toString() + " " +
                       clientQuery.record(0).value("Midname").toString()]
        paramMap[1] = [u'Дата рождения:', unicode(clientQuery.record(0).value('birthdate').toString())]
        paramMap[2] = [u'СНИЛС', unicode(clientQuery.record(0).value('snils').toString())]
        paramMap[3] = [u'Пол', u'М' if 1 == clientQuery.record(0).value('sex').toInt() else u'Ж']

        for param in paramMap:
            for i in xrange(2):
                cell = table.cellAt(param, i)
                cellCursor = cell.firstCursorPosition()
                cellCursor.insertText(paramMap[param][i])
        cursor.movePosition(QtGui.QTextCursor.End)
        cursor.insertHtml(u"<B>Информация об оказанных услугах</B><BR><BR>")

        cursor.movePosition(QtGui.QTextCursor.End)
        constraints = [QtGui.QTextLength(QtGui.QTextLength.PercentageLength, 5),
                       QtGui.QTextLength(QtGui.QTextLength.PercentageLength, 10),
                       QtGui.QTextLength(QtGui.QTextLength.PercentageLength, 25)]
        tableFormat.setBorder(1)
        tableFormat.setCellPadding(2)
        tableFormat.setCellSpacing(0)
        tableFormat.setColumnWidthConstraints(constraints)
        tableFormat.setHeaderRowCount(1)

        clientQuery.setQuery('''SELECT distinct s.*
                                FROM Client c
                                INNER join cure cr on cr.Client_id = c.id
                                INNER join services s on s.id = cr.services_id
                                where c.id = %d''' % self.clientId)

        table = cursor.insertTable(clientQuery.rowCount() + 1, 3, tableFormat)
        values = [u'№ п/п', u'Код', u'Наименование услуги']
        for i in xrange(3):
            cell = table.cellAt(0, i)
            cellCursor = cell.firstCursorPosition()
            cellCursor.insertText(values[i])
        for i in xrange(clientQuery.rowCount()):
            for j in xrange(clientQuery.columnCount()):
                cell = table.cellAt(i + 1, j)
                cellCursor = cell.firstCursorPosition()
                cellCursor.insertText(unicode(clientQuery.record(i).value(j).toString()))
        cursor.movePosition(QtGui.QTextCursor.End)
        cursor.insertHtml(u'Дата печати: <B>%s</B><BR>' % datetime.datetime.now().strftime('%Y-%m-%d'))
        cursor.endEditBlock()

        writer = QtGui.QTextDocumentWriter()
        writer.setFileName(filePath)
        writer.setFormat("HTML")
        writer.write(editor)