From 30df3ecbc1bebce294f39c9b18393446e18047b9 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Marcin=20Ka=C5=BAmierczak?= Date: Thu, 30 Dec 2010 16:33:46 +0100 Subject: [PATCH] features of DictManagerWidget restored in qml version. --- src/mdictionary/gui/DictManagerModel.cpp | 47 ++++++++++++++++++++++-- src/mdictionary/gui/DictManagerModel.h | 56 ++++++++++++++++++++++++++++- src/mdictionary/gui/DictManagerWidget.cpp | 55 +++++++++++++++------------- src/mdictionary/gui/DictTypeModel.cpp | 2 +- src/mdictionary/gui/DictTypeModel.h | 2 +- src/mdictionary/qml/Checkbox.qml | 24 +++++++++++++ src/mdictionary/qml/DictManagerWidget.qml | 10 +++--- 7 files changed, 162 insertions(+), 34 deletions(-) diff --git a/src/mdictionary/gui/DictManagerModel.cpp b/src/mdictionary/gui/DictManagerModel.cpp index 4714730..ecb93bd 100644 --- a/src/mdictionary/gui/DictManagerModel.cpp +++ b/src/mdictionary/gui/DictManagerModel.cpp @@ -1,8 +1,36 @@ +/******************************************************************************* + + This file is part of mDictionary. + + mDictionary is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + mDictionary is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with mDictionary. If not, see . + + Copyright 2010 Comarch S.A. + +*******************************************************************************/ + +/*! \file DictManagerModel.cpp + \brief Contains dictionaries data for qml UI + + \author Marcin Kaźmierczak +*/ + #include "DictManagerModel.h" DictManagerModel::DictManagerModel(QHash dictionaries, QObject *parent) : QAbstractListModel(parent) { + _currentIndex = 0; QHash roles; roles[NameRole] = "name"; roles[IconPathRole] = "iconPath"; @@ -35,7 +63,7 @@ void DictManagerModel::clear() _dictionaries.clear(); _dictList.clear(); endRemoveRows(); - emit dataChanged(QModelIndex(), QModelIndex()); + Q_EMIT dataChanged(QModelIndex(), QModelIndex()); } QVariant DictManagerModel::data(const QModelIndex & index, int role) const @@ -98,7 +126,7 @@ int DictManagerModel::setDataPriv(int index, const QVariant &value, int role) _dictionaries[dictionary] = value.toBool(); // if (index == _dictList.count()) // emit dataChanged(this->index(index-1), this->index(index)); - emit dataChanged(this->index(0), this->index(_dictList.count() - 1)); + Q_EMIT dataChanged(this->index(0), this->index(_dictList.count() - 1)); return 2; } else @@ -118,6 +146,21 @@ void DictManagerModel::setModelProperty(int index, const QVariant value, QString } +void DictManagerModel::itemSelected(int index) +{ + _currentIndex = index; +} + +CommonDictInterface* DictManagerModel::currentDict() +{ + return _dictList[_currentIndex]; +} + +bool DictManagerModel::isCurrentDictSelected() +{ + return _dictionaries[_dictList[_currentIndex]]; +} + Qt::ItemFlags DictManagerModel::flags(const QModelIndex &index) const { Qt::ItemFlags fl = QAbstractItemModel::flags(index); diff --git a/src/mdictionary/gui/DictManagerModel.h b/src/mdictionary/gui/DictManagerModel.h index 6c599f1..034867f 100644 --- a/src/mdictionary/gui/DictManagerModel.h +++ b/src/mdictionary/gui/DictManagerModel.h @@ -1,3 +1,30 @@ +/******************************************************************************* + + This file is part of mDictionary. + + mDictionary is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + mDictionary is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with mDictionary. If not, see . + + Copyright 2010 Comarch S.A. + +*******************************************************************************/ + +/*! \file DictManagerModel.h + \brief Contains dictionaries data for qml UI + + \author Marcin Kaźmierczak +*/ + #ifndef DICTMANAGERMODEL_H #define DICTMANAGERMODEL_H @@ -23,7 +50,7 @@ public: //! Constructor /*! - \param dictionaries list of dictionaries + \param dictionaries hash set (dictionary, is active) with dictionaries \param parent parent of this class. */ explicit DictManagerModel(QHash dictionaries, QObject *parent = 0); @@ -34,21 +61,48 @@ public: bool setData(const QModelIndex &index, const QVariant &value, int role); Qt::ItemFlags flags(const QModelIndex &index) const; + + //! Replace model data and refresh ui. + /*! + \param dictionaries hash set (dictionary, is active) with dictionaries + */ void setDictionaries(QHash dictionaries); + + //! Get dictionary hash set QHash dictionaries(); + + //! Get dictionary list QList dictList(); + //! Clear model data and refresh UI void clear(); + //! Get current selected dictionary + CommonDictInterface* currentDict(); + //! Get true if current selected dictionary was active. Otherwise return false. + bool isCurrentDictSelected(); public Q_SLOTS: + //! Set value at role in index row of data. + /*! + \param index dictionary position in data list + \param value new value for role + \param role role name + */ void setModelProperty(int index, const QVariant value, QString role); + //! Set index of current selected dictionary + /*! + \param index dictionary position in data list + */ + void itemSelected(int index); Q_SIGNALS: + //! emits when user changed data void itemChanged(); private: QHash _dictionaries; QList _dictList; + int _currentIndex; int setDataPriv(int index, const QVariant &value, int role); void addDictionary(CommonDictInterface* dictionary, bool isActive); diff --git a/src/mdictionary/gui/DictManagerWidget.cpp b/src/mdictionary/gui/DictManagerWidget.cpp index e300a26..86459b7 100644 --- a/src/mdictionary/gui/DictManagerWidget.cpp +++ b/src/mdictionary/gui/DictManagerWidget.cpp @@ -125,24 +125,14 @@ void DictManagerWidget::initalizeUI() { connect(rootObject, SIGNAL(settingsButtonClicked()), this, SLOT(settingsButtonClicked())); - //z modelu sygnał, oraz z okienka zmian ustawień w pluginie, gdy są zmiany -// oryginalnie: -// connect(dictList, SIGNAL(itemChanged(QListWidgetItem*)), -// this, SLOT(changed())); + connect(model, SIGNAL(itemChanged()), - this, SLOT(changed())); - //pozmieniać connecty, to jest na dwuklik mysza na liście, sprawdzić, zrobic alternatywne sloty - connect(rootObject, SIGNAL(itemActivated(int)), - this, SLOT(saveChanges())); - connect(rootObject, SIGNAL(itemActivated(int)), - this, SLOT(settingsButtonClicked())); - -// connect(dictList, SIGNAL(itemActivated(QListWidgetItem*)), -// this, SLOT(saveChanges())); -// connect(dictList, SIGNAL(itemActivated(QListWidgetItem*)), -// this, SLOT(itemSelected(QListWidgetItem*))); -// connect(dictList, SIGNAL(itemActivated(QListWidgetItem*)), -// settingsButton, SIGNAL(clicked())); + this, SLOT(changed())); + connect(rootObject, SIGNAL(itemActivated(int)), + this, SLOT(saveChanges())); + connect(rootObject, SIGNAL(itemActivated(int)), + this, SLOT(settingsButtonClicked())); + #endif #ifdef Q_WS_MAEMO_5 @@ -158,7 +148,6 @@ void DictManagerWidget::initalizeUI() { // setMaximumWidth(sizeHint().width()*2); // setMinimumHeight(sizeHint().height()); // setMaximumHeight(sizeHint().height()*2); - //connect(closeButton, SIGNAL(clicked()), this, SLOT(save())); connect(rootObject, SIGNAL(saveButtonClicked()), this, SLOT(save())); #endif } @@ -237,13 +226,22 @@ void DictManagerWidget::saveChanges() { QMessageBox::question(this, tr("Save"), tr("Do you want to save changes?"), QMessageBox::Save, QMessageBox::Cancel) == QMessageBox::Save) { + QList checkedDicts; + + for(int i=0; icount(); i++) { + QListWidgetItem* item = dictList->item(i); + if(item->checkState() == Qt::Checked) { + checkedDicts.push_back(dictsHash[item]); + } + } #endif QList checkedDicts; - for(int i=0; icount(); i++) { - QListWidgetItem* item = dictList->item(i); - if(item->checkState() == Qt::Checked) { - checkedDicts.push_back(dictsHash[item]); + for(int i=0; idictList().count(); i++) { +// QListWidgetItem* item = dictList->item(i); + CommonDictInterface* item = model->dictList()[i]; + if(model->dictionaries()[item] == true) { + checkedDicts.push_back(item); } } _changed = false; @@ -259,9 +257,11 @@ void DictManagerWidget::hideEvent(QHideEvent *e) { void DictManagerWidget::addNewDictButtonClicked() { #ifndef Q_WS_MAEMO_5 + qDebug()<<"1 "<<_changed; if(!_changed || QMessageBox::question(this, tr("Save"), tr("Do you want to save changes?"), QMessageBox::Save, QMessageBox::Cancel) == QMessageBox::Save) { + qDebug()<<"2"; _save = true; saveChanges(); _save = false; @@ -295,12 +295,16 @@ void DictManagerWidget::removeButtonClicked() { if(QMessageBox::question(this, tr("Remove dictionary"), tr("Do you want to remove selected dictionary?"), QMessageBox::Yes, QMessageBox::No) == QMessageBox::Yes) { - +#ifndef Q_WS_MAEMO_5 + emit removeDictionary(model->currentDict()); + refreshDictsList(); +#else QList selected = dictList->selectedItems(); if(selected.count() > 0) { emit removeDictionary(dictsHash[selected[0]]); refreshDictsList(); } +#endif } } @@ -313,12 +317,15 @@ void DictManagerWidget::settingsButtonClicked() { saveChanges(); _save = false; } - #endif + model->currentDict()->dictDialog()->changeSettings(this->parentWidget()); + refreshDictsList(); + #else QList selected = dictList->selectedItems(); if(selected.count() > 0) { dictsHash[selected[0]]->dictDialog()->changeSettings(this->parentWidget()); } refreshDictsList(); +#endif } diff --git a/src/mdictionary/gui/DictTypeModel.cpp b/src/mdictionary/gui/DictTypeModel.cpp index b2d09b2..aebcc3c 100644 --- a/src/mdictionary/gui/DictTypeModel.cpp +++ b/src/mdictionary/gui/DictTypeModel.cpp @@ -20,7 +20,7 @@ *******************************************************************************/ /*! \file DictTypeModel.cpp - \brief Implements plugin data for list model + \brief Contains plugins data for qml UI \author Marcin Kaźmierczak */ diff --git a/src/mdictionary/gui/DictTypeModel.h b/src/mdictionary/gui/DictTypeModel.h index 3a35e91..fa1ae2c 100644 --- a/src/mdictionary/gui/DictTypeModel.h +++ b/src/mdictionary/gui/DictTypeModel.h @@ -20,7 +20,7 @@ *******************************************************************************/ /*! \file DictTypeModel.h - \brief Implements plugin data for list model + \brief Contains plugins data for qml UI \author Marcin Kaźmierczak */ diff --git a/src/mdictionary/qml/Checkbox.qml b/src/mdictionary/qml/Checkbox.qml index 1af756f..c1a0ea7 100644 --- a/src/mdictionary/qml/Checkbox.qml +++ b/src/mdictionary/qml/Checkbox.qml @@ -1,3 +1,27 @@ +/******************************************************************************* + + This file is part of mDictionary. + + mDictionary is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + mDictionary is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with mDictionary. If not, see . + + Copyright 2010 Comarch S.A. + +*******************************************************************************/ +/*! + author: Marcin Kaźmierczak +*/ + import Qt 4.7 Image { diff --git a/src/mdictionary/qml/DictManagerWidget.qml b/src/mdictionary/qml/DictManagerWidget.qml index 7cb44f3..df43918 100644 --- a/src/mdictionary/qml/DictManagerWidget.qml +++ b/src/mdictionary/qml/DictManagerWidget.qml @@ -67,10 +67,10 @@ Rectangle { MouseArea{ anchors.fill: parent onClicked: { - console.log("aaaaa") dictList.currentIndex = number rectangle1.setEnableRemove(true) rectangle1.setEnableSettings(true) + dictModel.itemSelected(dictList.currentIndex) } onDoubleClicked: { rectangle1.itemActivated(dictList.currentIndex) @@ -129,7 +129,7 @@ Rectangle { anchors.leftMargin: 4 anchors.verticalCenter: parent.verticalCenter textInButton: qsTr("Add") - onClicked: rectangle1.addButtonClicked + onClicked: addButtonClicked(); } Button { @@ -141,7 +141,7 @@ Rectangle { anchors.verticalCenter: parent.verticalCenter textInButton: qsTr("Remove") enabled: false - onClicked: rectangle1.removeButtonClicked + onClicked: removeButtonClicked(); } Button { @@ -153,7 +153,7 @@ Rectangle { anchors.verticalCenter: parent.verticalCenter textInButton: qsTr("Settings") enabled: false - onClicked: rectangle1.settingsButtonClicked + onClicked: settingsButtonClicked(); } Button { @@ -166,7 +166,7 @@ Rectangle { anchors.rightMargin: 4 anchors.verticalCenter: parent.verticalCenter textInButton: qsTr("Save") - onClicked: rectangle1.saveButtonClicked + onClicked: saveButtonClicked() } } -- 1.7.9.5