Master properties widget : enable live edit mode

git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@3995 bfdf4180-ca20-0410-9c96-a3a8aa849046
This commit is contained in:
blacksun
2015-05-29 07:28:58 +00:00
parent 7e2ac0eea6
commit ba888ac726
3 changed files with 43 additions and 18 deletions

View File

@@ -42,7 +42,7 @@ class PropertiesEditorWidget : public QWidget
virtual bool setLiveEdit (bool live_edit); virtual bool setLiveEdit (bool live_edit);
bool isLiveEdit() const; bool isLiveEdit() const;
private: protected:
virtual void enableLiveEdit() {} virtual void enableLiveEdit() {}
virtual void disableLiveEdit() {} virtual void disableLiveEdit() {}

View File

@@ -70,8 +70,12 @@ void MasterPropertiesWidget::setElement(Element *element)
} }
else m_project = nullptr; else m_project = nullptr;
//Keep up to date this widget when the linked elements of m_element change
if (m_element) disconnect(m_element, &Element::linkedElementChanged, this, &MasterPropertiesWidget::updateUi);
m_element = element; m_element = element;
buildInterface(); connect(m_element, &Element::linkedElementChanged, this, &MasterPropertiesWidget::updateUi);
updateUi();
} }
/** /**
@@ -95,7 +99,7 @@ void MasterPropertiesWidget::reset() {
delete lwi; delete lwi;
} }
lwi_hash.clear(); lwi_hash.clear();
buildInterface(); updateUi();
} }
/** /**
@@ -145,10 +149,22 @@ QUndoCommand* MasterPropertiesWidget::associatedUndo() const {
} }
/** /**
* @brief MasterPropertiesWidget::buildInterface * @brief MasterPropertiesWidget::setLiveEdit
* @param live_edit = true : live edit is enable
* else false : live edit is disable.
* @return always true because live edit is handled by this editor widget
*/
bool MasterPropertiesWidget::setLiveEdit(bool live_edit)
{
m_live_edit = live_edit;
return true;
}
/**
* @brief MasterPropertiesWidget::updateUi
* Build the interface of the widget * Build the interface of the widget
*/ */
void MasterPropertiesWidget::buildInterface() void MasterPropertiesWidget::updateUi()
{ {
ui->free_list->clear(); ui->free_list->clear();
ui->linked_list->clear(); ui->linked_list->clear();
@@ -193,22 +209,28 @@ void MasterPropertiesWidget::buildInterface()
* @brief MasterPropertiesWidget::on_link_button_clicked * @brief MasterPropertiesWidget::on_link_button_clicked
* move curent item in the free_list to linked_list * move curent item in the free_list to linked_list
*/ */
void MasterPropertiesWidget::on_link_button_clicked() { void MasterPropertiesWidget::on_link_button_clicked()
//take the curent item from free_list and push it to linked_list {
//take the curent item from free_list and push it to linked_list
ui->linked_list->addItem( ui->linked_list->addItem(
ui->free_list->takeItem( ui->free_list->takeItem(
ui->free_list->currentRow())); ui->free_list->currentRow()));
if(m_live_edit) apply();
} }
/** /**
* @brief MasterPropertiesWidget::on_unlink_button_clicked * @brief MasterPropertiesWidget::on_unlink_button_clicked
* move curent item in linked_list to free_list * move curent item in linked_list to free_list
*/ */
void MasterPropertiesWidget::on_unlink_button_clicked() { void MasterPropertiesWidget::on_unlink_button_clicked()
//take the curent item from linked_list and push it to free_list {
//take the curent item from linked_list and push it to free_list
ui->free_list->addItem( ui->free_list->addItem(
ui->linked_list->takeItem( ui->linked_list->takeItem(
ui->linked_list->currentRow())); ui->linked_list->currentRow()));
if(m_live_edit) apply();
} }
/** /**
@@ -247,5 +269,5 @@ void MasterPropertiesWidget::diagramWasdeletedFromProject()
{ {
//We use a timer because if the removed diagram contain slave element linked to the edited element //We use a timer because if the removed diagram contain slave element linked to the edited element
//we must to wait for this elements be unlinked, else the linked list provide deleted elements. //we must to wait for this elements be unlinked, else the linked list provide deleted elements.
QTimer::singleShot(10, this, SLOT(buildInterface())); QTimer::singleShot(10, this, SLOT(updateUi()));
} }

View File

@@ -43,17 +43,20 @@ class MasterPropertiesWidget : public AbstractElementPropertiesEditorWidget
Q_OBJECT Q_OBJECT
public: public:
explicit MasterPropertiesWidget(Element *elmt, QWidget *parent = 0); explicit MasterPropertiesWidget(Element *elmt, QWidget *parent = 0);
~MasterPropertiesWidget(); ~MasterPropertiesWidget();
void setElement (Element *element); void setElement (Element *element);
void apply(); void apply();
void reset(); void reset();
QUndoCommand *associatedUndo () const; QUndoCommand *associatedUndo () const;
QString title() const {return tr("Référence croisée (maitre)");} QString title() const {return tr("Référence croisée (maitre)");}
bool setLiveEdit(bool live_edit);
public slots:
void updateUi();
private slots: private slots:
void buildInterface();
void on_link_button_clicked(); void on_link_button_clicked();
void on_unlink_button_clicked(); void on_unlink_button_clicked();
void showElementFromLWI(QListWidgetItem *lwi); void showElementFromLWI(QListWidgetItem *lwi);