+/*******************************************************************************
+
+ 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 <http://www.gnu.org/licenses/>.
+
+ Copyright 2010 Comarch S.A.
+
+*******************************************************************************/
+
+/*! \file DictManagerModel.cpp
+ \brief Contains dictionaries data for qml UI
+
+ \author Marcin Kaźmierczak <marcin.kazmierczak@comarch.pl>
+*/
+
#include "DictManagerModel.h"
DictManagerModel::DictManagerModel(QHash<CommonDictInterface *, bool> dictionaries, QObject *parent) :
QAbstractListModel(parent)
{
+ _currentIndex = 0;
QHash<int, QByteArray> roles;
roles[NameRole] = "name";
roles[IconPathRole] = "iconPath";
_dictionaries.clear();
_dictList.clear();
endRemoveRows();
- emit dataChanged(QModelIndex(), QModelIndex());
+ Q_EMIT dataChanged(QModelIndex(), QModelIndex());
}
QVariant DictManagerModel::data(const QModelIndex & index, int role) const
_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
}
+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);
+/*******************************************************************************
+
+ 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 <http://www.gnu.org/licenses/>.
+
+ Copyright 2010 Comarch S.A.
+
+*******************************************************************************/
+
+/*! \file DictManagerModel.h
+ \brief Contains dictionaries data for qml UI
+
+ \author Marcin Kaźmierczak <marcin.kazmierczak@comarch.pl>
+*/
+
#ifndef DICTMANAGERMODEL_H
#define DICTMANAGERMODEL_H
//! Constructor
/*!
- \param dictionaries list of dictionaries
+ \param dictionaries hash set (dictionary, is active) with dictionaries
\param parent parent of this class.
*/
explicit DictManagerModel(QHash<CommonDictInterface*, bool> dictionaries, QObject *parent = 0);
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<CommonDictInterface*, bool> dictionaries);
+
+ //! Get dictionary hash set
QHash<CommonDictInterface*, bool> dictionaries();
+
+ //! Get dictionary list
QList<CommonDictInterface*> 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<CommonDictInterface*, bool> _dictionaries;
QList<CommonDictInterface*> _dictList;
+ int _currentIndex;
int setDataPriv(int index, const QVariant &value, int role);
void addDictionary(CommonDictInterface* dictionary, bool isActive);
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
// 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
}
QMessageBox::question(this, tr("Save"),
tr("Do you want to save changes?"),
QMessageBox::Save, QMessageBox::Cancel) == QMessageBox::Save) {
+ QList<CommonDictInterface*> checkedDicts;
+
+ for(int i=0; i<dictList->count(); i++) {
+ QListWidgetItem* item = dictList->item(i);
+ if(item->checkState() == Qt::Checked) {
+ checkedDicts.push_back(dictsHash[item]);
+ }
+ }
#endif
QList<CommonDictInterface*> checkedDicts;
- for(int i=0; i<dictList->count(); i++) {
- QListWidgetItem* item = dictList->item(i);
- if(item->checkState() == Qt::Checked) {
- checkedDicts.push_back(dictsHash[item]);
+ for(int i=0; i<model->dictList().count(); i++) {
+// QListWidgetItem* item = dictList->item(i);
+ CommonDictInterface* item = model->dictList()[i];
+ if(model->dictionaries()[item] == true) {
+ checkedDicts.push_back(item);
}
}
_changed = false;
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;
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<QListWidgetItem*> selected = dictList->selectedItems();
if(selected.count() > 0) {
emit removeDictionary(dictsHash[selected[0]]);
refreshDictsList();
}
+#endif
}
}
saveChanges();
_save = false;
}
- #endif
+ model->currentDict()->dictDialog()->changeSettings(this->parentWidget());
+ refreshDictsList();
+ #else
QList<QListWidgetItem*> selected = dictList->selectedItems();
if(selected.count() > 0) {
dictsHash[selected[0]]->dictDialog()->changeSettings(this->parentWidget());
}
refreshDictsList();
+#endif
}
*******************************************************************************/
/*! \file DictTypeModel.cpp
- \brief Implements plugin data for list model
+ \brief Contains plugins data for qml UI
\author Marcin Kaźmierczak <marcin.kazmierczak@comarch.pl>
*/
*******************************************************************************/
/*! \file DictTypeModel.h
- \brief Implements plugin data for list model
+ \brief Contains plugins data for qml UI
\author Marcin Kaźmierczak <marcin.kazmierczak@comarch.pl>
*/
+/*******************************************************************************
+
+ 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 <http://www.gnu.org/licenses/>.
+
+ Copyright 2010 Comarch S.A.
+
+*******************************************************************************/
+/*!
+ author: Marcin Kaźmierczak <marcin.kazmierczak@comarch.pl>
+*/
+
import Qt 4.7
Image {
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)
anchors.leftMargin: 4
anchors.verticalCenter: parent.verticalCenter
textInButton: qsTr("Add")
- onClicked: rectangle1.addButtonClicked
+ onClicked: addButtonClicked();
}
Button {
anchors.verticalCenter: parent.verticalCenter
textInButton: qsTr("Remove")
enabled: false
- onClicked: rectangle1.removeButtonClicked
+ onClicked: removeButtonClicked();
}
Button {
anchors.verticalCenter: parent.verticalCenter
textInButton: qsTr("Settings")
enabled: false
- onClicked: rectangle1.settingsButtonClicked
+ onClicked: settingsButtonClicked();
}
Button {
anchors.rightMargin: 4
anchors.verticalCenter: parent.verticalCenter
textInButton: qsTr("Save")
- onClicked: rectangle1.saveButtonClicked
+ onClicked: saveButtonClicked()
}
}