Shinmera / qtools

Qtools is a collection of utilities to aid development with CommonQt
https://shinmera.github.io/qtools
zlib License
210 stars 17 forks source link

QAbstractTableModel issue with data and header-data #43

Open Kahmue opened 4 years ago

Kahmue commented 4 years ago

Testcase is `(defclass data-item () ((slot-1 :initarg :slot1 :initform "" :accessor slot1) (slot-2 :initarg :slot2 :initform "" :accessor slot2)))

(defparameter data (coerce (list (make-instance 'data-item :slot1 "slot1-1" :slot2 21) (make-instance 'data-item :slot1 "slot1-2" :slot2 22) (make-instance 'data-item :slot1 "slot1-3" :slot2 23) (make-instance 'data-item :slot1 "slot1-4" :slot2 24) (make-instance 'data-item :slot1 "slot1-5" :slot2 25)) 'vector))

(defparameter column-header #("Col-1" "Col-2")) (defparameter column-accessors #(slot1 slot2))

(define-object table-model (QAbstractTableModel) ((%rows :initarg :rows :initform (make-array 1 :fill-pointer 0 :adjustable t) :accessor table-rows)))`

Overriding QAbstractTableModel::data like so

(define-override (table-model data) (index role) (when (q+:is-valid index) (when (= role (q+:qt.display-role)) (let* ((item (aref (table-rows table-model) (q+:row index))) (col (q+:column index)) (val (funcall (aref *column-accessors* col) item))) (format t "Slot-Data ~a -> ~a~%" (aref *column-accessors* col) val) (format NIL "~a" val)))))

The TableView then shows https://imgur.com/a/CwGkmzc.

When (q+:resize-columns-to-contentstable)` is called, the view changes to https://imgur.com/a/kRO2600

unless one sets (q+:item-delegate-for-column col table) manually.

table-fail-lisp.txt