522 if (other_right < right) { |
543 if (other_right < right) { |
523 QModelIndex tl = model->index(top, other_right + 1, parent); |
544 QModelIndex tl = model->index(top, other_right + 1, parent); |
524 QModelIndex br = model->index(bottom, right, parent); |
545 QModelIndex br = model->index(bottom, right, parent); |
525 result->append(QItemSelectionRange(tl, br)); |
546 result->append(QItemSelectionRange(tl, br)); |
526 right = other_right; |
547 right = other_right; |
|
548 } |
|
549 } |
|
550 |
|
551 |
|
552 void QItemSelectionModelPrivate::initModel(QAbstractItemModel *model) |
|
553 { |
|
554 this->model = model; |
|
555 if (model) { |
|
556 Q_Q(QItemSelectionModel); |
|
557 QObject::connect(model, SIGNAL(rowsAboutToBeRemoved(QModelIndex,int,int)), |
|
558 q, SLOT(_q_rowsAboutToBeRemoved(QModelIndex,int,int))); |
|
559 QObject::connect(model, SIGNAL(columnsAboutToBeRemoved(QModelIndex,int,int)), |
|
560 q, SLOT(_q_columnsAboutToBeRemoved(QModelIndex,int,int))); |
|
561 QObject::connect(model, SIGNAL(rowsAboutToBeInserted(QModelIndex,int,int)), |
|
562 q, SLOT(_q_rowsAboutToBeInserted(QModelIndex,int,int))); |
|
563 QObject::connect(model, SIGNAL(columnsAboutToBeInserted(QModelIndex,int,int)), |
|
564 q, SLOT(_q_columnsAboutToBeInserted(QModelIndex,int,int))); |
|
565 QObject::connect(model, SIGNAL(layoutAboutToBeChanged()), |
|
566 q, SLOT(_q_layoutAboutToBeChanged())); |
|
567 QObject::connect(model, SIGNAL(layoutChanged()), |
|
568 q, SLOT(_q_layoutChanged())); |
527 } |
569 } |
528 } |
570 } |
529 |
571 |
530 /*! |
572 /*! |
531 \internal |
573 \internal |
888 Constructs a selection model that operates on the specified item \a model. |
934 Constructs a selection model that operates on the specified item \a model. |
889 */ |
935 */ |
890 QItemSelectionModel::QItemSelectionModel(QAbstractItemModel *model) |
936 QItemSelectionModel::QItemSelectionModel(QAbstractItemModel *model) |
891 : QObject(*new QItemSelectionModelPrivate, model) |
937 : QObject(*new QItemSelectionModelPrivate, model) |
892 { |
938 { |
893 d_func()->model = model; |
939 d_func()->initModel(model); |
894 if (model) { |
|
895 connect(model, SIGNAL(rowsAboutToBeRemoved(QModelIndex,int,int)), |
|
896 this, SLOT(_q_rowsAboutToBeRemoved(QModelIndex,int,int))); |
|
897 connect(model, SIGNAL(columnsAboutToBeRemoved(QModelIndex,int,int)), |
|
898 this, SLOT(_q_columnsAboutToBeRemoved(QModelIndex,int,int))); |
|
899 connect(model, SIGNAL(rowsAboutToBeInserted(QModelIndex,int,int)), |
|
900 this, SLOT(_q_rowsAboutToBeInserted(QModelIndex,int,int))); |
|
901 connect(model, SIGNAL(columnsAboutToBeInserted(QModelIndex,int,int)), |
|
902 this, SLOT(_q_columnsAboutToBeInserted(QModelIndex,int,int))); |
|
903 connect(model, SIGNAL(layoutAboutToBeChanged()), |
|
904 this, SLOT(_q_layoutAboutToBeChanged())); |
|
905 connect(model, SIGNAL(layoutChanged()), |
|
906 this, SLOT(_q_layoutChanged())); |
|
907 } |
|
908 } |
940 } |
909 |
941 |
910 /*! |
942 /*! |
911 Constructs a selection model that operates on the specified item \a model with \a parent. |
943 Constructs a selection model that operates on the specified item \a model with \a parent. |
912 */ |
944 */ |
913 QItemSelectionModel::QItemSelectionModel(QAbstractItemModel *model, QObject *parent) |
945 QItemSelectionModel::QItemSelectionModel(QAbstractItemModel *model, QObject *parent) |
914 : QObject(*new QItemSelectionModelPrivate, parent) |
946 : QObject(*new QItemSelectionModelPrivate, parent) |
915 { |
947 { |
916 d_func()->model = model; |
948 d_func()->initModel(model); |
917 if (model) { |
|
918 connect(model, SIGNAL(rowsAboutToBeRemoved(QModelIndex,int,int)), |
|
919 this, SLOT(_q_rowsAboutToBeRemoved(QModelIndex,int,int))); |
|
920 connect(model, SIGNAL(columnsAboutToBeRemoved(QModelIndex,int,int)), |
|
921 this, SLOT(_q_columnsAboutToBeRemoved(QModelIndex,int,int))); |
|
922 connect(model, SIGNAL(rowsAboutToBeInserted(QModelIndex,int,int)), |
|
923 this, SLOT(_q_rowsAboutToBeInserted(QModelIndex,int,int))); |
|
924 connect(model, SIGNAL(columnsAboutToBeInserted(QModelIndex,int,int)), |
|
925 this, SLOT(_q_columnsAboutToBeInserted(QModelIndex,int,int))); |
|
926 connect(model, SIGNAL(layoutAboutToBeChanged()), |
|
927 this, SLOT(_q_layoutAboutToBeChanged())); |
|
928 connect(model, SIGNAL(layoutChanged()), |
|
929 this, SLOT(_q_layoutChanged())); |
|
930 } |
|
931 } |
949 } |
932 |
950 |
933 /*! |
951 /*! |
934 \internal |
952 \internal |
935 */ |
953 */ |
936 QItemSelectionModel::QItemSelectionModel(QItemSelectionModelPrivate &dd, QAbstractItemModel *model) |
954 QItemSelectionModel::QItemSelectionModel(QItemSelectionModelPrivate &dd, QAbstractItemModel *model) |
937 : QObject(dd, model) |
955 : QObject(dd, model) |
938 { |
956 { |
939 d_func()->model = model; |
957 dd.initModel(model); |
940 if (model) { |
|
941 connect(model, SIGNAL(rowsAboutToBeRemoved(QModelIndex,int,int)), |
|
942 this, SLOT(_q_rowsAboutToBeRemoved(QModelIndex,int,int))); |
|
943 connect(model, SIGNAL(columnsAboutToBeRemoved(QModelIndex,int,int)), |
|
944 this, SLOT(_q_columnsAboutToBeRemoved(QModelIndex,int,int))); |
|
945 connect(model, SIGNAL(rowsAboutToBeInserted(QModelIndex,int,int)), |
|
946 this, SLOT(_q_rowsAboutToBeInserted(QModelIndex,int,int))); |
|
947 connect(model, SIGNAL(columnsAboutToBeInserted(QModelIndex,int,int)), |
|
948 this, SLOT(_q_columnsAboutToBeInserted(QModelIndex,int,int))); |
|
949 connect(model, SIGNAL(layoutAboutToBeChanged()), |
|
950 this, SLOT(_q_layoutAboutToBeChanged())); |
|
951 connect(model, SIGNAL(layoutChanged()), |
|
952 this, SLOT(_q_layoutChanged())); |
|
953 } |
|
954 } |
958 } |
955 |
959 |
956 /*! |
960 /*! |
957 Destroys the selection model. |
961 Destroys the selection model. |
958 */ |
962 */ |
959 QItemSelectionModel::~QItemSelectionModel() |
963 QItemSelectionModel::~QItemSelectionModel() |
960 { |
964 { |
961 Q_D(QItemSelectionModel); |
|
962 if (d->model) { |
|
963 disconnect(d->model, SIGNAL(rowsAboutToBeRemoved(QModelIndex,int,int)), |
|
964 this, SLOT(_q_rowsAboutToBeRemoved(QModelIndex,int,int))); |
|
965 disconnect(d->model, SIGNAL(columnsAboutToBeRemoved(QModelIndex,int,int)), |
|
966 this, SLOT(_q_columnsAboutToBeRemoved(QModelIndex,int,int))); |
|
967 disconnect(d->model, SIGNAL(rowsAboutToBeInserted(QModelIndex,int,int)), |
|
968 this, SLOT(_q_rowsAboutToBeInserted(QModelIndex,int,int))); |
|
969 disconnect(d->model, SIGNAL(columnsAboutToBeInserted(QModelIndex,int,int)), |
|
970 this, SLOT(_q_columnsAboutToBeInserted(QModelIndex,int,int))); |
|
971 disconnect(d->model, SIGNAL(layoutAboutToBeChanged()), |
|
972 this, SLOT(_q_layoutAboutToBeChanged())); |
|
973 disconnect(d->model, SIGNAL(layoutChanged()), |
|
974 this, SLOT(_q_layoutChanged())); |
|
975 } |
|
976 } |
965 } |
977 |
966 |
978 /*! |
967 /*! |
979 Selects the model item \a index using the specified \a command, and emits |
968 Selects the model item \a index using the specified \a command, and emits |
980 selectionChanged(). |
969 selectionChanged(). |