/*
* Project: MoleCuilder
* Description: creates and alters molecular systems
* Copyright (C) 2013 Frederik Heber. All rights reserved.
*
*
* This file is part of MoleCuilder.
*
* MoleCuilder 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 2 of the License, or
* (at your option) any later version.
*
* MoleCuilder 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 MoleCuilder. If not, see .
*/
/*
* QtFragmentList.cpp
*
* Created on: Sep 03, 2013
* Author: heber
*/
// include config.h
#ifdef HAVE_CONFIG_H
#include
#endif
#include "Views/Qt4/QtFragmentList.hpp"
#include "Views/Qt4/QtNumericalItem.hpp"
#include
#include
#include
#include
#include "CodePatterns/MemDebug.hpp"
#include
#include
#include
#include "CodePatterns/Log.hpp"
#include "Descriptors/AtomIdDescriptor.hpp"
#include "Formula.hpp"
#include "Fragmentation/KeySetsContainer.hpp"
#include "Fragmentation/Summation/IndexSetContainer.hpp"
#include "Fragmentation/Summation/Containers/FragmentationResultContainer.hpp"
#include "Fragmentation/Summation/Containers/MPQCData.hpp"
#include "World.hpp"
using namespace std;
using namespace boost::assign;
const int QtFragmentList::COLUMNCOUNT = COLUMNTYPES_MAX;
const char *QtFragmentList::COLUMNNAMES[QtFragmentList::COLUMNCOUNT]={"Number","KeySet","Formula","Energy value","Energy contribution"};
QtFragmentList::QtFragmentList(QWidget * _parent) :
QTreeWidget (_parent),
Observer("QtFragmentList")
{
setColumnCount(COLUMNCOUNT);
setSortingEnabled(true);
QStringList header;
for(int i=0; i lock(flag_mutex);
dirty = true;
}
void QtFragmentList::refill()
{
boost::unique_lock lock(flag_mutex);
FragmentationResultContainer &fragments =
FragmentationResultContainer::getInstance();
// clear everything
FragmentSelection.clear();
indexsets.clear();
clear();
size_t count = 0;
const IndexSetContainer keysets(fragments.getKeySets());
const FragmentationResultContainer::shortrangedata_t &shortrange = fragments.getShortRangeResults();
const FragmentationShortRangeResults::summedshortrange_t &summedshortrange = fragments.getShortRangeSummedResults();
IndexSetContainer::Container_t::const_iterator keyiter = keysets.getContainer().begin();
FragmentationResultContainer::shortrangedata_t::const_iterator resultiter = shortrange.begin();
for (;(keyiter != keysets.getContainer().end()) && (resultiter != shortrange.end());
++keyiter,++resultiter,++count) {
std::vector numerical_columns;
numerical_columns += ENERGYVALUE, ENERGYCONTRIBUTION;
QTreeWidgetItem *treeItem = new QtNumericalItem(NUMBER, numerical_columns, this);
treeItem->setText(NUMBER, QString::number(count));
{
std::stringstream output;
output << **keyiter;
treeItem->setText(KEYSET, QString(output.str().c_str()));
}
{
std::stringstream output;
Formula formula;
for (IndexSet::const_iterator indexiter = (*keyiter)->begin();
indexiter != (*keyiter)->end();
++indexiter) {
const atom * const _atom = const_cast(World::getInstance()).
getAtom(AtomById(*indexiter));
if (_atom != NULL)
formula.addElements(_atom->getElementNo(), 1);
else
ELOG(2, "QtFragmentList::refill() - Could not find id " << *indexiter << " for formula.");
}
output << formula.toString();
treeItem->setText(FORMULA, QString(output.str().c_str()));
}
if (summedshortrange.empty()) {
{
std::stringstream output;
output << resultiter->second.energies.total;
treeItem->setText(ENERGYVALUE, QString(output.str().c_str()));
}
{
std::stringstream output;
output << "";
treeItem->setText(ENERGYCONTRIBUTION, QString(output.str().c_str()));
}
} else {
FragmentationShortRangeResults::summedshortrange_t::const_iterator sumresiter =
summedshortrange.find(*keyiter);
ASSERT( sumresiter != summedshortrange.end(),
"QtFragmentList::refill() - "+toString(*keyiter)+" not present in summed results.");
{
std::stringstream output;
output << sumresiter->second.first.energies.total;
treeItem->setText(ENERGYVALUE, QString(output.str().c_str()));
}
{
std::stringstream output;
output << sumresiter->second.second.energies.total;
treeItem->setText(ENERGYCONTRIBUTION, QString(output.str().c_str()));
}
}
FragmentSelection.push_back(treeItem->isSelected());
indexsets.push_back( **keyiter );
}
dirty = false;
}
void QtFragmentList::paintEvent(QPaintEvent * event)
{
if (dirty)
refill();
QTreeWidget::paintEvent(event);
}
void QtFragmentList::subjectKilled(Observable *publisher)
{
// as a new instance should always already be present ... just sign on
FragmentationResultContainer &fragments =
FragmentationResultContainer::getInstance();
fragments.signOn(this);
}
void QtFragmentList::rowSelected()
{
//std::cout << "rowSelected\n";
// unselect
for (int i=0;iisSelected();
const int itemno = boost::lexical_cast(item->text(NUMBER).toStdString());
if (newSelection != FragmentSelection[itemno]){
// LOG(1, "INFO: selection changed for item #" << itemno);
// get the keyset and select the specific atoms
if (!newSelection) {
// LOG(2, "INFO: Seeing unselection for item #" << itemno);
for (IndexSet::const_iterator iter = indexsets[itemno].begin();
iter != indexsets[itemno].end();
++iter)
World::getInstance().unselectAtom(*iter);
}
}
}
// select all
for (int i=0;iisSelected();
const int itemno = boost::lexical_cast(item->text(NUMBER).toStdString());
if (newSelection != FragmentSelection[itemno]){
FragmentSelection[itemno] = newSelection;
// get the keyset and select the specific atoms
if (newSelection) {
// LOG(2, "INFO: Seeing selection for item #" << itemno);
for (IndexSet::const_iterator iter = indexsets[itemno].begin();
iter != indexsets[itemno].end();
++iter)
World::getInstance().selectAtom(*iter);
}
}
}
}