| 139 | } |
| 140 | |
| 141 | void ClassicComicsView::setModel(ComicModel *model) |
| 142 | { |
| 143 | ComicsView::setModel(model); |
| 144 | |
| 145 | if (model == NULL) { |
| 146 | comicFlow->clear(); |
| 147 | } else { |
| 148 | connect(model, &QAbstractItemModel::dataChanged, this, &ClassicComicsView::applyModelChanges, Qt::UniqueConnection); |
| 149 | connect(model, &QAbstractItemModel::rowsRemoved, this, &ClassicComicsView::removeItemsFromFlow, Qt::UniqueConnection); |
| 150 | connect(model, &QAbstractItemModel::rowsInserted, this, &ClassicComicsView::addItemsToFlow, Qt::UniqueConnection); |
| 151 | // TODO: Missing method resortCovers? |
| 152 | connect(model, &ComicModel::resortedIndexes, comicFlow, &ComicFlowWidget::resortCovers, Qt::UniqueConnection); |
| 153 | connect(model, &ComicModel::newSelectedIndex, this, &ClassicComicsView::setCurrentIndex, Qt::UniqueConnection); |
| 154 | |
| 155 | tableView->horizontalHeader()->blockSignals(true); |
| 156 | |
| 157 | tableView->setModel(model); |
| 158 | if (model->rowCount() > 0) |
| 159 | tableView->setCurrentIndex(model->index(0, 0)); |
| 160 | |
| 161 | QStringList paths = model->getPaths(model->getCurrentPath()); // TODO ComicsView: get currentpath from somewhere currentPath()); |
| 162 | comicFlow->setImagePaths(paths); |
| 163 | comicFlow->setMarks(model->getReadList()); |
| 164 | |
| 165 | bool loadDefaults = true; |
| 166 | if (settings->contains(COMICS_VIEW_HEADERS)) { |
| 167 | try { |
| 168 | loadDefaults = !tableView->horizontalHeader()->restoreState(settings->value(COMICS_VIEW_HEADERS).toByteArray()); |
| 169 | } catch (...) { |
| 170 | } |
| 171 | } |
| 172 | |
| 173 | if (loadDefaults) { |
| 174 | // default columns and order |
| 175 | for (int i = 0; i < tableView->horizontalHeader()->count(); i++) |
| 176 | tableView->horizontalHeader()->hideSection(i); |
| 177 | |
| 178 | tableView->horizontalHeader()->showSection(ComicModel::Number); |
| 179 | tableView->horizontalHeader()->showSection(ComicModel::Title); |
| 180 | tableView->horizontalHeader()->showSection(ComicModel::FileName); |
| 181 | tableView->horizontalHeader()->showSection(ComicModel::NumPages); |
| 182 | tableView->horizontalHeader()->showSection(ComicModel::Size); |
| 183 | tableView->horizontalHeader()->showSection(ComicModel::ReadColumn); |
| 184 | tableView->horizontalHeader()->showSection(ComicModel::CurrentPage); |
| 185 | tableView->horizontalHeader()->showSection(ComicModel::PublicationDate); |
| 186 | tableView->horizontalHeader()->showSection(ComicModel::Rating); |
| 187 | |
| 188 | tableView->horizontalHeader()->moveSection(ComicModel::CurrentPage, 3); |
| 189 | tableView->horizontalHeader()->moveSection(ComicModel::Rating, 12); |
| 190 | tableView->horizontalHeader()->moveSection(ComicModel::Size, 5); |
| 191 | } |
| 192 | |
| 193 | // make sure that columns without title are hidden |
| 194 | for (int i = 0; i < tableView->horizontalHeader()->count(); i++) { |
| 195 | auto title = tableView->model()->headerData(i, Qt::Horizontal).toString(); |
| 196 | if (title.isEmpty()) { |
| 197 | tableView->horizontalHeader()->hideSection(i); |
| 198 | } |
nothing calls this directly
no test coverage detected