#ifndef EXTERNALDATABASE_H
#define EXTERNALDATABASE_H

#include <QDialog>
#include <QMessageBox>
#include <QCheckBox>
#include "core.h"
#include "ui_external_database.h"


class ExternalDatabase: public QDialog, public Ui::ExternalDatabase {
	Q_OBJECT
public:
	explicit ExternalDatabase(QWidget * parent = 0);
	~ExternalDatabase();
	
	bool showImport(QSqlDatabase & db_);
	bool showExport(QSqlDatabase & db_);
	
private:
	bool eventFilter(QObject * o, QEvent * e);
	bool show(QSqlDatabase db_from, QSqlDatabase db_to);
	void setDatabase();
	void fillINDTree(QTreeWidget * tree, const QString & qs);
	void checkAll(bool on);
	int insertRecord(const QSqlRecord & r, const QString & table, QSqlDatabase & base);
	void removeRecord(int id, const QString & table, QSqlDatabase & base);
	//int lastInsertedID(QSqlDatabase & base);

	bool import;
	QSqlDatabase dbf, dbt;
	QSqlQueryModel models[4];
	BlockItem blockitem;
	QCheckBox * check_for_table, * check_for_all;
	QMessageBox msgbox;

private slots:
	void ok();
	void checkDependencies();
	void treeItemChanged(QTreeWidgetItem * item, int);
	void on_treeDevices_currentItemChanged(QTreeWidgetItem * item, QTreeWidgetItem * );
	void on_treeDevices_itemChanged(QTreeWidgetItem * item, int);
	void on_buttonAll_clicked() {checkAll(true);}
	void on_buttonNone_clicked() {checkAll(false);}
	
};

#endif // EXTERNALDATABASE_H
