Skip to content

Commit

Permalink
[dbmanager] Fix non-clickable checkbox in Null column when creating t…
Browse files Browse the repository at this point in the history
…able (on Mac)

- Switch from checkbox delegate to Qt::CheckStateRole for column
- Enable all triggers for table view
  • Loading branch information
dakcarto committed Aug 3, 2013
1 parent fe6dcf1 commit a773be2
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
9 changes: 8 additions & 1 deletion python/plugins/db_manager/db_plugins/data_model.py
Expand Up @@ -204,6 +204,13 @@ def headerData(self, section, orientation, role):
return section+1
return SimpleTableModel.headerData(self, section, orientation, role)

def flags(self, index):
flags = SimpleTableModel.flags(self, index)
if index.column() == 2: # set Null column as checkable
flags &= ~Qt.ItemIsEditable
flags |= Qt.ItemIsUserCheckable
return flags

def append(self, fld):
data = [fld.name, fld.type2String(), not fld.notNull, fld.default2String()]
self.appendRow( self.rowFromData(data) )
Expand All @@ -230,7 +237,7 @@ def getObject(self, row):
fld.modifier = None
fld.dataType = typestr

fld.notNull = self.data(self.index(row, 2)) != "true"
fld.notNull = self.data(self.index(row, 2), Qt.CheckStateRole) == Qt.Unchecked
fld.primaryKey = self.data(self.index(row, 1), Qt.UserRole)
return fld

Expand Down
10 changes: 2 additions & 8 deletions python/plugins/db_manager/dlg_create_table.py
Expand Up @@ -49,8 +49,6 @@ def createEditor(self, parent, option, index):
for item in self.fieldTypes:
cbo.addItem(item)
return cbo
elif index.column() == 2:
return QCheckBox(parent)
return QItemDelegate.createEditor(self, parent, option, index)

def setEditorData(self, editor, index):
Expand All @@ -59,9 +57,6 @@ def setEditorData(self, editor, index):
if index.column() == 1:
txt = m.data(index, Qt.DisplayRole)
editor.setEditText(txt)
elif index.column() == 2:
checked = m.data(index, Qt.DisplayRole) == "true"
editor.setChecked( checked )
else:
# use default
QItemDelegate.setEditorData(self, editor, index)
Expand All @@ -70,8 +65,6 @@ def setModelData(self, editor, model, index):
""" save data from editor back to model """
if index.column() == 1:
model.setData(index, editor.currentText())
elif index.column() == 1:
model.setData(index, editor.isChecked())
else:
# use default
QItemDelegate.setModelData(self, editor, model, index)
Expand Down Expand Up @@ -191,7 +184,8 @@ def addField(self):
if "serial" in self.fieldTypes: # PostgreSQL
colType = "serial"
m.setData(indexType, colType)
m.setData(indexNull, False)
m.setData(indexNull, None, Qt.DisplayRole)
m.setData(indexNull, Qt.Unchecked, Qt.CheckStateRole)

# selects the new row
sel = self.fields.selectionModel()
Expand Down
3 changes: 3 additions & 0 deletions python/plugins/db_manager/ui/DlgCreateTable.ui
Expand Up @@ -253,6 +253,9 @@
</item>
<item row="1" column="0">
<widget class="QTableView" name="fields">
<property name="editTriggers">
<set>QAbstractItemView::AllEditTriggers</set>
</property>
<attribute name="horizontalHeaderStretchLastSection">
<bool>true</bool>
</attribute>
Expand Down

0 comments on commit a773be2

Please sign in to comment.