Added base classes for plugin UI.
							parent
							
								
									07bb708437
								
							
						
					
					
						commit
						02c5bbe788
					
				@ -0,0 +1,14 @@
 | 
			
		||||
#include "accgrid.h"
 | 
			
		||||
 | 
			
		||||
#include "tablemodel.h"
 | 
			
		||||
 | 
			
		||||
AccGrid::AccGrid(QWidget *parent) :
 | 
			
		||||
    GridForm<Person>(parent)
 | 
			
		||||
{
 | 
			
		||||
    setTableModel(new TableModel());
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
AccGrid::~AccGrid()
 | 
			
		||||
{
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -0,0 +1,18 @@
 | 
			
		||||
#ifndef ACCGRID_H
 | 
			
		||||
#define ACCGRID_H
 | 
			
		||||
 | 
			
		||||
#include <core.h>
 | 
			
		||||
#include "data/person.h"
 | 
			
		||||
 | 
			
		||||
#include "accommodation-odb.hxx"
 | 
			
		||||
 | 
			
		||||
class AccGrid : public GridForm<Person>
 | 
			
		||||
{
 | 
			
		||||
    Q_OBJECT
 | 
			
		||||
 | 
			
		||||
public:
 | 
			
		||||
    explicit AccGrid(QWidget *parent = NULL);
 | 
			
		||||
    ~AccGrid();
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
#endif // ACCGRID_H
 | 
			
		||||
@ -1,47 +0,0 @@
 | 
			
		||||
#include "accommodationform.h"
 | 
			
		||||
#include "ui_accommodationform.h"
 | 
			
		||||
 | 
			
		||||
#include <core.h>
 | 
			
		||||
#include <autotablemodel.h>
 | 
			
		||||
 | 
			
		||||
#include "dialog.h"
 | 
			
		||||
#include "data/person.h"
 | 
			
		||||
 | 
			
		||||
#include "tablemodel.h"
 | 
			
		||||
 | 
			
		||||
#include "accommodation-odb.hxx"
 | 
			
		||||
 | 
			
		||||
AccommodationForm::AccommodationForm(QWidget *parent) :
 | 
			
		||||
    QWidget(parent),
 | 
			
		||||
    ui(new Ui::AccommodationForm)
 | 
			
		||||
{
 | 
			
		||||
    ui->setupUi(this);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
AccommodationForm::~AccommodationForm()
 | 
			
		||||
{
 | 
			
		||||
    delete ui;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void AccommodationForm::fillGrid()
 | 
			
		||||
{
 | 
			
		||||
    Service<Person> service;
 | 
			
		||||
    TableModel *model = qobject_cast<TableModel*>(ui->tableView->model());
 | 
			
		||||
 | 
			
		||||
    if (model == NULL) {
 | 
			
		||||
        model = new TableModel();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    model->setData(service.all());
 | 
			
		||||
    ui->tableView->setModel(model);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void AccommodationForm::on_pushButton_clicked()
 | 
			
		||||
{
 | 
			
		||||
    Dialog *d = new Dialog();
 | 
			
		||||
    if (ui->tableView->model()->rowCount() > 0)
 | 
			
		||||
    {
 | 
			
		||||
        d->setData(((TableModel*)ui->tableView->model())->itemFromIndex(ui->tableView->currentIndex()));
 | 
			
		||||
    }
 | 
			
		||||
    d->open();
 | 
			
		||||
}
 | 
			
		||||
@ -1,27 +0,0 @@
 | 
			
		||||
#ifndef ACCOMMODATIONFORM_H
 | 
			
		||||
#define ACCOMMODATIONFORM_H
 | 
			
		||||
 | 
			
		||||
#include <QWidget>
 | 
			
		||||
 | 
			
		||||
namespace Ui {
 | 
			
		||||
class AccommodationForm;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
class AccommodationForm : public QWidget
 | 
			
		||||
{
 | 
			
		||||
    Q_OBJECT
 | 
			
		||||
 | 
			
		||||
public:
 | 
			
		||||
    explicit AccommodationForm(QWidget *parent = 0);
 | 
			
		||||
    ~AccommodationForm();
 | 
			
		||||
 | 
			
		||||
    void fillGrid();
 | 
			
		||||
 | 
			
		||||
private slots:
 | 
			
		||||
    void on_pushButton_clicked();
 | 
			
		||||
 | 
			
		||||
private:
 | 
			
		||||
    Ui::AccommodationForm *ui;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
#endif // ACCOMMODATIONFORM_H
 | 
			
		||||
@ -1,41 +0,0 @@
 | 
			
		||||
<?xml version="1.0" encoding="UTF-8"?>
 | 
			
		||||
<ui version="4.0">
 | 
			
		||||
 <class>AccommodationForm</class>
 | 
			
		||||
 <widget class="QWidget" name="AccommodationForm">
 | 
			
		||||
  <property name="geometry">
 | 
			
		||||
   <rect>
 | 
			
		||||
    <x>0</x>
 | 
			
		||||
    <y>0</y>
 | 
			
		||||
    <width>828</width>
 | 
			
		||||
    <height>548</height>
 | 
			
		||||
   </rect>
 | 
			
		||||
  </property>
 | 
			
		||||
  <property name="windowTitle">
 | 
			
		||||
   <string>Form</string>
 | 
			
		||||
  </property>
 | 
			
		||||
  <layout class="QVBoxLayout" name="verticalLayout">
 | 
			
		||||
   <item>
 | 
			
		||||
    <widget class="QPushButton" name="pushButton">
 | 
			
		||||
     <property name="text">
 | 
			
		||||
      <string>PushButton</string>
 | 
			
		||||
     </property>
 | 
			
		||||
    </widget>
 | 
			
		||||
   </item>
 | 
			
		||||
   <item>
 | 
			
		||||
    <widget class="QTableView" name="tableView">
 | 
			
		||||
     <property name="selectionMode">
 | 
			
		||||
      <enum>QAbstractItemView::SingleSelection</enum>
 | 
			
		||||
     </property>
 | 
			
		||||
     <property name="selectionBehavior">
 | 
			
		||||
      <enum>QAbstractItemView::SelectRows</enum>
 | 
			
		||||
     </property>
 | 
			
		||||
     <property name="sortingEnabled">
 | 
			
		||||
      <bool>true</bool>
 | 
			
		||||
     </property>
 | 
			
		||||
    </widget>
 | 
			
		||||
   </item>
 | 
			
		||||
  </layout>
 | 
			
		||||
 </widget>
 | 
			
		||||
 <resources/>
 | 
			
		||||
 <connections/>
 | 
			
		||||
</ui>
 | 
			
		||||
@ -1,44 +0,0 @@
 | 
			
		||||
#include "dialog.h"
 | 
			
		||||
#include "ui_dialog.h"
 | 
			
		||||
 | 
			
		||||
#include <core.h>
 | 
			
		||||
 | 
			
		||||
#include "data/person.h"
 | 
			
		||||
#include "accommodationservice.h"
 | 
			
		||||
 | 
			
		||||
#include "acform.h"
 | 
			
		||||
 | 
			
		||||
#include "accommodation-odb.hxx"
 | 
			
		||||
 | 
			
		||||
Dialog::Dialog(QWidget *parent) :
 | 
			
		||||
    QDialog(parent),
 | 
			
		||||
    ui(new Ui::Dialog)
 | 
			
		||||
{
 | 
			
		||||
    ui->setupUi(this);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
Dialog::~Dialog()
 | 
			
		||||
{
 | 
			
		||||
    delete ui;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Dialog::setData(QSharedPointer<Person> data)
 | 
			
		||||
{
 | 
			
		||||
    m_data = data;
 | 
			
		||||
 | 
			
		||||
    AcForm *form = new AcForm(this);
 | 
			
		||||
    form->setEntity(data);
 | 
			
		||||
    ui->verticalLayout->addWidget(form);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Dialog::on_buttonBox_accepted()
 | 
			
		||||
{
 | 
			
		||||
    IPlugin *plugin = Context::instance().plugins().at(0);
 | 
			
		||||
    QSharedPointer<Person> p(new Person());
 | 
			
		||||
 | 
			
		||||
    p->setFirstName(ui->lineEdit->text());
 | 
			
		||||
    p->setLastName(ui->lineEdit_2->text());
 | 
			
		||||
 | 
			
		||||
    AccommodationService *service = (AccommodationService*)plugin->service<Person>();
 | 
			
		||||
    service->pokus(p);
 | 
			
		||||
}
 | 
			
		||||
@ -1,31 +0,0 @@
 | 
			
		||||
#ifndef DIALOG_H
 | 
			
		||||
#define DIALOG_H
 | 
			
		||||
 | 
			
		||||
#include <QDialog>
 | 
			
		||||
#include <QSharedPointer>
 | 
			
		||||
 | 
			
		||||
#include "data/person.h"
 | 
			
		||||
 | 
			
		||||
namespace Ui {
 | 
			
		||||
class Dialog;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
class Dialog : public QDialog
 | 
			
		||||
{
 | 
			
		||||
    Q_OBJECT
 | 
			
		||||
 | 
			
		||||
public:
 | 
			
		||||
    explicit Dialog(QWidget *parent = 0);
 | 
			
		||||
    ~Dialog();
 | 
			
		||||
 | 
			
		||||
    void setData(QSharedPointer<Person> data);
 | 
			
		||||
 | 
			
		||||
private slots:
 | 
			
		||||
    void on_buttonBox_accepted();
 | 
			
		||||
 | 
			
		||||
private:
 | 
			
		||||
    Ui::Dialog *ui;
 | 
			
		||||
    QSharedPointer<Person> m_data;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
#endif // DIALOG_H
 | 
			
		||||
@ -1,99 +0,0 @@
 | 
			
		||||
<?xml version="1.0" encoding="UTF-8"?>
 | 
			
		||||
<ui version="4.0">
 | 
			
		||||
 <class>Dialog</class>
 | 
			
		||||
 <widget class="QDialog" name="Dialog">
 | 
			
		||||
  <property name="geometry">
 | 
			
		||||
   <rect>
 | 
			
		||||
    <x>0</x>
 | 
			
		||||
    <y>0</y>
 | 
			
		||||
    <width>544</width>
 | 
			
		||||
    <height>444</height>
 | 
			
		||||
   </rect>
 | 
			
		||||
  </property>
 | 
			
		||||
  <property name="windowTitle">
 | 
			
		||||
   <string>Dialog</string>
 | 
			
		||||
  </property>
 | 
			
		||||
  <widget class="QDialogButtonBox" name="buttonBox">
 | 
			
		||||
   <property name="geometry">
 | 
			
		||||
    <rect>
 | 
			
		||||
     <x>30</x>
 | 
			
		||||
     <y>340</y>
 | 
			
		||||
     <width>341</width>
 | 
			
		||||
     <height>32</height>
 | 
			
		||||
    </rect>
 | 
			
		||||
   </property>
 | 
			
		||||
   <property name="orientation">
 | 
			
		||||
    <enum>Qt::Horizontal</enum>
 | 
			
		||||
   </property>
 | 
			
		||||
   <property name="standardButtons">
 | 
			
		||||
    <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
 | 
			
		||||
   </property>
 | 
			
		||||
  </widget>
 | 
			
		||||
  <widget class="QLineEdit" name="lineEdit">
 | 
			
		||||
   <property name="geometry">
 | 
			
		||||
    <rect>
 | 
			
		||||
     <x>180</x>
 | 
			
		||||
     <y>40</y>
 | 
			
		||||
     <width>113</width>
 | 
			
		||||
     <height>23</height>
 | 
			
		||||
    </rect>
 | 
			
		||||
   </property>
 | 
			
		||||
  </widget>
 | 
			
		||||
  <widget class="QLineEdit" name="lineEdit_2">
 | 
			
		||||
   <property name="geometry">
 | 
			
		||||
    <rect>
 | 
			
		||||
     <x>180</x>
 | 
			
		||||
     <y>90</y>
 | 
			
		||||
     <width>113</width>
 | 
			
		||||
     <height>23</height>
 | 
			
		||||
    </rect>
 | 
			
		||||
   </property>
 | 
			
		||||
  </widget>
 | 
			
		||||
  <widget class="QWidget" name="verticalLayoutWidget">
 | 
			
		||||
   <property name="geometry">
 | 
			
		||||
    <rect>
 | 
			
		||||
     <x>60</x>
 | 
			
		||||
     <y>130</y>
 | 
			
		||||
     <width>421</width>
 | 
			
		||||
     <height>191</height>
 | 
			
		||||
    </rect>
 | 
			
		||||
   </property>
 | 
			
		||||
   <layout class="QVBoxLayout" name="verticalLayout"/>
 | 
			
		||||
  </widget>
 | 
			
		||||
 </widget>
 | 
			
		||||
 <resources/>
 | 
			
		||||
 <connections>
 | 
			
		||||
  <connection>
 | 
			
		||||
   <sender>buttonBox</sender>
 | 
			
		||||
   <signal>accepted()</signal>
 | 
			
		||||
   <receiver>Dialog</receiver>
 | 
			
		||||
   <slot>accept()</slot>
 | 
			
		||||
   <hints>
 | 
			
		||||
    <hint type="sourcelabel">
 | 
			
		||||
     <x>248</x>
 | 
			
		||||
     <y>254</y>
 | 
			
		||||
    </hint>
 | 
			
		||||
    <hint type="destinationlabel">
 | 
			
		||||
     <x>157</x>
 | 
			
		||||
     <y>274</y>
 | 
			
		||||
    </hint>
 | 
			
		||||
   </hints>
 | 
			
		||||
  </connection>
 | 
			
		||||
  <connection>
 | 
			
		||||
   <sender>buttonBox</sender>
 | 
			
		||||
   <signal>rejected()</signal>
 | 
			
		||||
   <receiver>Dialog</receiver>
 | 
			
		||||
   <slot>reject()</slot>
 | 
			
		||||
   <hints>
 | 
			
		||||
    <hint type="sourcelabel">
 | 
			
		||||
     <x>316</x>
 | 
			
		||||
     <y>260</y>
 | 
			
		||||
    </hint>
 | 
			
		||||
    <hint type="destinationlabel">
 | 
			
		||||
     <x>286</x>
 | 
			
		||||
     <y>274</y>
 | 
			
		||||
    </hint>
 | 
			
		||||
   </hints>
 | 
			
		||||
  </connection>
 | 
			
		||||
 </connections>
 | 
			
		||||
</ui>
 | 
			
		||||
@ -1,13 +1,13 @@
 | 
			
		||||
#ifndef COREDATA_H
 | 
			
		||||
#define COREDATA_H
 | 
			
		||||
 | 
			
		||||
class User;
 | 
			
		||||
class Permission;
 | 
			
		||||
class Role;
 | 
			
		||||
 | 
			
		||||
#include "user.h"
 | 
			
		||||
#include "role.h"
 | 
			
		||||
#include "permission.h"
 | 
			
		||||
 | 
			
		||||
#endif // COREDATA_H
 | 
			
		||||
 | 
			
		||||
#ifndef COREDATA_H
 | 
			
		||||
#define COREDATA_H
 | 
			
		||||
 | 
			
		||||
class User;
 | 
			
		||||
class Permission;
 | 
			
		||||
class Role;
 | 
			
		||||
 | 
			
		||||
#include "user.h"
 | 
			
		||||
#include "role.h"
 | 
			
		||||
#include "permission.h"
 | 
			
		||||
 | 
			
		||||
#endif // COREDATA_H
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -0,0 +1,19 @@
 | 
			
		||||
#include "defaultformhandler.h"
 | 
			
		||||
 | 
			
		||||
DefaultFormHandler::DefaultFormHandler()
 | 
			
		||||
{
 | 
			
		||||
    m_dialog = new FormDialog();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
DefaultFormHandler::~DefaultFormHandler()
 | 
			
		||||
{
 | 
			
		||||
    delete m_dialog;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void DefaultFormHandler::showForm(IForm *formWidget)
 | 
			
		||||
{
 | 
			
		||||
    m_dialog->setForm(formWidget);
 | 
			
		||||
    m_dialog->setModal(true);
 | 
			
		||||
    m_dialog->show();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -0,0 +1,32 @@
 | 
			
		||||
#ifndef DEFAULTFORMHANDLER_H
 | 
			
		||||
#define DEFAULTFORMHANDLER_H
 | 
			
		||||
 | 
			
		||||
#include "formdialog.h"
 | 
			
		||||
#include "iform.h"
 | 
			
		||||
 | 
			
		||||
#include "core_global.h"
 | 
			
		||||
 | 
			
		||||
class CORESHARED_EXPORT IFormHandler
 | 
			
		||||
{
 | 
			
		||||
public:
 | 
			
		||||
    IFormHandler() {}
 | 
			
		||||
    virtual ~IFormHandler() {}
 | 
			
		||||
 | 
			
		||||
    virtual void showForm(IForm *formWidget) = 0;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
class DefaultFormHandler : public IFormHandler
 | 
			
		||||
{
 | 
			
		||||
public:
 | 
			
		||||
    DefaultFormHandler();
 | 
			
		||||
    virtual ~DefaultFormHandler();
 | 
			
		||||
 | 
			
		||||
private:
 | 
			
		||||
    FormDialog *m_dialog;
 | 
			
		||||
 | 
			
		||||
    // IFormHandler interface
 | 
			
		||||
public:
 | 
			
		||||
    void showForm(IForm *formWidget) override;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
#endif // DEFAULTFORMHANDLER_H
 | 
			
		||||
@ -0,0 +1,31 @@
 | 
			
		||||
#include "formdialog.h"
 | 
			
		||||
#include "ui_formdialog.h"
 | 
			
		||||
 | 
			
		||||
FormDialog::FormDialog(QWidget *parent) :
 | 
			
		||||
    QDialog(parent),
 | 
			
		||||
    ui(new Ui::FormDialog)
 | 
			
		||||
{
 | 
			
		||||
    ui->setupUi(this);
 | 
			
		||||
    m_formSet = false;
 | 
			
		||||
    m_form = NULL;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
FormDialog::~FormDialog()
 | 
			
		||||
{
 | 
			
		||||
    delete ui;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void FormDialog::setForm(IForm *formWidget)
 | 
			
		||||
{
 | 
			
		||||
    if (m_form == NULL)
 | 
			
		||||
    {
 | 
			
		||||
        ui->verticalLayout->addWidget(formWidget);
 | 
			
		||||
        m_form = formWidget;
 | 
			
		||||
        setGeometry(formWidget->geometry());
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void FormDialog::on_buttonBox_accepted()
 | 
			
		||||
{
 | 
			
		||||
    m_form->saveRecord();
 | 
			
		||||
}
 | 
			
		||||
@ -0,0 +1,32 @@
 | 
			
		||||
#ifndef FORMDIALOG_H
 | 
			
		||||
#define FORMDIALOG_H
 | 
			
		||||
 | 
			
		||||
#include <QDialog>
 | 
			
		||||
#include <QWidget>
 | 
			
		||||
 | 
			
		||||
#include "iform.h"
 | 
			
		||||
 | 
			
		||||
namespace Ui {
 | 
			
		||||
class FormDialog;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
class FormDialog : public QDialog
 | 
			
		||||
{
 | 
			
		||||
    Q_OBJECT
 | 
			
		||||
 | 
			
		||||
public:
 | 
			
		||||
    explicit FormDialog(QWidget *parent = 0);
 | 
			
		||||
    ~FormDialog();
 | 
			
		||||
 | 
			
		||||
    void setForm(IForm *formWidget);
 | 
			
		||||
 | 
			
		||||
private slots:
 | 
			
		||||
    void on_buttonBox_accepted();
 | 
			
		||||
 | 
			
		||||
private:
 | 
			
		||||
    bool m_formSet;
 | 
			
		||||
    IForm *m_form;
 | 
			
		||||
    Ui::FormDialog *ui;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
#endif // FORMDIALOG_H
 | 
			
		||||
@ -0,0 +1,79 @@
 | 
			
		||||
<?xml version="1.0" encoding="UTF-8"?>
 | 
			
		||||
<ui version="4.0">
 | 
			
		||||
 <class>FormDialog</class>
 | 
			
		||||
 <widget class="QDialog" name="FormDialog">
 | 
			
		||||
  <property name="geometry">
 | 
			
		||||
   <rect>
 | 
			
		||||
    <x>0</x>
 | 
			
		||||
    <y>0</y>
 | 
			
		||||
    <width>543</width>
 | 
			
		||||
    <height>383</height>
 | 
			
		||||
   </rect>
 | 
			
		||||
  </property>
 | 
			
		||||
  <property name="windowTitle">
 | 
			
		||||
   <string>Dialog</string>
 | 
			
		||||
  </property>
 | 
			
		||||
  <layout class="QVBoxLayout" name="verticalLayout_2">
 | 
			
		||||
   <property name="leftMargin">
 | 
			
		||||
    <number>0</number>
 | 
			
		||||
   </property>
 | 
			
		||||
   <property name="topMargin">
 | 
			
		||||
    <number>0</number>
 | 
			
		||||
   </property>
 | 
			
		||||
   <property name="rightMargin">
 | 
			
		||||
    <number>0</number>
 | 
			
		||||
   </property>
 | 
			
		||||
   <property name="bottomMargin">
 | 
			
		||||
    <number>9</number>
 | 
			
		||||
   </property>
 | 
			
		||||
   <item>
 | 
			
		||||
    <layout class="QVBoxLayout" name="verticalLayout"/>
 | 
			
		||||
   </item>
 | 
			
		||||
   <item>
 | 
			
		||||
    <widget class="QDialogButtonBox" name="buttonBox">
 | 
			
		||||
     <property name="orientation">
 | 
			
		||||
      <enum>Qt::Horizontal</enum>
 | 
			
		||||
     </property>
 | 
			
		||||
     <property name="standardButtons">
 | 
			
		||||
      <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
 | 
			
		||||
     </property>
 | 
			
		||||
    </widget>
 | 
			
		||||
   </item>
 | 
			
		||||
  </layout>
 | 
			
		||||
 </widget>
 | 
			
		||||
 <resources/>
 | 
			
		||||
 <connections>
 | 
			
		||||
  <connection>
 | 
			
		||||
   <sender>buttonBox</sender>
 | 
			
		||||
   <signal>accepted()</signal>
 | 
			
		||||
   <receiver>FormDialog</receiver>
 | 
			
		||||
   <slot>accept()</slot>
 | 
			
		||||
   <hints>
 | 
			
		||||
    <hint type="sourcelabel">
 | 
			
		||||
     <x>248</x>
 | 
			
		||||
     <y>254</y>
 | 
			
		||||
    </hint>
 | 
			
		||||
    <hint type="destinationlabel">
 | 
			
		||||
     <x>157</x>
 | 
			
		||||
     <y>274</y>
 | 
			
		||||
    </hint>
 | 
			
		||||
   </hints>
 | 
			
		||||
  </connection>
 | 
			
		||||
  <connection>
 | 
			
		||||
   <sender>buttonBox</sender>
 | 
			
		||||
   <signal>rejected()</signal>
 | 
			
		||||
   <receiver>FormDialog</receiver>
 | 
			
		||||
   <slot>reject()</slot>
 | 
			
		||||
   <hints>
 | 
			
		||||
    <hint type="sourcelabel">
 | 
			
		||||
     <x>316</x>
 | 
			
		||||
     <y>260</y>
 | 
			
		||||
    </hint>
 | 
			
		||||
    <hint type="destinationlabel">
 | 
			
		||||
     <x>286</x>
 | 
			
		||||
     <y>274</y>
 | 
			
		||||
    </hint>
 | 
			
		||||
   </hints>
 | 
			
		||||
  </connection>
 | 
			
		||||
 </connections>
 | 
			
		||||
</ui>
 | 
			
		||||
@ -0,0 +1,124 @@
 | 
			
		||||
#ifndef GRIDFORM_H
 | 
			
		||||
#define GRIDFORM_H
 | 
			
		||||
 | 
			
		||||
#include <QWidget>
 | 
			
		||||
 | 
			
		||||
#include "autoform.h"
 | 
			
		||||
#include "autotablemodel.h"
 | 
			
		||||
#include "context.h"
 | 
			
		||||
#include "iplugin.h"
 | 
			
		||||
 | 
			
		||||
#include "igridform.h"
 | 
			
		||||
 | 
			
		||||
template<class T>
 | 
			
		||||
class GridForm : public IGridForm
 | 
			
		||||
{
 | 
			
		||||
 | 
			
		||||
public:
 | 
			
		||||
    explicit GridForm(QWidget *parent = 0) :
 | 
			
		||||
    IGridForm(parent)
 | 
			
		||||
{
 | 
			
		||||
    m_form = NULL;
 | 
			
		||||
    m_tableModel = NULL;
 | 
			
		||||
    m_formHandler = new DefaultFormHandler();
 | 
			
		||||
}
 | 
			
		||||
    virtual ~GridForm()
 | 
			
		||||
    {
 | 
			
		||||
        delete m_formHandler;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    void setForm(AutoForm<T> *form) {
 | 
			
		||||
        Q_ASSERT(m_form == NULL);
 | 
			
		||||
 | 
			
		||||
        m_form = form;
 | 
			
		||||
        //m_form->setParent(this);
 | 
			
		||||
 | 
			
		||||
        connect(m_form, SIGNAL(recordAdded()), this, SLOT(saveNew()));
 | 
			
		||||
        connect(m_form, SIGNAL(recordUpdated()), this, SLOT(saveUpdate()));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    void setTableModel(AutoTableModel<T> *tableModel) {
 | 
			
		||||
        Q_ASSERT(m_tableModel == NULL);
 | 
			
		||||
 | 
			
		||||
        m_tableModel = tableModel;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    void setFormHandler(IFormHandler *handler) {
 | 
			
		||||
        delete m_formHandler;
 | 
			
		||||
        m_formHandler = handler;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
public slots:
 | 
			
		||||
    void fillData() {
 | 
			
		||||
        if (m_tableModel == NULL) {
 | 
			
		||||
            Q_ASSERT(false);
 | 
			
		||||
            return;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        m_tableModel->setData(service()->all());
 | 
			
		||||
        tableView()->setModel(m_tableModel);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
protected slots:
 | 
			
		||||
    void saveNew() {
 | 
			
		||||
        service()->save(m_form->entity());
 | 
			
		||||
        m_tableModel->addRow(m_form->entity());
 | 
			
		||||
        emit dataChanged();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    void saveUpdate() {
 | 
			
		||||
        service()->update(m_form->entity());
 | 
			
		||||
        emit dataChanged();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
private:
 | 
			
		||||
    AutoForm<T> *m_form;
 | 
			
		||||
    AutoTableModel<T> *m_tableModel;
 | 
			
		||||
    IFormHandler *m_formHandler;
 | 
			
		||||
 | 
			
		||||
    Service<T> *service() {
 | 
			
		||||
        IPlugin *plugin = Context::instance().plugin(pluginId());
 | 
			
		||||
        if (plugin == NULL) {
 | 
			
		||||
            Q_ASSERT(false);
 | 
			
		||||
            return NULL;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        Service<T> *service = plugin->service<T>();
 | 
			
		||||
        if (service == NULL) {
 | 
			
		||||
            Q_ASSERT(false);
 | 
			
		||||
            return NULL;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return service;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // IGridForm interface
 | 
			
		||||
protected:
 | 
			
		||||
    void handleNewRecord() override
 | 
			
		||||
    {
 | 
			
		||||
        if (m_form == NULL)
 | 
			
		||||
        {
 | 
			
		||||
            Q_ASSERT(false);
 | 
			
		||||
            return;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        m_form->setEntity(QSharedPointer<T>(new T()));
 | 
			
		||||
        m_form->setNewRec(true);
 | 
			
		||||
        m_formHandler->showForm(m_form);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    void handleEditRecord() override
 | 
			
		||||
    {
 | 
			
		||||
        if (m_form == NULL || m_tableModel == NULL || tableView()->currentIndex().row() < 0)
 | 
			
		||||
        {
 | 
			
		||||
            Q_ASSERT(false);
 | 
			
		||||
            return;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        m_form->setEntity(m_tableModel->itemFromIndex(tableView()->currentIndex()));
 | 
			
		||||
        m_form->setNewRec(false);
 | 
			
		||||
        m_formHandler->showForm(m_form);
 | 
			
		||||
    }
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
#endif // GRIDFORM_H
 | 
			
		||||
@ -0,0 +1,88 @@
 | 
			
		||||
<?xml version="1.0" encoding="UTF-8"?>
 | 
			
		||||
<ui version="4.0">
 | 
			
		||||
 <class>GridForm</class>
 | 
			
		||||
 <widget class="QWidget" name="GridForm">
 | 
			
		||||
  <property name="geometry">
 | 
			
		||||
   <rect>
 | 
			
		||||
    <x>0</x>
 | 
			
		||||
    <y>0</y>
 | 
			
		||||
    <width>680</width>
 | 
			
		||||
    <height>480</height>
 | 
			
		||||
   </rect>
 | 
			
		||||
  </property>
 | 
			
		||||
  <property name="windowTitle">
 | 
			
		||||
   <string>Form</string>
 | 
			
		||||
  </property>
 | 
			
		||||
  <layout class="QVBoxLayout" name="verticalLayout">
 | 
			
		||||
   <item>
 | 
			
		||||
    <widget class="QWidget" name="widget" native="true">
 | 
			
		||||
     <layout class="QHBoxLayout" name="horizontalLayout">
 | 
			
		||||
      <item>
 | 
			
		||||
       <widget class="QToolButton" name="btnNew">
 | 
			
		||||
        <property name="text">
 | 
			
		||||
         <string>N</string>
 | 
			
		||||
        </property>
 | 
			
		||||
       </widget>
 | 
			
		||||
      </item>
 | 
			
		||||
      <item>
 | 
			
		||||
       <widget class="QToolButton" name="btnEdit">
 | 
			
		||||
        <property name="text">
 | 
			
		||||
         <string>E</string>
 | 
			
		||||
        </property>
 | 
			
		||||
       </widget>
 | 
			
		||||
      </item>
 | 
			
		||||
      <item>
 | 
			
		||||
       <widget class="QToolButton" name="btnDelete">
 | 
			
		||||
        <property name="text">
 | 
			
		||||
         <string>D</string>
 | 
			
		||||
        </property>
 | 
			
		||||
       </widget>
 | 
			
		||||
      </item>
 | 
			
		||||
      <item>
 | 
			
		||||
       <widget class="QToolButton" name="btnFilter">
 | 
			
		||||
        <property name="text">
 | 
			
		||||
         <string>F</string>
 | 
			
		||||
        </property>
 | 
			
		||||
       </widget>
 | 
			
		||||
      </item>
 | 
			
		||||
      <item>
 | 
			
		||||
       <widget class="QToolButton" name="btnPrint">
 | 
			
		||||
        <property name="text">
 | 
			
		||||
         <string>P</string>
 | 
			
		||||
        </property>
 | 
			
		||||
       </widget>
 | 
			
		||||
      </item>
 | 
			
		||||
      <item>
 | 
			
		||||
       <spacer name="horizontalSpacer">
 | 
			
		||||
        <property name="orientation">
 | 
			
		||||
         <enum>Qt::Horizontal</enum>
 | 
			
		||||
        </property>
 | 
			
		||||
        <property name="sizeHint" stdset="0">
 | 
			
		||||
         <size>
 | 
			
		||||
          <width>40</width>
 | 
			
		||||
          <height>20</height>
 | 
			
		||||
         </size>
 | 
			
		||||
        </property>
 | 
			
		||||
       </spacer>
 | 
			
		||||
      </item>
 | 
			
		||||
     </layout>
 | 
			
		||||
    </widget>
 | 
			
		||||
   </item>
 | 
			
		||||
   <item>
 | 
			
		||||
    <widget class="QTableView" name="tableView">
 | 
			
		||||
     <property name="selectionMode">
 | 
			
		||||
      <enum>QAbstractItemView::SingleSelection</enum>
 | 
			
		||||
     </property>
 | 
			
		||||
     <property name="selectionBehavior">
 | 
			
		||||
      <enum>QAbstractItemView::SelectRows</enum>
 | 
			
		||||
     </property>
 | 
			
		||||
     <property name="sortingEnabled">
 | 
			
		||||
      <bool>true</bool>
 | 
			
		||||
     </property>
 | 
			
		||||
    </widget>
 | 
			
		||||
   </item>
 | 
			
		||||
  </layout>
 | 
			
		||||
 </widget>
 | 
			
		||||
 <resources/>
 | 
			
		||||
 <connections/>
 | 
			
		||||
</ui>
 | 
			
		||||
@ -0,0 +1,10 @@
 | 
			
		||||
#include "iform.h"
 | 
			
		||||
 | 
			
		||||
IForm::IForm(QWidget *parent) : QWidget(parent)
 | 
			
		||||
{   
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
IForm::~IForm()
 | 
			
		||||
{
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -0,0 +1,23 @@
 | 
			
		||||
#ifndef IFORM_H
 | 
			
		||||
#define IFORM_H
 | 
			
		||||
 | 
			
		||||
#include <QWidget>
 | 
			
		||||
 | 
			
		||||
class IForm : public QWidget
 | 
			
		||||
{
 | 
			
		||||
    Q_OBJECT
 | 
			
		||||
 | 
			
		||||
public:
 | 
			
		||||
    explicit IForm(QWidget *parent = 0);
 | 
			
		||||
    virtual ~IForm();
 | 
			
		||||
 | 
			
		||||
signals:
 | 
			
		||||
    void recordAdded();
 | 
			
		||||
    void recordUpdated();
 | 
			
		||||
    void validationError(QString errMessage);
 | 
			
		||||
 | 
			
		||||
public slots:
 | 
			
		||||
    virtual bool saveRecord() = 0;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
#endif // IFORM_H
 | 
			
		||||
@ -0,0 +1,40 @@
 | 
			
		||||
#include "igridform.h"
 | 
			
		||||
 | 
			
		||||
#include "ui_gridform.h"
 | 
			
		||||
 | 
			
		||||
IGridForm::IGridForm(QWidget *parent) :
 | 
			
		||||
    QWidget(parent),
 | 
			
		||||
    ui(new Ui::GridForm)
 | 
			
		||||
{
 | 
			
		||||
    ui->setupUi(this);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
IGridForm::~IGridForm()
 | 
			
		||||
{
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void IGridForm::setPluginId(const QString &pluginId)
 | 
			
		||||
{
 | 
			
		||||
    m_pluginId = pluginId;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
QString IGridForm::pluginId()
 | 
			
		||||
{
 | 
			
		||||
    return m_pluginId;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
QTableView *IGridForm::tableView()
 | 
			
		||||
{
 | 
			
		||||
    return ui->tableView;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
void IGridForm::on_btnNew_clicked()
 | 
			
		||||
{
 | 
			
		||||
    handleNewRecord();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void IGridForm::on_btnEdit_clicked()
 | 
			
		||||
{
 | 
			
		||||
    handleEditRecord();
 | 
			
		||||
}
 | 
			
		||||
@ -0,0 +1,52 @@
 | 
			
		||||
#ifndef IGRIDFORM_H
 | 
			
		||||
#define IGRIDFORM_H
 | 
			
		||||
 | 
			
		||||
#include <QWidget>
 | 
			
		||||
#include <QString>
 | 
			
		||||
#include <QTableView>
 | 
			
		||||
 | 
			
		||||
#include "defaultformhandler.h"
 | 
			
		||||
#include "core_global.h"
 | 
			
		||||
 | 
			
		||||
namespace Ui {
 | 
			
		||||
    class GridForm;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
class CORESHARED_EXPORT IGridForm : public QWidget
 | 
			
		||||
{
 | 
			
		||||
    Q_OBJECT
 | 
			
		||||
 | 
			
		||||
public:
 | 
			
		||||
    explicit IGridForm(QWidget *parent = 0);
 | 
			
		||||
    virtual ~IGridForm();
 | 
			
		||||
 | 
			
		||||
    void setPluginId(const QString &pluginId);
 | 
			
		||||
    QString pluginId();
 | 
			
		||||
    QTableView *tableView();
 | 
			
		||||
 | 
			
		||||
signals:
 | 
			
		||||
    void dataChanged();
 | 
			
		||||
 | 
			
		||||
public slots:
 | 
			
		||||
    virtual void fillData() = 0;
 | 
			
		||||
 | 
			
		||||
protected slots:
 | 
			
		||||
    virtual void saveNew() = 0;
 | 
			
		||||
    virtual void saveUpdate() = 0;
 | 
			
		||||
 | 
			
		||||
protected:
 | 
			
		||||
    virtual void handleNewRecord() = 0;
 | 
			
		||||
    virtual void handleEditRecord() = 0;
 | 
			
		||||
    //virtual void handleDeleteRecord() = 0;
 | 
			
		||||
 | 
			
		||||
private slots:
 | 
			
		||||
    void on_btnNew_clicked();
 | 
			
		||||
    void on_btnEdit_clicked();
 | 
			
		||||
 | 
			
		||||
private:
 | 
			
		||||
    QString m_pluginId;
 | 
			
		||||
    IFormHandler *m_formHandler;
 | 
			
		||||
    Ui::GridForm *ui;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
#endif // IGRIDFORM_H
 | 
			
		||||
					Loading…
					
					
				
		Reference in New Issue