Skip to content
Permalink
Browse files
[dbmanager] Fix non-clickable checkbox in Null column when creating t…
…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 a773be2837b8a15a52a2682fa95e9e653f4e2d50
Showing with 13 additions and 9 deletions.
  1. +8 −1 python/plugins/db_manager/db_plugins/data_model.py
  2. +2 −8 python/plugins/db_manager/dlg_create_table.py
  3. +3 −0 python/plugins/db_manager/ui/DlgCreateTable.ui
@@ -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) )
@@ -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

@@ -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):
@@ -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)
@@ -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)
@@ -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()
@@ -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>

0 comments on commit a773be2

Please sign in to comment.