#pragma once
#include "QxModelView.h"

class MultipleTableView;

class OrmModelBase : public qx::IxModel
{
	friend MultipleTableView;
	Q_OBJECT
public:
	static const int pageSize = 20;

public:
	OrmModelBase(QObject *parent);
	virtual ~OrmModelBase();

	bool getMultiSelect() const { return multiSelect; }

	void setMultiSelect(bool val) { multiSelect = val; }

	const int getTotalCount() { return totalCount; }

	const int getPageCount() { return ceil(totalCount*1.0 / pageSize); };

	void setAutoUpdate(){ setAutoUpdateDatabase(e_auto_update_on_field_change); };

signals:
	void checkStateChanged(Qt::CheckState state, int row);

public:
    bool setData(const QModelIndex &, const QVariant &, int role= Qt::EditRole) override;

    Qt::ItemFlags flags(const QModelIndex &) const override;

    QVariant data(const QModelIndex &index, int role) const override;

protected:
	void limit(qx::QxSqlQuery &query, int pageIndex);

	void count(const qx::QxSqlQuery  &query);

protected:
	QMap<int, Qt::CheckState> checkStateMap;
	bool multiSelect;
	long totalCount;
};
