• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdesdk API Reference
  • KDE Home
  • Contact Us
 

lokalize

  • sources
  • kde-4.14
  • kdesdk
  • lokalize
  • src
phaseswindow.cpp
Go to the documentation of this file.
1 /* ****************************************************************************
2  This file is part of Lokalize
3 
4  Copyright (C) 2009 by Nick Shaforostoff <shafff@ukr.net>
5 
6  This program is free software; you can redistribute it and/or
7  modify it under the terms of the GNU General Public License as
8  published by the Free Software Foundation; either version 2 of
9  the License or (at your option) version 3 or any later version
10  accepted by the membership of KDE e.V. (or its successor approved
11  by the membership of KDE e.V.), which shall act as a proxy
12  defined in Section 14 of version 3 of the license.
13 
14  This program is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  GNU General Public License for more details.
18 
19  You should have received a copy of the GNU General Public License
20  along with this program. If not, see <http://www.gnu.org/licenses/>.
21 
22 **************************************************************************** */
23 
24 #include "phaseswindow.h"
25 #include "catalog.h"
26 #include "cmd.h"
27 #include "noteeditor.h"
28 
29 #include <klocale.h>
30 #include <KPushButton>
31 #include <KTextBrowser>
32 #include <KComboBox>
33 
34 #include <QTreeView>
35 #include <QStringListModel>
36 #include <QVBoxLayout>
37 #include <QFormLayout>
38 #include <QApplication>
39 
40 
41 //BEGIN PhasesModel
42 #include <QAbstractListModel>
43 #include <QSplitter>
44 #include <QStackedLayout>
45 
46 class PhasesModel: public QAbstractListModel
47 {
48 public:
49  enum PhasesModelColumns
50  {
51  Date=0,
52  Process,
53  Company,
54  Contact,
55  ToolName,
56  ColumnCount
57  };
58 
59  PhasesModel(Catalog* catalog, QObject* parent);
60  ~PhasesModel(){}
61  QModelIndex addPhase(const Phase& phase);
62  QModelIndex activePhaseIndex()const{return index(m_activePhase);}
63  QList<Phase> addedPhases()const;
64 
65  int rowCount(const QModelIndex& parent=QModelIndex()) const;
66  int columnCount(const QModelIndex& parent=QModelIndex()) const{Q_UNUSED(parent); return ColumnCount;}
67  QVariant data(const QModelIndex&,int role=Qt::DisplayRole) const;
68  QVariant headerData(int section, Qt::Orientation, int role=Qt::DisplayRole) const;
69 
70 
71 private:
72  Catalog* m_catalog;
73  QList<Phase> m_phases;
74  QMap<QString,Tool> m_tools;
75  int m_activePhase;
76 };
77 
78 PhasesModel::PhasesModel(Catalog* catalog, QObject* parent)
79  : QAbstractListModel(parent)
80  , m_catalog(catalog)
81  , m_phases(catalog->allPhases())
82  , m_tools(catalog->allTools())
83 {
84  m_activePhase=m_phases.size();
85  while (--m_activePhase>=0 && m_phases.at(m_activePhase).name!=catalog->activePhase())
86  ;
87 }
88 
89 QModelIndex PhasesModel::addPhase(const Phase& phase)
90 {
91  m_activePhase=m_phases.size();
92  beginInsertRows(QModelIndex(),m_activePhase,m_activePhase);
93  m_phases.append(phase);
94  endInsertRows();
95  return index(m_activePhase);
96 }
97 
98 QList<Phase> PhasesModel::addedPhases()const
99 {
100  QList<Phase> result;
101  for (int i=m_catalog->allPhases().size();i<m_phases.size();++i)
102  result.append(m_phases.at(i));
103 
104  return result;
105 }
106 
107 int PhasesModel::rowCount(const QModelIndex& parent) const
108 {
109  if (parent.isValid())
110  return 0;
111  return m_phases.size();
112 }
113 
114 QVariant PhasesModel::data(const QModelIndex& index, int role) const
115 {
116  if (role==Qt::FontRole && index.row()==m_activePhase)
117  {
118  QFont font=QApplication::font();
119  font.setBold(true);
120  return font;
121  }
122  if (role==Qt::UserRole)
123  return m_phases.at(index.row()).name;
124  if (role!=Qt::DisplayRole)
125  return QVariant();
126 
127  const Phase& phase=m_phases.at(index.row());
128  switch (index.column())
129  {
130  case Date: return phase.date.toString();
131  case Process: return phase.process;
132  case Company: return phase.company;
133  case Contact: return QString(phase.contact
134  +(phase.email.isEmpty()?"":QString(" <%1> ").arg(phase.email))
135  +(phase.phone.isEmpty()?"":QString(", %1").arg(phase.phone)));
136  case ToolName: return m_tools.value(phase.tool).name;
137  }
138  return QVariant();
139 }
140 
141 QVariant PhasesModel::headerData(int section, Qt::Orientation, int role) const
142 {
143  if (role!=Qt::DisplayRole)
144  return QVariant();
145 
146  switch (section)
147  {
148  case Date: return i18nc("@title:column","Date");
149  case Process: return i18nc("@title:column","Process");
150  case Company: return i18nc("@title:column","Company");
151  case Contact: return i18nc("@title:column","Person");
152  case ToolName: return i18nc("@title:column","Tool");
153  }
154  return QVariant();
155 }
156 //END PhasesModel
157 
158 
159 //BEGIN PhaseEditDialog
160 class PhaseEditDialog: public KDialog
161 {
162 public:
163  PhaseEditDialog(QWidget *parent);
164  ~PhaseEditDialog(){}
165 
166  Phase phase()const;
167 private:
168  KComboBox* m_process;
169 };
170 
171 
172 PhaseEditDialog::PhaseEditDialog(QWidget *parent)
173  : KDialog(parent)
174  , m_process(new KComboBox(this))
175 {
176  QStringList processes;
177  processes<<i18n("Translation")<<i18n("Review")<<i18n("Approval");
178  m_process->setModel(new QStringListModel(processes,this));
179 
180  QFormLayout* l=new QFormLayout(mainWidget());
181  l->addRow(i18n("Process"), m_process);
182 }
183 
184 Phase PhaseEditDialog::phase() const
185 {
186  Phase phase;
187  phase.process=processes()[m_process->currentIndex()];
188  return phase;
189 }
190 
191 PhasesWindow::PhasesWindow(Catalog* catalog, QWidget *parent)
192  : KDialog(parent)
193  , m_catalog(catalog)
194  , m_model(new PhasesModel(catalog, this))
195  , m_view(new MyTreeView(this))
196  , m_browser(new KTextBrowser(this))
197  , m_editor(0)
198 {
199  connect(this, SIGNAL(accepted()), SLOT(handleResult()));
200  //setAttribute(Qt::WA_DeleteOnClose, true);
201  QVBoxLayout* l=new QVBoxLayout(mainWidget());
202  QHBoxLayout* btns=new QHBoxLayout;
203  l->addLayout(btns);
204 
205  KPushButton* add=new KPushButton(KStandardGuiItem::add(),this);
206  connect(add, SIGNAL(clicked()),this,SLOT(addPhase()));
207  btns->addWidget(add);
208  btns->addStretch(5);
209 /*
210  KPushButton* add=new KPushButton(i18nc("@action:button",""),this);
211  btns->addWidget(activate);
212 */
213  QSplitter* splitter=new QSplitter(this);
214  l->addWidget(splitter);
215 
216  m_view->setRootIsDecorated(false);
217  m_view->setModel(m_model);
218  splitter->addWidget(m_view);
219  int column=m_model->columnCount();
220  while (--column>=0)
221  m_view->resizeColumnToContents(column);
222  if (m_model->rowCount())
223  m_view->setCurrentIndex(m_model->activePhaseIndex());
224  connect(m_view, SIGNAL(currentIndexChanged(QModelIndex)), SLOT(displayPhaseNotes(QModelIndex)));
225 
226 
227  m_noteView=new QWidget(this);
228  m_noteView->hide();
229  splitter->addWidget(m_noteView);
230  m_stackedLayout = new QStackedLayout(m_noteView);
231  m_stackedLayout->addWidget(m_browser);
232 
233  m_browser->viewport()->setBackgroundRole(QPalette::Background);
234  m_browser->setOpenLinks(false);
235  connect(m_browser,SIGNAL(anchorClicked(QUrl)),this,SLOT(anchorClicked(QUrl)));
236 
237  splitter->setStretchFactor(0,15);
238  splitter->setStretchFactor(1,5);
239  setInitialSize(QSize(700,400));
240 }
241 
242 void PhasesWindow::handleResult()
243 {
244  m_catalog->beginMacro(i18nc("@item Undo action item", "Edit phases"));
245 
246  Phase last;
247  foreach(const Phase& phase, m_model->addedPhases())
248  static_cast<QUndoStack*>(m_catalog)->push(new UpdatePhaseCmd(m_catalog, last=phase));
249  m_catalog->setActivePhase(last.name,roleForProcess(last.process));
250 
251  QMapIterator<QString, QVector<Note> > i(m_phaseNotes);
252  while (i.hasNext())
253  {
254  i.next();
255  m_catalog->setPhaseNotes(i.key(),i.value());
256  }
257 
258  m_catalog->endMacro();
259 }
260 
261 void PhasesWindow::addPhase()
262 {
263  PhaseEditDialog d(this);
264  if (!d.exec())
265  return;
266 
267  Phase phase=d.phase();
268  initPhaseForCatalog(m_catalog, phase, ForceAdd);
269  m_view->setCurrentIndex(m_model->addPhase(phase));
270  m_phaseNotes.insert(phase.name, QVector<Note>());
271 }
272 
273 static QString phaseNameFromView(QTreeView* view)
274 {
275  return view->currentIndex().data(Qt::UserRole).toString();
276 }
277 
278 void PhasesWindow::anchorClicked(QUrl link)
279 {
280  QString path=link.path().mid(1);// minus '/'
281 
282  if (link.scheme()=="note")
283  {
284  if (!m_editor)
285  {
286  m_editor=new NoteEditor(this);
287  m_stackedLayout->addWidget(m_editor);
288  connect(m_editor,SIGNAL(accepted()),this,SLOT(noteEditAccepted()));
289  connect(m_editor,SIGNAL(rejected()),this,SLOT(noteEditRejected()));
290  }
291  m_editor->setNoteAuthors(m_catalog->noteAuthors());
292  if (path.endsWith("add"))
293  m_editor->setNote(Note(),-1);
294  else
295  {
296  int pos=path.toInt();
297  QString phaseName=phaseNameFromView(m_view);
298  QVector<Note> notes=m_phaseNotes.contains(phaseName)?
299  m_phaseNotes.value(phaseName)
300  :m_catalog->phaseNotes(phaseName);
301  m_editor->setNote(notes.at(pos),pos);
302  }
303  m_stackedLayout->setCurrentIndex(1);
304  }
305 }
306 
307 void PhasesWindow::noteEditAccepted()
308 {
309  QString phaseName=phaseNameFromView(m_view);
310  if (!m_phaseNotes.contains(phaseName))
311  m_phaseNotes.insert(phaseName, m_catalog->phaseNotes(phaseName));
312 
313  QVector<Note> notes=m_phaseNotes.value(phaseName);
314  if (m_editor->noteIndex()==-1)
315  m_phaseNotes[phaseName].append(m_editor->note());
316  else
317  m_phaseNotes[phaseName][m_editor->noteIndex()]=m_editor->note();
318 
319  m_stackedLayout->setCurrentIndex(0);
320  displayPhaseNotes(m_view->currentIndex());
321 }
322 
323 void PhasesWindow::noteEditRejected()
324 {
325  m_stackedLayout->setCurrentIndex(0);
326 }
327 
328 void PhasesWindow::displayPhaseNotes(const QModelIndex& current)
329 {
330  m_browser->clear();
331  QString phaseName=current.data(Qt::UserRole).toString();
332  QVector<Note> notes=m_phaseNotes.contains(phaseName)?
333  m_phaseNotes.value(phaseName)
334  :m_catalog->phaseNotes(phaseName);
335  kWarning()<<notes.size();
336  displayNotes(m_browser, notes);
337  m_noteView->show();
338  m_stackedLayout->setCurrentIndex(0);
339 }
340 
Phase::company
QString company
Definition: phase.h:38
QModelIndex
QWidget
QAbstractItemModel::rowCount
virtual int rowCount(const QModelIndex &parent) const =0
phaseNameFromView
static QString phaseNameFromView(QTreeView *view)
Definition: phaseswindow.cpp:273
QMap::contains
bool contains(const Key &key) const
QAbstractItemView::setCurrentIndex
void setCurrentIndex(const QModelIndex &index)
QDate::toString
QString toString(Qt::DateFormat format) const
Phase::contact
QString contact
Definition: phase.h:40
QSplitter::setStretchFactor
void setStretchFactor(int index, int stretch)
QUndoStack::beginMacro
void beginMacro(const QString &text)
QFont
Phase::phone
QString phone
Definition: phase.h:42
QMap< QString, Tool >
Catalog::phaseNotes
QVector< Note > phaseNotes(const QString &phase) const
Definition: catalog.cpp:390
roleForProcess
ProjectLocal::PersonRole roleForProcess(const QString &process)
Definition: phase.cpp:39
Note
Definition: note.h:29
QHBoxLayout
cmd.h
Catalog::setActivePhase
void setActivePhase(const QString &phase, ProjectLocal::PersonRole role=ProjectLocal::Approver)
Definition: catalog.cpp:339
Catalog::activePhase
QString activePhase() const
Definition: catalog.h:119
QList::size
int size() const
QSplitter::addWidget
void addWidget(QWidget *widget)
initPhaseForCatalog
bool initPhaseForCatalog(Catalog *catalog, Phase &phase, int options)
Definition: phase.cpp:62
QFont::setBold
void setBold(bool enable)
QModelIndex::isValid
bool isValid() const
QBoxLayout::addWidget
void addWidget(QWidget *widget, int stretch, QFlags< Qt::AlignmentFlag > alignment)
QApplication::font
QFont font()
QList::append
void append(const T &value)
QMapIterator
Phase::date
QDate date
Definition: phase.h:39
Phase::name
QString name
Definition: phase.h:36
PhasesWindow::PhasesWindow
PhasesWindow(Catalog *catalog, QWidget *parent)
Definition: phaseswindow.cpp:191
QTreeView::resizeColumnToContents
void resizeColumnToContents(int column)
Phase::email
QString email
Definition: phase.h:41
QObject
catalog.h
QAbstractListModel::index
virtual QModelIndex index(int row, int column, const QModelIndex &parent) const
QAbstractListModel
QString::toInt
int toInt(bool *ok, int base) const
Catalog::noteAuthors
QStringList noteAuthors() const
Definition: catalog.cpp:252
QString::isEmpty
bool isEmpty() const
QModelIndex::row
int row() const
processes
const char *const * processes()
Definition: phase.cpp:32
QUrl::path
QString path() const
QVBoxLayout
QString::endsWith
bool endsWith(const QString &s, Qt::CaseSensitivity cs) const
NoteEditor
Definition: noteeditor.h:39
QAbstractItemModel::data
virtual QVariant data(const QModelIndex &index, int role) const =0
Catalog::setPhaseNotes
QVector< Note > setPhaseNotes(const QString &phase, QVector< Note >)
Definition: catalog.cpp:395
QString
QList< Phase >
QWidget::hide
void hide()
Phase
Definition: phase.h:34
QStackedLayout::setCurrentIndex
void setCurrentIndex(int index)
QUrl::scheme
QString scheme() const
QFormLayout::addRow
void addRow(QWidget *label, QWidget *field)
QStringListModel
QStringList
QAbstractItemModel::headerData
virtual QVariant headerData(int section, Qt::Orientation orientation, int role) const
MyTreeView
Definition: phaseswindow.h:71
QSize
QUrl
KTextBrowser
displayNotes
int displayNotes(KTextBrowser *browser, const QVector< Note > &notes, int active, bool multiple)
Definition: noteeditor.cpp:124
QVector::at
const T & at(int i) const
QSplitter
QString::mid
QString mid(int position, int n) const
QVector
QModelIndex::data
QVariant data(int role) const
QTreeView
QBoxLayout::addStretch
void addStretch(int stretch)
QUndoStack::endMacro
void endMacro()
Phase::tool
QString tool
Definition: phase.h:43
QStackedLayout
QTreeView::setModel
virtual void setModel(QAbstractItemModel *model)
NoteEditor::setNoteAuthors
void setNoteAuthors(const QStringList &)
Definition: noteeditor.cpp:117
QAbstractItemModel::columnCount
virtual int columnCount(const QModelIndex &parent) const =0
QModelIndex::column
int column() const
Phase::process
QString process
Definition: phase.h:37
NoteEditor::note
Note note()
Definition: noteeditor.cpp:99
Catalog
This class represents a catalog It uses CatalogStorage interface to work with catalogs in different f...
Definition: catalog.h:74
NoteEditor::noteIndex
int noteIndex()
Definition: noteeditor.h:48
QMap::insert
iterator insert(const Key &key, const T &value)
QWidget::show
void show()
QAbstractItemView::currentIndex
QModelIndex currentIndex() const
QTreeView::setRootIsDecorated
void setRootIsDecorated(bool show)
QStackedLayout::addWidget
int addWidget(QWidget *widget)
NoteEditor::setNote
void setNote(const Note &, int idx)
Definition: noteeditor.cpp:106
noteeditor.h
QVector::size
int size() const
QString::arg
QString arg(qlonglong a, int fieldWidth, int base, const QChar &fillChar) const
QVariant::toString
QString toString() const
UpdatePhaseCmd
Add or remove (if content is empty) a phase.
Definition: cmd.h:180
QBoxLayout::addLayout
void addLayout(QLayout *layout, int stretch)
QFormLayout
QMap::value
const T value(const Key &key) const
phaseswindow.h
ForceAdd
Definition: phase.h:78
QVariant
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:40:07 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

lokalize

Skip menu "lokalize"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members

kdesdk API Reference

Skip menu "kdesdk API Reference"
  • kapptemplate
  • kcachegrind
  • kompare
  • lokalize
  • umbrello
  •   umbrello

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal