mirror of
https://github.com/rizinorg/cutter.git
synced 2024-12-20 20:06:12 +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.
|
* @brief Select first item of a QAbstractItemView if not empty
|
||||||
* @param tw - QTreeWidget instance
|
* @param itemView
|
||||||
* @return true - setCurrentItem was set, false - tree is empty
|
* @return true if first item was selected
|
||||||
*/
|
*/
|
||||||
bool selectFirstItem(QTreeWidget *tw)
|
bool selectFirstItem(QAbstractItemView *itemView)
|
||||||
{
|
{
|
||||||
if (tw->topLevelItem(0)) {
|
if (!itemView) {
|
||||||
tw->setCurrentItem(tw->topLevelItem(0));
|
return false;
|
||||||
|
}
|
||||||
|
auto model = itemView->model();
|
||||||
|
if (!model) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (model->hasIndex(0, 0)) {
|
||||||
|
itemView->setCurrentIndex(model->index(0, 0));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
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)
|
void setVerticalScrollMode(QAbstractItemView *tw)
|
||||||
{
|
{
|
||||||
tw->setVerticalScrollMode(scrollMode());
|
tw->setVerticalScrollMode(scrollMode());
|
||||||
|
@ -24,7 +24,6 @@ namespace qhelpers {
|
|||||||
QString formatBytecount(const long bytecount);
|
QString formatBytecount(const long bytecount);
|
||||||
void adjustColumns(QTreeView *tv, int columnCount, int padding);
|
void adjustColumns(QTreeView *tv, int columnCount, int padding);
|
||||||
void adjustColumns(QTreeWidget *tw, int padding);
|
void adjustColumns(QTreeWidget *tw, int padding);
|
||||||
bool selectFirstItem(QTreeWidget *tw);
|
|
||||||
bool selectFirstItem(QAbstractItemView *itemView);
|
bool selectFirstItem(QAbstractItemView *itemView);
|
||||||
QTreeWidgetItem *appendRow(QTreeWidget *tw, const QString &str, const QString &str2 = QString(),
|
QTreeWidgetItem *appendRow(QTreeWidget *tw, const QString &str, const QString &str2 = QString(),
|
||||||
const QString &str3 = QString(), const QString &str4 = QString(), const QString &str5 = 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);
|
qhelpers::adjustColumns(ui->toTreeWidget, toModel.columnCount(), 0);
|
||||||
|
|
||||||
// Automatically select the first line
|
// Automatically select the first line
|
||||||
if (toModel.hasIndex(0, 0)) {
|
if (!qhelpers::selectFirstItem(ui->toTreeWidget)) {
|
||||||
ui->toTreeWidget->setCurrentIndex(toModel.index(0, 0));
|
qhelpers::selectFirstItem(ui->fromTreeWidget);
|
||||||
} else if (fromModel.hasIndex(0, 0)) {
|
|
||||||
ui->fromTreeWidget->setCurrentIndex(fromModel.index(0, 0));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user