1 module dqml.qabstractlistmodel; 2 3 import dqml.global; 4 import dqml.dothersideinterface; 5 import dqml.qobject; 6 import dqml.qmodelindex; 7 import dqml.qvariant; 8 import dqml.qmetaobject; 9 import std.string; 10 import core.memory; 11 12 class QAbstractListModel : QObject 13 { 14 shared static this() 15 { 16 m_staticMetaObject = new QMetaObject(dos_qabstractlistmodel_qmetaobject()); 17 } 18 19 this() 20 { 21 super(true); 22 GC.setAttr(cast(void*)this, GC.BlkAttr.NO_MOVE); 23 this.vptr = dos_qabstractlistmodel_create(cast(void*)this, 24 metaObject().voidPointer(), 25 &staticSlotCallback, 26 &rowCountCallback, 27 &columnCountCallback, 28 &dataCallback, 29 &setDataCallback, 30 &roleNamesCallback, 31 &flagsCallback, 32 &headerDataCallback); 33 } 34 35 ~this() 36 { 37 dos_qobject_delete(this.vptr); 38 } 39 40 public static QMetaObject staticMetaObject() { 41 return m_staticMetaObject; 42 } 43 44 public override QMetaObject metaObject() { 45 return m_staticMetaObject; 46 } 47 48 49 public int rowCount(QModelIndex parentIndex) 50 { 51 return 0; 52 } 53 54 public int columnCount(QModelIndex parentIndex) 55 { 56 return 1; 57 } 58 59 public QVariant data(QModelIndex index, int role) 60 { 61 return null; 62 } 63 64 public bool setData(QModelIndex index, QVariant value, int role) 65 { 66 return false; 67 } 68 69 public string[int] roleNames() 70 { 71 return null; 72 } 73 74 public int flags(QModelIndex index) 75 { 76 return 0; 77 } 78 79 public QVariant headerData(int section, int orienation, int role) 80 { 81 return null; 82 } 83 84 protected final void beginInsertRows(QModelIndex parent, int first, int last) 85 { 86 dos_qabstractlistmodel_beginInsertRows(this.vptr, 87 parent.voidPointer(), 88 first, 89 last); 90 } 91 92 protected final void endInsertRows() 93 { 94 dos_qabstractlistmodel_endInsertRows(this.vptr); 95 } 96 97 protected final void beginRemoveRows(QModelIndex parent, int first, int last) 98 { 99 dos_qabstractlistmodel_beginRemoveRows(this.vptr, 100 parent.voidPointer(), 101 first, 102 last); 103 } 104 105 protected final void endRemoveRows() 106 { 107 dos_qabstractlistmodel_endRemoveRows(this.vptr); 108 } 109 110 protected final void beginResetModel() 111 { 112 dos_qabstractlistmodel_beginResetModel(this.vptr); 113 } 114 115 protected final void endResetModel() 116 { 117 dos_qabstractlistmodel_endResetModel(this.vptr); 118 } 119 120 protected final void dataChanged(QModelIndex topLeft, QModelIndex bottomRight, int[] roles) 121 { 122 dos_qabstractlistmodel_dataChanged(this.vptr, 123 topLeft.voidPointer(), 124 bottomRight.voidPointer(), 125 roles.ptr, 126 cast(int)(roles.length)); 127 } 128 129 private extern (C) static void rowCountCallback(void* modelPtr, 130 void* indexPtr, 131 ref int result) 132 { 133 auto model = cast(QAbstractListModel)(modelPtr); 134 auto index = new QModelIndex(indexPtr, Ownership.Clone); 135 result = model.rowCount(index); 136 } 137 138 private extern (C) static void columnCountCallback(void* modelPtr, 139 void* indexPtr, 140 ref int result) 141 { 142 auto model = cast(QAbstractListModel)(modelPtr); 143 auto index = new QModelIndex(indexPtr, Ownership.Clone); 144 result = model.columnCount(index); 145 } 146 147 private extern (C) static void dataCallback(void* modelPtr, 148 void* indexPtr, 149 int role, 150 void* result) 151 { 152 auto model = cast(QAbstractListModel)(modelPtr); 153 auto index = new QModelIndex(indexPtr, Ownership.Clone); 154 auto value = model.data(index, role); 155 if (value is null) 156 return; 157 dos_qvariant_assign(result, value.voidPointer()); 158 } 159 160 private extern (C) static void setDataCallback(void* modelPtr, 161 void* indexPtr, 162 void* valuePtr, 163 int role, 164 ref bool result) 165 { 166 auto model = cast(QAbstractListModel)(modelPtr); 167 auto index = new QModelIndex(indexPtr, Ownership.Clone); 168 auto value = new QVariant(valuePtr, Ownership.Clone); 169 result = model.setData(index, value, role); 170 } 171 172 private extern (C) static void roleNamesCallback(void* modelPtr, 173 void* result) 174 { 175 auto model = cast(QAbstractListModel)(modelPtr); 176 auto roles = model.roleNames(); 177 foreach(int key; roles.keys) { 178 dos_qhash_int_qbytearray_insert(result, key, roles[key].toStringz()); 179 } 180 } 181 182 private extern (C) static void flagsCallback(void* modelPtr, 183 void* indexPtr, 184 ref int result) 185 { 186 auto model = cast(QAbstractListModel)(modelPtr); 187 auto index = new QModelIndex(indexPtr, Ownership.Clone); 188 result = model.flags(index); 189 } 190 191 private extern (C) static void headerDataCallback(void* modelPtr, 192 int section, 193 int orientation, 194 int role, 195 void* result) 196 { 197 auto model = cast(QAbstractListModel)(modelPtr); 198 QVariant value = model.headerData(section, orientation, role); 199 if (value is null) 200 return; 201 dos_qvariant_assign(result, value.voidPointer()); 202 } 203 204 private static QMetaObject m_staticMetaObject; 205 }