git-svn-id: svn://db.shs.com.ru/libs@575 a8b55f48-bf90-11e4-a774-851b48703e85
This commit is contained in:
@@ -19,6 +19,8 @@ enum ColumnContainers {
|
||||
|
||||
ContainersModel::ContainersModel() {
|
||||
mode_changes = false;
|
||||
ls_column = 0;
|
||||
ls_order = Qt::AscendingOrder;
|
||||
all.resize(columnCount(), 0L);
|
||||
prev_all.resize(all.size(), 0L);
|
||||
}
|
||||
@@ -45,7 +47,7 @@ void ContainersModel::update(const PIVector<PIIntrospectionContainers::TypeInfo>
|
||||
beginRemoveRows(QModelIndex(), t.size_s(), pts - 1);
|
||||
endRemoveRows();
|
||||
}
|
||||
dataChanged(index(0, 0), index(cur_data.size_s() - 1, columnCount()));
|
||||
sort(ls_column, ls_order);
|
||||
emit headerDataChanged(Qt::Horizontal, ccCount, columnCount());
|
||||
}
|
||||
|
||||
@@ -108,7 +110,9 @@ QVariant ContainersModel::data(const QModelIndex & index, int role) const {
|
||||
if (role == Qt::DisplayRole || role == Qt::UserRole) {
|
||||
switch (index.column()) {
|
||||
case ccType: return PI2QString(t.name);
|
||||
case ccItemSize: return PI2QString(PIString::readableSize(t.item_size));
|
||||
case ccItemSize:
|
||||
if (role == Qt::UserRole) return t.item_size;
|
||||
return PI2QString(PIString::readableSize(t.item_size));
|
||||
default: break;
|
||||
}
|
||||
if (mode_changes) {
|
||||
@@ -153,10 +157,50 @@ Qt::ItemFlags ContainersModel::flags(const QModelIndex & index) const {
|
||||
}
|
||||
|
||||
|
||||
//bool cmp(const PIIntrospectionContainers::TypeInfo & a, const PIIntrospectionContainers::TypeInfo & b);
|
||||
int cmp_func_name_a(const PIIntrospectionContainers::TypeInfo * t0, const PIIntrospectionContainers::TypeInfo * t1) {
|
||||
return QString::localeAwareCompare(PI2QString(t0->name), PI2QString(t1->name));
|
||||
}
|
||||
int cmp_func_name_d(const PIIntrospectionContainers::TypeInfo * t0, const PIIntrospectionContainers::TypeInfo * t1) {
|
||||
return -cmp_func_name_a(t0, t1);
|
||||
}
|
||||
#define CMP_FUNC(field) \
|
||||
int cmp_func_##field##_a(const PIIntrospectionContainers::TypeInfo * t0, const PIIntrospectionContainers::TypeInfo * t1) { \
|
||||
return (t0->field) <= (t1->field) ? -1 : ((t0->field) == (t1->field) ? 0 : 1); \
|
||||
} \
|
||||
int cmp_func_##field##_d(const PIIntrospectionContainers::TypeInfo * t0, const PIIntrospectionContainers::TypeInfo * t1) { \
|
||||
return -cmp_func_##field##_a(t0, t1); \
|
||||
}
|
||||
CMP_FUNC(item_size)
|
||||
CMP_FUNC(count)
|
||||
CMP_FUNC(allocated)
|
||||
CMP_FUNC(used)
|
||||
#undef CMP_FUNC
|
||||
void ContainersModel::sort(int column, Qt::SortOrder order) {
|
||||
ls_column = column;
|
||||
ls_order = order;
|
||||
if (cur_data.isEmpty()) return;
|
||||
PIVector<PIIntrospectionContainers::TypeInfo>::CompareFunc cf = 0;
|
||||
switch (column) {
|
||||
case ccType : cf = order == Qt::AscendingOrder ? cmp_func_name_a : cmp_func_name_d; break;
|
||||
case ccItemSize : cf = order == Qt::AscendingOrder ? cmp_func_item_size_a : cmp_func_item_size_d; break;
|
||||
case ccCount : cf = order == Qt::AscendingOrder ? cmp_func_count_a : cmp_func_count_d; break;
|
||||
case ccBytesAllocated: cf = order == Qt::AscendingOrder ? cmp_func_allocated_a : cmp_func_allocated_d; break;
|
||||
case ccBytesUsed : cf = order == Qt::AscendingOrder ? cmp_func_used_a : cmp_func_used_d; break;
|
||||
default : break;
|
||||
}
|
||||
if (cf)
|
||||
cur_data.sort(cf);
|
||||
qDebug() << "sort" << column << order;
|
||||
dataChanged(index(0, 0), index(cur_data.size_s() - 1, columnCount()));
|
||||
}
|
||||
|
||||
|
||||
void ContainersModel::setChangesMode(bool yes) {
|
||||
mode_changes = yes;
|
||||
if (cur_data.isEmpty()) return;
|
||||
dataChanged(index(0, ccCount), index(cur_data.size_s() - 1, columnCount()));
|
||||
sort(ls_column, ls_order);
|
||||
//dataChanged(index(0, ccCount), index(cur_data.size_s() - 1, columnCount()));
|
||||
emit headerDataChanged(Qt::Horizontal, ccCount, columnCount());
|
||||
}
|
||||
|
||||
|
||||
@@ -25,11 +25,14 @@ public:
|
||||
QVariant headerData(int section, Qt::Orientation orientation, int role) const;
|
||||
QVariant data(const QModelIndex & index, int role) const;
|
||||
Qt::ItemFlags flags(const QModelIndex & index) const;
|
||||
void sort(int column, Qt::SortOrder order = Qt::AscendingOrder);
|
||||
|
||||
protected:
|
||||
PIVector<PIIntrospectionContainers::TypeInfo> cur_data;
|
||||
PIMap<uint, PIIntrospectionContainers::TypeInfo> prev_data;
|
||||
PIVector<llong> all, prev_all;
|
||||
Qt::SortOrder ls_order;
|
||||
int ls_column;
|
||||
bool mode_changes;
|
||||
|
||||
public slots:
|
||||
@@ -62,6 +65,8 @@ protected:
|
||||
ContainersModel * model;
|
||||
|
||||
private slots:
|
||||
void sessionSave(QByteArray * data) {*data = treeContainers->header()->saveState();}
|
||||
void sessionLoad(QByteArray * data) {treeContainers->header()->restoreState(*data);}
|
||||
|
||||
public slots:
|
||||
|
||||
|
||||
Reference in New Issue
Block a user