Sort material, pose, and motion list by name

master
Jeremy Hu 2019-06-26 07:24:22 +09:30
parent 7a33fa2531
commit 4689ed163a
4 changed files with 42 additions and 12 deletions

View File

@ -435,6 +435,7 @@ void Document::renameMotion(QUuid motionId, QString name)
findMotionResult->second.name = name;
emit motionNameChanged(motionId);
emit motionListChanged();
emit optionsChanged();
}
@ -507,6 +508,7 @@ void Document::renamePose(QUuid poseId, QString name)
findPoseResult->second.name = name;
emit poseNameChanged(poseId);
emit poseListChanged();
emit optionsChanged();
}
@ -3067,6 +3069,7 @@ void Document::renameMaterial(QUuid materialId, QString name)
findMaterialResult->second.name = name;
emit materialNameChanged(materialId);
emit materialListChanged();
emit optionsChanged();
}

View File

@ -249,13 +249,22 @@ void MaterialListWidget::reload()
setColumnCount(columns);
for (int i = 0; i < columns; i++)
setColumnWidth(i, columnWidth);
std::vector<QUuid> orderedMaterialIdList = m_document->materialIdList;
std::sort(orderedMaterialIdList.begin(), orderedMaterialIdList.end(), [&](const QUuid &firstMaterialId, const QUuid &secondMaterialId) {
const auto *firstMaterial = m_document->findMaterial(firstMaterialId);
const auto *secondMaterial = m_document->findMaterial(secondMaterialId);
if (nullptr == firstMaterial || nullptr == secondMaterial)
return false;
return QString::compare(firstMaterial->name, secondMaterial->name, Qt::CaseInsensitive) < 0;
});
decltype(m_document->materialIdList.size()) materialIndex = 0;
while (materialIndex < m_document->materialIdList.size()) {
decltype(orderedMaterialIdList.size()) materialIndex = 0;
while (materialIndex < orderedMaterialIdList.size()) {
QTreeWidgetItem *item = new QTreeWidgetItem(this);
item->setFlags((item->flags() | Qt::ItemIsEnabled) & ~(Qt::ItemIsSelectable) & ~(Qt::ItemIsEditable));
for (int col = 0; col < columns && materialIndex < m_document->materialIdList.size(); col++, materialIndex++) {
const auto &materialId = m_document->materialIdList[materialIndex];
for (int col = 0; col < columns && materialIndex < orderedMaterialIdList.size(); col++, materialIndex++) {
const auto &materialId = orderedMaterialIdList[materialIndex];
item->setSizeHint(col, QSize(columnWidth, MaterialWidget::preferredHeight() + 2));
item->setData(col, Qt::UserRole, materialId.toString());
MaterialWidget *widget = new MaterialWidget(m_document, materialId);

View File

@ -240,12 +240,21 @@ void MotionListWidget::reload()
for (int i = 0; i < columns; i++)
setColumnWidth(i, columnWidth);
decltype(m_document->motionIdList.size()) motionIndex = 0;
while (motionIndex < m_document->motionIdList.size()) {
std::vector<QUuid> orderedMotionIdList = m_document->motionIdList;
std::sort(orderedMotionIdList.begin(), orderedMotionIdList.end(), [&](const QUuid &firstMotionId, const QUuid &secondMotionId) {
const auto *firstMotion = m_document->findMotion(firstMotionId);
const auto *secondMotion = m_document->findMotion(secondMotionId);
if (nullptr == firstMotion || nullptr == secondMotion)
return false;
return QString::compare(firstMotion->name, secondMotion->name, Qt::CaseInsensitive) < 0;
});
decltype(orderedMotionIdList.size()) motionIndex = 0;
while (motionIndex < orderedMotionIdList.size()) {
QTreeWidgetItem *item = new QTreeWidgetItem(this);
item->setFlags((item->flags() | Qt::ItemIsEnabled) & ~(Qt::ItemIsSelectable) & ~(Qt::ItemIsEditable));
for (int col = 0; col < columns && motionIndex < m_document->motionIdList.size(); col++, motionIndex++) {
const auto &motionId = m_document->motionIdList[motionIndex];
for (int col = 0; col < columns && motionIndex < orderedMotionIdList.size(); col++, motionIndex++) {
const auto &motionId = orderedMotionIdList[motionIndex];
item->setSizeHint(col, QSize(columnWidth, MotionWidget::preferredHeight() + 2));
item->setData(col, Qt::UserRole, motionId.toString());
MotionWidget *widget = new MotionWidget(m_document, motionId);

View File

@ -240,12 +240,21 @@ void PoseListWidget::reload()
for (int i = 0; i < columns; i++)
setColumnWidth(i, columnWidth);
decltype(m_document->poseIdList.size()) poseIndex = 0;
while (poseIndex < m_document->poseIdList.size()) {
std::vector<QUuid> orderedPoseIdList = m_document->poseIdList;
std::sort(orderedPoseIdList.begin(), orderedPoseIdList.end(), [&](const QUuid &firstPoseId, const QUuid &secondPoseId) {
const auto *firstPose = m_document->findPose(firstPoseId);
const auto *secondPose = m_document->findPose(secondPoseId);
if (nullptr == firstPose || nullptr == secondPose)
return false;
return QString::compare(firstPose->name, secondPose->name, Qt::CaseInsensitive) < 0;
});
decltype(orderedPoseIdList.size()) poseIndex = 0;
while (poseIndex < orderedPoseIdList.size()) {
QTreeWidgetItem *item = new QTreeWidgetItem(this);
item->setFlags((item->flags() | Qt::ItemIsEnabled) & ~(Qt::ItemIsSelectable) & ~(Qt::ItemIsEditable));
for (int col = 0; col < columns && poseIndex < m_document->poseIdList.size(); col++, poseIndex++) {
const auto &poseId = m_document->poseIdList[poseIndex];
for (int col = 0; col < columns && poseIndex < orderedPoseIdList.size(); col++, poseIndex++) {
const auto &poseId = orderedPoseIdList[poseIndex];
item->setSizeHint(col, QSize(columnWidth, PoseWidget::preferredHeight() + 2));
item->setData(col, Qt::UserRole, poseId.toString());
PoseWidget *widget = new PoseWidget(m_document, poseId);