Skip to content
Snippets Groups Projects
Commit 4de56a9a authored by Pospelov, Gennady's avatar Pospelov, Gennady
Browse files

Fixed number of rows in proxy model.

parent 3760bf80
No related branches found
No related tags found
No related merge requests found
......@@ -84,15 +84,15 @@ int ComponentProxyModel::rowCount(const QModelIndex& parent) const
QModelIndex sourceParent;
if (parent.isValid())
sourceParent = mapToSource(parent);
int count = 0;
QMapIterator<QPersistentModelIndex, QPersistentModelIndex> it(m_proxySourceParent);
QSet<int> rows;
while (it.hasNext()) {
it.next();
if (it.value() == sourceParent)
count++;
rows.insert(it.value().row());
}
return count;
return rows.size();
}
int ComponentProxyModel::columnCount(const QModelIndex& parent) const
......@@ -115,11 +115,10 @@ void ComponentProxyModel::buildModelMap()
m_sourceToProxy.insert(QPersistentModelIndex(index), proxy);
QPersistentModelIndex sourceParent;
if (item->parent())
sourceParent = item->parent()->index();
if (index.parent().isValid())
sourceParent = index.parent();
m_proxySourceParent.insert(proxy, sourceParent);
});
}
......@@ -18,6 +18,7 @@
#include "mainwindow.h"
#include "ComponentProxyModel.h"
#include "SampleModel.h"
#include "item_constants.h"
#include <QTreeView>
#include <QBoxLayout>
#include <QPushButton>
......@@ -25,6 +26,7 @@
TestComponentView::TestComponentView(MainWindow* mainWindow)
: m_mainWindow(mainWindow)
, m_sourceModel(nullptr)
, m_proxyModel(new ComponentProxyModel(this))
, m_sourceTree(new QTreeView)
, m_proxyTree(new QTreeView)
......@@ -47,12 +49,22 @@ TestComponentView::TestComponentView(MainWindow* mainWindow)
setLayout(vlayout);
m_sourceTree->setModel(m_mainWindow->sampleModel());
init_source();
}
void TestComponentView::onUpdateRequest()
{
qDebug() << "TestComponentView::onUpdateRequest() ->";
m_proxyTree->setModel(m_proxyModel);
m_proxyModel->setSessionModel(m_mainWindow->sampleModel());
m_proxyModel->setSessionModel(m_sourceModel);
}
void TestComponentView::init_source()
{
m_sourceModel = new SessionModel("TestModel");
SessionItem* item = m_sourceModel->insertNewItem(Constants::PropertyType);
item->setDisplayName("PropertyItem");
item->setValue(42.0);
m_sourceTree->setModel(m_sourceModel);
}
......@@ -24,6 +24,7 @@ class MainWindow;
class QPushButton;
class ComponentProxyModel;
class QTreeView;
class SessionModel;
//! View to tests QListView working with ComponentProxyModel.
......@@ -37,7 +38,10 @@ private slots:
void onUpdateRequest();
private:
void init_source();
MainWindow* m_mainWindow;
SessionModel* m_sourceModel;
ComponentProxyModel* m_proxyModel;
QTreeView* m_sourceTree;
QTreeView* m_proxyTree;
......
......@@ -4,6 +4,7 @@
#include "item_constants.h"
#include "ComponentProxyModel.h"
#include <QSignalSpy>
#include <QDebug>
class TestComponentProxyModel : public QObject
{
......@@ -13,9 +14,10 @@ public:
private slots:
void test_emptyModel();
void test_setModel();
void test_setModelWithItem();
};
//! Testing iteration over empty model.
//! Empty proxy model.
inline void TestComponentProxyModel::test_emptyModel()
{
......@@ -25,6 +27,8 @@ inline void TestComponentProxyModel::test_emptyModel()
QVERIFY(proxy.sourceModel() == nullptr);
}
//! Set empty model to proxy.
inline void TestComponentProxyModel::test_setModel()
{
SessionModel model("TestModel");
......@@ -36,4 +40,20 @@ inline void TestComponentProxyModel::test_setModel()
QCOMPARE(spy.count(), 1);
QCOMPARE(proxy.rowCount(QModelIndex()), 0);
QCOMPARE(proxy.columnCount(QModelIndex()), static_cast<int>(SessionModel::MAX_COLUMNS));
QCOMPARE(proxy.sourceModel(), &model);
}
//! Set model to proxy. Model contains simple item.
inline void TestComponentProxyModel::test_setModelWithItem()
{
SessionModel model("TestModel");
model.insertNewItem(Constants::PropertyType);
ComponentProxyModel proxy;
proxy.setSessionModel(&model);
QCOMPARE(model.rowCount(QModelIndex()), 1);
QCOMPARE(model.columnCount(QModelIndex()), static_cast<int>(SessionModel::MAX_COLUMNS));
QCOMPARE(proxy.rowCount(QModelIndex()), 1);
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment