Beispiel #1
0
    def setModelData(self, editor, model, index):
        """For the LOCATION column: If the user selects a location from the
           combobox, get the corresponding coordinates.
        """
        if index.column() == LOCATION:
            loc = editor.currentText()
            locations = config_loader(dataset='locations',
                                      default=mss_default.locations)
            if loc in locations:
                lat, lon = locations[loc]
                # Don't update distances and flight performance twice, hence
                # set update=False for LAT.
                model.setData(index.sibling(index.row(), LAT),
                              QtCore.QVariant(lat),
                              update=False)
                model.setData(index.sibling(index.row(), LON),
                              QtCore.QVariant(lon))
            else:
                for wp in self.parent().waypoints_model.all_waypoint_data():
                    if loc == wp.location:
                        lat, lon = wp.lat, wp.lon
                        # Don't update distances and flight performance twice, hence
                        # set update=False for LAT.
                        model.setData(index.sibling(index.row(), LAT),
                                      QtCore.QVariant(lat),
                                      update=False)
                        model.setData(index.sibling(index.row(), LON),
                                      QtCore.QVariant(lon))

            model.setData(index, QtCore.QVariant(editor.currentText()))
        else:
            QtWidgets.QItemDelegate.setModelData(self, editor, model, index)
Beispiel #2
0
    def data(self, index, role=QtCore.Qt.DisplayRole):
        """Return a data field at the given index (of type QModelIndex,
           specifying row and column); overrides the corresponding
           QAbstractTableModel method.

        NOTE: Other roles (e.g. for display appearance) could be specified in
        this method as well. Cf. the 'ships' example in chapter 14/16 of 'Rapid
        GUI Programming with Python and Qt: The Definitive Guide to PyQt
        Programming' (Mark Summerfield).
        """
        waypoints = self.waypoints

        if not index.isValid() or not (0 <= index.row() < len(waypoints)):
            return QtCore.QVariant()
        waypoint = waypoints[index.row()]
        column = index.column()
        if role == QtCore.Qt.DisplayRole:
            if self.performance_settings["visible"]:
                return QtCore.QVariant(TABLE_FULL[column][1](waypoint))
            else:
                return QtCore.QVariant(TABLE_SHORT[column][1](waypoint))
        elif role == QtCore.Qt.TextAlignmentRole:
            return QtCore.QVariant(
                int(QtCore.Qt.AlignLeft | QtCore.Qt.AlignVCenter))
        return QtCore.QVariant()
Beispiel #3
0
    def button_release_move_callback(self, event):
        """Called whenever a mouse button is released.
        """
        if not self.showverts or event.button != 1 or self._ind is None:
            return

        # Submit the new position to the data model.
        vertices = self.pathpatch.get_path().wp_vertices
        lon, lat = self.map(vertices[self._ind][0], vertices[self._ind][1],
                            inverse=True)
        loc = find_location(lat, lon, tolerance=self.appropriate_epsilon_km(px=15))
        if loc is not None:
            lat, lon = loc[0]
        self.waypoints_model.setData(
            self.waypoints_model.createIndex(self._ind, ft.LAT), QtCore.QVariant(lat), update=False)
        self.waypoints_model.setData(
            self.waypoints_model.createIndex(self._ind, ft.LON), QtCore.QVariant(lon))

        self._ind = None
Beispiel #4
0
 def display_uploaded_img(self, file_path):
     self.messageText.clear()
     image_uri = QtCore.QUrl(f"file://{file_path}")
     image = QtGui.QImage(QtGui.QImageReader(file_path).read())
     self.messageText.document().addResource(
         QtGui.QTextDocument.ImageResource, image_uri,
         QtCore.QVariant(image))
     img_width, img_height = self.get_img_dimensions(image)
     image_format = QtGui.QTextImageFormat()
     image_format.setWidth(img_width)
     image_format.setHeight(img_height)
     image_format.setName(image_uri.toString())
     cursor = self.messageText.textCursor()
     cursor.movePosition(QtGui.QTextCursor.End,
                         QtGui.QTextCursor.MoveAnchor)
     cursor.insertImage(image_format)
     self.messageText.setReadOnly(True)
Beispiel #5
0
    def button_release_move_callback(self, event):
        """Called whenever a mouse button is released.
        """
        if not self.showverts or event.button != 1:
            return

        if self._ind is not None:
            # Submit the new pressure (the only value that can be edited
            # in the side view) to the data model.
            vertices = self.pathpatch.get_path().vertices
            pressure = vertices[self._ind][1]
            # http://doc.trolltech.com/4.3/qabstractitemmodel.html#createIndex
            qt_index = self.waypoints_model.createIndex(self._ind, ft.PRESSURE)
            # NOTE: QVariant cannot handle numpy.float64 types, hence convert
            # to float().
            self.waypoints_model.setData(qt_index, QtCore.QVariant(float(pressure / 100.)))

        self._ind = None
Beispiel #6
0
 def headerData(self, section, orientation, role=QtCore.Qt.DisplayRole):
     """Return data describing the table header; overrides the
        corresponding QAbstractTableModel method.
     """
     if role == QtCore.Qt.TextAlignmentRole:
         if orientation == QtCore.Qt.Horizontal:
             return QtCore.QVariant(
                 int(QtCore.Qt.AlignLeft | QtCore.Qt.AlignVCenter))
         return QtCore.QVariant(
             int(QtCore.Qt.AlignRight | QtCore.Qt.AlignVCenter))
     if role != QtCore.Qt.DisplayRole:
         return QtCore.QVariant()
     # Return the names of the table columns.
     if orientation == QtCore.Qt.Horizontal:
         if self.performance_settings["visible"]:
             return QtCore.QVariant(TABLE_FULL[section][0])
         else:
             return QtCore.QVariant(TABLE_SHORT[section][0])
     # Table rows (waypoints) are labelled with their number (= number of
     # waypoint).
     return QtCore.QVariant(int(section))