chore: 格式化ElaWidgetTools代码
This commit is contained in:
@@ -1,56 +1,37 @@
|
||||
#include "ElaBreadcrumbBarModel.h"
|
||||
|
||||
ElaBreadcrumbBarModel::ElaBreadcrumbBarModel(QObject* parent)
|
||||
: QAbstractListModel{parent}
|
||||
{
|
||||
}
|
||||
ElaBreadcrumbBarModel::ElaBreadcrumbBarModel(QObject *parent) : QAbstractListModel{parent} {}
|
||||
|
||||
ElaBreadcrumbBarModel::~ElaBreadcrumbBarModel()
|
||||
{
|
||||
}
|
||||
ElaBreadcrumbBarModel::~ElaBreadcrumbBarModel() {}
|
||||
|
||||
int ElaBreadcrumbBarModel::rowCount(const QModelIndex& parent) const
|
||||
{
|
||||
if (!_breadcrumbList.isEmpty())
|
||||
{
|
||||
int ElaBreadcrumbBarModel::rowCount(const QModelIndex &parent) const {
|
||||
if (!_breadcrumbList.isEmpty()) {
|
||||
return _breadcrumbList.count() * 2 - 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
QVariant ElaBreadcrumbBarModel::data(const QModelIndex& index, int role) const
|
||||
{
|
||||
if (role == Qt::DisplayRole)
|
||||
{
|
||||
if (index.row() % 2 == 0)
|
||||
{
|
||||
QVariant ElaBreadcrumbBarModel::data(const QModelIndex &index, int role) const {
|
||||
if (role == Qt::DisplayRole) {
|
||||
if (index.row() % 2 == 0) {
|
||||
return _breadcrumbList[index.row() / 2];
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
return ">";
|
||||
}
|
||||
}
|
||||
else if (role == Qt::UserRole)
|
||||
{
|
||||
if (index.row() == _breadcrumbList.count() * 2 - 2 || index.row() == _breadcrumbList.count() * 2 - 3)
|
||||
{
|
||||
} else if (role == Qt::UserRole) {
|
||||
if (index.row() == _breadcrumbList.count() * 2 - 2 || index.row() == _breadcrumbList.count() * 2 - 3) {
|
||||
return QString("LastBreadcrumb");
|
||||
}
|
||||
}
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
void ElaBreadcrumbBarModel::appendBreadcrumb(QString breadcrumb)
|
||||
{
|
||||
if (!breadcrumb.isEmpty())
|
||||
{
|
||||
if (_breadcrumbList.count() && _breadcrumbList.last() == breadcrumb)
|
||||
{
|
||||
void ElaBreadcrumbBarModel::appendBreadcrumb(QString breadcrumb) {
|
||||
if (!breadcrumb.isEmpty()) {
|
||||
if (_breadcrumbList.count() && _breadcrumbList.last() == breadcrumb) {
|
||||
return;
|
||||
}
|
||||
if (_breadcrumbList.count() >= 2 && _breadcrumbList[_breadcrumbList.count() - 2] == breadcrumb)
|
||||
{
|
||||
if (_breadcrumbList.count() >= 2 && _breadcrumbList[_breadcrumbList.count() - 2] == breadcrumb) {
|
||||
beginResetModel();
|
||||
_breadcrumbList.removeLast();
|
||||
endResetModel();
|
||||
@@ -62,30 +43,24 @@ void ElaBreadcrumbBarModel::appendBreadcrumb(QString breadcrumb)
|
||||
}
|
||||
}
|
||||
|
||||
void ElaBreadcrumbBarModel::removeBreadcrumb(QString breadcrumb)
|
||||
{
|
||||
if (_breadcrumbList.contains(breadcrumb))
|
||||
{
|
||||
void ElaBreadcrumbBarModel::removeBreadcrumb(QString breadcrumb) {
|
||||
if (_breadcrumbList.contains(breadcrumb)) {
|
||||
beginResetModel();
|
||||
_breadcrumbList.removeAt(_breadcrumbList.lastIndexOf(breadcrumb));
|
||||
endResetModel();
|
||||
}
|
||||
}
|
||||
|
||||
void ElaBreadcrumbBarModel::removeBreadcrumb(int index)
|
||||
{
|
||||
if (index >= _breadcrumbList.count())
|
||||
{
|
||||
void ElaBreadcrumbBarModel::removeBreadcrumb(int index) {
|
||||
if (index >= _breadcrumbList.count()) {
|
||||
return;
|
||||
}
|
||||
beginResetModel();
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
||||
_breadcrumbList.remove(index, _breadcrumbList.count() - index);
|
||||
#else
|
||||
for (int i = _breadcrumbList.count() - 1; i >= 0; i--)
|
||||
{
|
||||
if (i < index)
|
||||
{
|
||||
for (int i = _breadcrumbList.count() - 1; i >= 0; i--) {
|
||||
if (i < index) {
|
||||
break;
|
||||
}
|
||||
_breadcrumbList.removeAt(i);
|
||||
@@ -94,19 +69,12 @@ void ElaBreadcrumbBarModel::removeBreadcrumb(int index)
|
||||
endResetModel();
|
||||
}
|
||||
|
||||
void ElaBreadcrumbBarModel::setBreadcrumbList(QStringList breadcrumbList)
|
||||
{
|
||||
void ElaBreadcrumbBarModel::setBreadcrumbList(QStringList breadcrumbList) {
|
||||
beginResetModel();
|
||||
this->_breadcrumbList = breadcrumbList;
|
||||
endResetModel();
|
||||
}
|
||||
|
||||
int ElaBreadcrumbBarModel::getBreadcrumbListCount()
|
||||
{
|
||||
return _breadcrumbList.count();
|
||||
}
|
||||
int ElaBreadcrumbBarModel::getBreadcrumbListCount() { return _breadcrumbList.count(); }
|
||||
|
||||
QStringList ElaBreadcrumbBarModel::getBreadcrumbList()
|
||||
{
|
||||
return _breadcrumbList;
|
||||
}
|
||||
QStringList ElaBreadcrumbBarModel::getBreadcrumbList() { return _breadcrumbList; }
|
||||
|
||||
Reference in New Issue
Block a user