Heading widget updates correctly.

This commit is contained in:
Nick Foster
2012-07-14 22:24:18 -07:00
parent 86a7bbbb2a
commit 923651f69a

View File

@@ -90,16 +90,23 @@ class mainwindow(QtGui.QMainWindow):
#hook up the update signal
self.ui.list_aircraft.selectionModel().currentRowChanged.connect(self.dashboard_mapper.setCurrentModelIndex)
#self.ui.list_aircraft.selectionModel().currentRowChanged.connect(self.update_heading_widget)
self.ui.list_aircraft.selectionModel().currentRowChanged.connect(self.update_heading_widget)
self.datamodel.dataChanged.connect(self.update_heading_widget_data)
self.ui.list_aircraft.selectionModel().currentRowChanged.connect(self.update_rssi_widget)
def update_heading_widget(self, index):
heading = index.model().data(index.model().index(index.row(), 7)).toDouble()[0]
self.ui.compass_heading.setValue(heading)
if index.model() is not None:
heading = index.model().data(index.model().index(index.row(), 7)).toDouble()[0]
self.ui.compass_heading.setValue(heading)
def update_heading_widget_data(self, startIndex, endIndex):
index = self.ui.list_aircraft.selectionModel().currentIndex()
self.update_heading_widget(index)
def update_rssi_widget(self, index):
rssi = index.model().data(index.model().index(index.row(), 2)).toDouble()[0]
self.ui.prog_rssi.setValue(rssi)
if index.model() is not None:
rssi = index.model().data(index.model().index(index.row(), 2)).toDouble()[0]
self.ui.prog_rssi.setValue(rssi)
#goes and gets valid antenna, sample rate options from the device and grays out appropriate things
def populate_source_options(self):
@@ -242,11 +249,12 @@ class mainwindow(QtGui.QMainWindow):
#and display ident if available, ICAO otherwise
class ICAOViewDelegate(QtGui.QStyledItemDelegate):
def paint(self, painter, option, index):
#draw selection rectangle
if option.state & QtGui.QStyle.State_Selected:
painter.setBrush(QtGui.QPalette().highlight())
#painter.setBrush(QtGui.QBrush(QtCore.Qt.red))
painter.drawRect(option.rect)
#if there's an ident available, use it. otherwise print the ICAO
if index.model().data(index.model().index(index.row(), 9)) != QtCore.QVariant():
paintstr = index.model().data(index.model().index(index.row(), 9)).toString()
else:
@@ -258,9 +266,7 @@ class ICAOViewDelegate(QtGui.QStyledItemDelegate):
age = min(age, max_age)
alpha = int(0xFF - (0xBF / max_age) * age)
painter.setPen(QtGui.QColor(0, 0, 0, alpha))
#QtGui.QStyledItemDelegate.paint(self, painter, option, index)
painter.drawText(option.rect.left()+3, option.rect.top(), option.rect.width(), option.rect.height(), option.displayAlignment, paintstr)
#TODO: draw highlight for selection
#the data model used to display dashboard data.
class dashboard_data_model(QtCore.QAbstractTableModel):
@@ -289,6 +295,10 @@ class dashboard_data_model(QtCore.QAbstractTableModel):
if self._data[index.row()][index.column()] is None:
return QtCore.QVariant()
else:
#if there's a dedicated precision for that column, print it out with the specified precision.
#this only works well if you DON'T have other views/widgets that depend on numeric data coming out.
#i don't like this, but it works for now. unfortunately it seems like Qt doesn't give you a
#good alternative.
if self._precisions[index.column()] is not None:
return QtCore.QVariant("%.*f" % (self._precisions[index.column()], self._data[index.row()][index.column()]))
else:
@@ -311,11 +321,7 @@ class dashboard_data_model(QtCore.QAbstractTableModel):
self.lock.release()
#addRecord implements an upsert on self._data; that is,
#it updates the row if the ICAO exists, or else it creates a new
#row with the appropriate information. in any case, it maintains sorting
#by ICAO, emits beginInsertRows() and endInsertRows()
#NOTE: could also use QSortFilterProxyModel to handle sorting without
#having to do it in the model, but this isn't exactly hard
#it updates the row if the ICAO exists, or else it creates a new row.
def addRecord(self, record):
self.lock.acquire()
icaos = [x[0] for x in self._data]