##// END OF EJS Templates
Mini code clean on PyDataProvider...
Mini code clean on PyDataProvider Signed-off-by: Alexis Jeandet <alexis.jeandet@member.fsf.org>

File last commit:

r1486:8539a975891c
r1491:317c38eb0f17
Show More
eventsmodel.cpp
153 lines | 4.7 KiB | text/x-c | CppLexer
Converted catalogue gui tests to manual tests...
r1407 /*
This file is part of SciQLop.
SciQLop is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
SciQLop is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with SciQLop. If not, see <https://www.gnu.org/licenses/>.
*/
New Catalogue API WIP, basic models and views implemented...
r1406 #include "Catalogue2/eventsmodel.h"
Added catalog columns sorting but broken :(...
r1474 #include <SqpApplication.h>
Switched to cpp_utils package...
r1486 #include <containers/algorithms.hpp>
New Catalogue API WIP, basic models and views implemented...
r1406
EventsModel::EventsModel(QObject* parent) : QAbstractItemModel(parent) {}
EventsModel::ItemType EventsModel::type(const QModelIndex& index) const
{
Some progress on new Catalogue GUI, can display most of items, still lack edition and link to SciQLop...
r1408 if (EventsModelItem* item = to_item(index))
New Catalogue API WIP, basic models and views implemented...
r1406 {
Some progress on new Catalogue GUI, can display most of items, still lack edition and link to SciQLop...
r1408 return item->type;
New Catalogue API WIP, basic models and views implemented...
r1406 }
Some progress on new Catalogue GUI, can display most of items, still lack edition and link to SciQLop...
r1408 return ItemType::None;
New Catalogue API WIP, basic models and views implemented...
r1406 }
QVariant EventsModel::data(const QModelIndex& index, int role) const
{
Some progress on new Catalogue GUI, can display most of items, still lack edition and link to SciQLop...
r1408 if (index.isValid())
New Catalogue API WIP, basic models and views implemented...
r1406 {
Added catalog columns sorting but broken :(...
r1474 return to_item(index)->data(index.column(), role);
New Catalogue API WIP, basic models and views implemented...
r1406 }
return QVariant {};
}
QModelIndex EventsModel::index(int row, int column, const QModelIndex& parent) const
{
if (!hasIndex(row, column, parent))
{
return QModelIndex();
}
switch (type(parent))
{
Some progress on new Catalogue GUI, can display most of items, still lack edition and link to SciQLop...
r1408 case ItemType::None: // is an event
return createIndex(row, column, _items[row].get());
case ItemType::Event: // is a product
return createIndex(row, column, to_item(parent)->children[row].get());
case ItemType::Product:
QModelIndex();
New Catalogue API WIP, basic models and views implemented...
r1406 }
return QModelIndex();
}
QModelIndex EventsModel::parent(const QModelIndex& index) const
{
Some progress on new Catalogue GUI, can display most of items, still lack edition and link to SciQLop...
r1408 auto item = to_item(index);
if (item->type == ItemType::Product)
New Catalogue API WIP, basic models and views implemented...
r1406 {
Switched to cpp_utils package...
r1486 auto repoIndex = cpp_utils::containers::index_of(_items, item->parent);
Some progress on new Catalogue GUI, can display most of items, still lack edition and link to SciQLop...
r1408 return createIndex(repoIndex, 0, item->parent);
New Catalogue API WIP, basic models and views implemented...
r1406 }
return QModelIndex();
}
int EventsModel::rowCount(const QModelIndex& parent) const
{
if (parent.column() > 0)
{
return 0;
}
switch (type(parent))
{
Some progress on new Catalogue GUI, can display most of items, still lack edition and link to SciQLop...
r1408 case ItemType::None:
return _items.size();
case ItemType::Event:
return to_item(parent)->children.size();
case ItemType::Product:
New Catalogue API WIP, basic models and views implemented...
r1406 break;
}
return 0;
}
int EventsModel::columnCount(const QModelIndex& parent) const
{
return static_cast<int>(EventsModel::Columns::NbColumn);
}
QVariant EventsModel::headerData(int section, Qt::Orientation orientation, int role) const
{
if (orientation == Qt::Horizontal && role == Qt::DisplayRole && section < ColumnsNames.size())
{
return ColumnsNames[section];
}
return QVariant();
}
Added catalog columns sorting but broken :(...
r1474 void EventsModel::sort(int column, Qt::SortOrder order)
{
beginResetModel();
switch (static_cast<Columns>(column))
{
case EventsModel::Columns::Name:
std::sort(std::begin(_items), std::end(_items),
[inverse = order != Qt::SortOrder::AscendingOrder](
const std::unique_ptr<EventsModelItem>& a,
const std::unique_ptr<EventsModelItem>& b) {
return (a->event()->name < b->event()->name) xor inverse;
});
break;
case EventsModel::Columns::TStart:
std::sort(std::begin(_items), std::end(_items),
[inverse = order != Qt::SortOrder::AscendingOrder](
const std::unique_ptr<EventsModelItem>& a,
const std::unique_ptr<EventsModelItem>& b) {
Started PySide2 migration, builds with CMake and produces a working binary...
r1477 if (auto t1 = a->event()->startTime(); auto t2 = b->event()->startTime())
Added catalog columns sorting but broken :(...
r1474 {
Started PySide2 migration, builds with CMake and produces a working binary...
r1477 if (t1 and t2)
return bool((t1.value() < t2.value()) xor inverse);
Added catalog columns sorting but broken :(...
r1474 }
Started PySide2 migration, builds with CMake and produces a working binary...
r1477 return true;
Added catalog columns sorting but broken :(...
r1474 });
break;
case EventsModel::Columns::TEnd:
std::sort(std::begin(_items), std::end(_items),
[inverse = order != Qt::SortOrder::AscendingOrder](
const std::unique_ptr<EventsModelItem>& a,
const std::unique_ptr<EventsModelItem>& b) {
if (auto t1 = a->event()->stopTime(); auto t2 = b->event()->stopTime())
{
if (t1 and t2)
return bool((t1.value() < t2.value()) xor inverse);
}
return true;
});
break;
case EventsModel::Columns::Product:
break;
case EventsModel::Columns::Tags:
break;
default:
break;
}
endResetModel();
}