Other: Override roleNames

This enables to use userModel inside Repeater and other model-based
components together with modelData attached property.
This commit is contained in:
Alexander Bilyak
2021-10-19 11:59:05 +02:00
committed by Jakub
parent d9847ddd6a
commit 36ec9b07e0

View File

@ -15,6 +15,7 @@
// You should have received a copy of the GNU General Public License
// along with ProtonMail Bridge. If not, see <https://www.gnu.org/licenses/>.
//go:build build_qt
// +build build_qt
package qt
@ -51,6 +52,7 @@ func (um *QMLUserModel) init() {
defer um.access.Unlock()
um.SetCount(0)
um.ConnectRowCount(um.rowCount)
um.ConnectRoleNames(um.roleNames)
um.ConnectData(um.data)
um.ConnectGet(um.get)
um.ConnectCount(func() int {
@ -62,6 +64,12 @@ func (um *QMLUserModel) init() {
um.userByID = map[string]*QMLUser{}
}
func (um *QMLUserModel) roleNames() map[int]*core.QByteArray {
return map[int]*core.QByteArray{
int(core.Qt__DisplayRole): core.NewQByteArray2("user", -1),
}
}
func (um *QMLUserModel) data(index *core.QModelIndex, property int) *core.QVariant {
if !index.IsValid() {
um.f.log.WithField("size", len(um.userIDs)).Info("Trying to get user by invalid index")