mirror of
https://github.com/rizinorg/cutter.git
synced 2024-12-18 19:06:10 +00:00
Refactored qhelpers AbstractItemView item select (#1850)
This commit is contained in:
parent
3e0d5a8981
commit
cae07d15db
@ -75,32 +75,26 @@ QTreeWidgetItem *appendRow(QTreeWidget *tw, const QString &str, const QString &s
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief select first item of QTreeWidget if tree is not empty.
|
||||
* @param tw - QTreeWidget instance
|
||||
* @return true - setCurrentItem was set, false - tree is empty
|
||||
* @brief Select first item of a QAbstractItemView if not empty
|
||||
* @param itemView
|
||||
* @return true if first item was selected
|
||||
*/
|
||||
bool selectFirstItem(QTreeWidget *tw)
|
||||
bool selectFirstItem(QAbstractItemView *itemView)
|
||||
{
|
||||
if (tw->topLevelItem(0)) {
|
||||
tw->setCurrentItem(tw->topLevelItem(0));
|
||||
if (!itemView) {
|
||||
return false;
|
||||
}
|
||||
auto model = itemView->model();
|
||||
if (!model) {
|
||||
return false;
|
||||
}
|
||||
if (model->hasIndex(0, 0)) {
|
||||
itemView->setCurrentIndex(model->index(0, 0));
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool selectFirstItem(QAbstractItemView *itemView)
|
||||
{
|
||||
auto selectionModel = itemView->selectionModel();
|
||||
auto model = itemView->model();
|
||||
if (model->hasChildren()) {
|
||||
selectionModel->setCurrentIndex(model->index(0, 0), QItemSelectionModel::SelectCurrent);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
void setVerticalScrollMode(QAbstractItemView *tw)
|
||||
{
|
||||
tw->setVerticalScrollMode(scrollMode());
|
||||
|
@ -24,7 +24,6 @@ namespace qhelpers {
|
||||
QString formatBytecount(const long bytecount);
|
||||
void adjustColumns(QTreeView *tv, int columnCount, int padding);
|
||||
void adjustColumns(QTreeWidget *tw, int padding);
|
||||
bool selectFirstItem(QTreeWidget *tw);
|
||||
bool selectFirstItem(QAbstractItemView *itemView);
|
||||
QTreeWidgetItem *appendRow(QTreeWidget *tw, const QString &str, const QString &str2 = QString(),
|
||||
const QString &str3 = QString(), const QString &str4 = QString(), const QString &str5 = QString());
|
||||
|
@ -152,10 +152,8 @@ void XrefsDialog::fillRefsForAddress(RVA addr, QString name, bool whole_function
|
||||
qhelpers::adjustColumns(ui->toTreeWidget, toModel.columnCount(), 0);
|
||||
|
||||
// Automatically select the first line
|
||||
if (toModel.hasIndex(0, 0)) {
|
||||
ui->toTreeWidget->setCurrentIndex(toModel.index(0, 0));
|
||||
} else if (fromModel.hasIndex(0, 0)) {
|
||||
ui->fromTreeWidget->setCurrentIndex(fromModel.index(0, 0));
|
||||
if (!qhelpers::selectFirstItem(ui->toTreeWidget)) {
|
||||
qhelpers::selectFirstItem(ui->fromTreeWidget);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user