1 /*******************************************************************************
3 This file is part of mDictionary.
5 mDictionary is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
10 mDictionary is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with mDictionary. If not, see <http://www.gnu.org/licenses/>.
18 Copyright 2010 Comarch S.A.
20 *******************************************************************************/
22 //Created by Mateusz Półrola
24 #include "XdxfDictSelectDialog.h"
26 XdxfDictSelectDialog::XdxfDictSelectDialog(QList<DownloadDict> dicts,
30 layout = new QVBoxLayout;
33 checkBoxLayout = new QHBoxLayout;
34 layout->addLayout(checkBoxLayout);
36 langFrom = new QComboBox;
37 langTo = new QComboBox;
39 langFrom->setInsertPolicy(QComboBox::InsertAlphabetically);
40 langTo->setInsertPolicy(QComboBox::InsertAlphabetically);
42 checkBoxLayout->addWidget(langFrom);
43 checkBoxLayout->addWidget(langTo);
45 model = new DictsModel(dicts, this);
47 proxyModel = new DictsProxyModel;
48 proxyModel->setDynamicSortFilter(true);
49 proxyModel->setSourceModel(model);
52 treeView = new QTreeView;
53 treeView->setModel(proxyModel);
54 treeView->setRootIsDecorated(false);
55 treeView->setExpandsOnDoubleClick(false);
57 treeView->setSortingEnabled(true);
58 // treeView->sortByColumn(0);
60 layout->addWidget(treeView);
63 connect(langFrom, SIGNAL(currentIndexChanged(int)),
64 this, SLOT(refreshDictList()));
66 connect(langTo, SIGNAL(currentIndexChanged(int)),
67 this, SLOT(refreshDictList()));
69 connect(treeView, SIGNAL(activated(QModelIndex)),
70 this, SLOT(itemClicked(QModelIndex)));
73 setMinimumSize(400,200);
75 setMinimumHeight(350);
82 void XdxfDictSelectDialog::initializeDicts() {
84 QSet<QString> languagesFrom;
85 QSet<QString> languagesTo;
87 for(int i=0; i < model->rowCount(QModelIndex()); i++) {
89 model->data(model->index(i, 0, QModelIndex())).toString());
91 model->data(model->index(i, 1, QModelIndex())).toString());
94 languagesFrom.remove(QString());
95 languagesTo.remove(QString());
97 QList<QString> langFromList = languagesFrom.toList();
100 QList<QString> langToList = languagesTo.toList();
103 langFrom->addItem(tr("Any"));
104 for(int i=0; i < langFromList.count(); i++) {
105 langFrom->addItem(langFromList.at(i));
108 langTo->addItem(tr("Any"));
109 for(int i=0; i < langToList.count(); i++) {
110 langTo->addItem(langToList.at(i));
114 void XdxfDictSelectDialog::refreshDictList() {
115 if(langTo->currentIndex() == 0)
116 proxyModel->setTo(QString());
118 proxyModel->setTo(langTo->currentText());
120 if(langFrom->currentIndex() == 0)
121 proxyModel->setFrom(QString());
123 proxyModel->setFrom(langFrom->currentText());
126 void XdxfDictSelectDialog::itemClicked(QModelIndex index) {
127 _link = index.model()->data(index, Qt::UserRole);