PublicationDashboardWindow::PublicationDashboardWindow(const QString &csv_filename) { PublicationParser parser; try { records = parser.parse(csv_filename); } catch (const std::exception &e) { qDebug() << e.what(); QMessageBox::critical(this, "Error", "A fatal error occurred while parsing the CSV file"); exit(1); } if (records.empty()) { QMessageBox::critical(this, "Error", "The CSV file has no records"); exit(1); } ui.treeWidget->setHeaderLabels(QStringList() << "" << "Publication Type" << "Faculty Name" << "Title" << "Total #" << ""); ui.titleLabel->setText("Publication Summary, Department of " + records[0].primaryDomain); ui.statusbar->showMessage("Read " + QString::number(records.size()) + " records from " + csv_filename); setWindowTitle("Publication - " + records[0].primaryDomain + " - " + csv_filename); QPair<QDate, QDate> dateInterval = findDateRange(records); ui.startDateSelector->setDate(dateInterval.first); ui.endDateSelector->setDate(dateInterval.second); updateDateLabel(); updateTreeWidget(); }
// Search for the item specified by index and ensure the item is visible. bool ObxTreeView::select(const QModelIndex & index) { selected_ = -1; for(int i = 0; i < all_items_.size(); ++i) { if (all_items_.at(i)->index() == index) { selected_ = i; break; } } if (selected_ < 0) { return false; } // Update tree widget if necessary. int new_page = selected_ / itemsPerPage() + 1; first_visible_ = (new_page - 1) * items_per_page_; if (isVisible()) { updateTreeWidget(); reportPosition(); } return true; }
void ObxTreeView::setModel(QStandardItemModel * model) { header_bar_.setModel(model); model_ = model; all_items_.clear(); setupInternalModel(model_, model_->invisibleRootItem(), -1); if (isVisible()) { updateTreeWidget(); reportPosition(); } }
void ObxTreeView::resizeEvent(QResizeEvent *) { // Need to calculate the first_visible according to the select item. if (selected_ < 0) { selected_ = 0; } first_visible_ = selected_ / itemsPerPage() * itemsPerPage(); updateTreeWidget(); updateLayout(itemsPerPage()); reportPosition(); }
bool ObxTreeView::jumpToPage(int page) { if (page < 1 || page > pages() || page == currentPage()) { return false; } first_visible_ = (page - 1)* items_per_page_; selected_ = first_visible_; updateTreeWidget(); reportPosition(); return true; }
bool DuokanTreeView::pageDown() { int new_pos = first_visible_ + items_per_page_; if (new_pos >= all_items_.size()) { emit exceed(false); return false; } first_visible_ = new_pos; selected_ = first_visible_; updateTreeWidget(); reportPosition(); return true; }
PublicationDashboardWindow::PublicationDashboardWindow(QList<PublicationRecord> records, const QString &csv_filename) { this->records = records; ui.treeWidget->setHeaderLabels(QStringList() << "" << "Publication Type" << "Faculty Name" << "Title" << "Total #" << ""); ui.titleLabel->setText("Publication Summary, Department of " + records[0].primaryDomain); ui.statusbar->showMessage("Read " + QString::number(records.size()) + " records from " + csv_filename); setWindowTitle("Publication - " + records[0].primaryDomain + " - " + csv_filename); QPair<QDate, QDate> dateInterval = findDateRange(records); ui.startDateSelector->setDate(dateInterval.first); ui.endDateSelector->setDate(dateInterval.second); updateDateLabel(); updateTreeWidget(); }
bool DuokanTreeView::pageUp() { if (first_visible_ <= 0) { emit exceed(true); return false; } first_visible_ -= items_per_page_; if (first_visible_ < 0) { first_visible_ = 0; } selected_ = first_visible_; updateTreeWidget(); reportPosition(); return true; }
bool ObxTreeView::pageDown() { int new_pos = first_visible_ + items_per_page_; if (new_pos >= all_items_.size()) { emit exceed(false); if (selected_ < all_items_.size() - 1) { navigate(all_items_.size() - 1 - selected_); } return false; } first_visible_ = new_pos; selected_ = first_visible_; updateTreeWidget(); reportPosition(); return true; }
bool ObxTreeView::navigate(int offset) { // Check new position is valid or not. int new_select = selected_ + offset; if (new_select < 0 || new_select >= all_items_.size()) { return false; } bool page_changed = false; selected_ = new_select; if (new_select < first_visible_) { first_visible_ -= itemsPerPage(); page_changed = true; } else if (new_select >= first_visible_ + itemsPerPage()) { first_visible_ += itemsPerPage(); page_changed = true; } updateTreeWidget(); if (page_changed) { reportPosition(); } else { onyx::screen::instance().flush(); onyx::screen::instance().updateWidget( this, onyx::screen::ScreenProxy::DW, false, onyx::screen::ScreenCommand::WAIT_ALL); } return true; }
void ObxTreeView::onItemClicked(ObxTreeViewItem *item) { if (item->data() == 0) { return; } // Disable screen update now. onyx::screen::instance().enableUpdate(false); // Make the node selected. if (selectItem(item)) { updateTreeWidget(); onyx::screen::instance().flush( this, onyx::screen::ScreenProxy::DW, false, onyx::screen::ScreenCommand::WAIT_ALL); } onyx::screen::instance().enableUpdate(true); activate(); }
void DashboardWindow::on_dateFilterButton_clicked() { updateDateLabel(); updateTreeWidget(); }