Translations has been fixed

This commit is contained in:
Arin Alexander 2019-07-24 03:13:23 +03:00
parent c498d96862
commit 1a10fc496e
16 changed files with 140 additions and 42 deletions

View File

@ -127,7 +127,7 @@ RCC_DIR = $${ARCH_DIR}/$${BUILD_TYPE}/rcc
LIMEREPORT_VERSION_MAJOR = 1
LIMEREPORT_VERSION_MINOR = 5
LIMEREPORT_VERSION_RELEASE = 2
LIMEREPORT_VERSION_RELEASE = 3
LIMEREPORT_VERSION = '$${LIMEREPORT_VERSION_MAJOR}.$${LIMEREPORT_VERSION_MINOR}.$${LIMEREPORT_VERSION_RELEASE}'
DEFINES *= LIMEREPORT_VERSION_STR=\\\"$${LIMEREPORT_VERSION}\\\"

View File

@ -500,7 +500,7 @@ void BaseDesignIntf::hoverLeaveEvent(QGraphicsSceneHoverEvent *)
update();
}
void BaseDesignIntf::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
void BaseDesignIntf::hoverEnterEvent(QGraphicsSceneHoverEvent /**event*/)
{
m_hovered = true;
update();

View File

@ -320,7 +320,7 @@ protected:
void mousePressEvent(QGraphicsSceneMouseEvent* event);
void hoverMoveEvent(QGraphicsSceneHoverEvent* event);
void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
void hoverEnterEvent(QGraphicsSceneHoverEvent);
void mouseMoveEvent(QGraphicsSceneMouseEvent* event);
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event);

View File

@ -176,7 +176,7 @@ public:
bool isOwned() const {return true;}
bool isEditable() const {return true;}
bool isRemovable() const {return true;}
void invalidate(IDataSource::DatasourceMode mode, bool /*dbWillBeClosed*/){ updateModel();}
void invalidate(IDataSource::DatasourceMode /*mode*/, bool /*dbWillBeClosed*/){ updateModel();}
void update(){ updateModel(); }
void clearErrors(){}
private:

View File

@ -816,6 +816,7 @@ void PageDesignIntf::slotItemPropertyObjectNameChanged(const QString &oldName, c
if (oldName.compare(newName)!=0 && !m_executingCommand){
CommandIf::Ptr command = PropertyObjectNameChangedCommand::create(this, oldName, newName);
saveCommand(command, false);
emit itemPropertyObjectNameChanged(oldName, newName);
}
}

View File

@ -218,6 +218,7 @@ namespace LimeReport {
const QString& propertyName,
const QVariant& oldValue,
const QVariant& newValue);
void itemPropertyObjectNameChanged(const QString& oldName, const QString& newName);
void itemAdded(LimeReport::PageDesignIntf* page, LimeReport::BaseDesignIntf* item);
void itemRemoved(LimeReport::PageDesignIntf* page, LimeReport::BaseDesignIntf* item);
void bandAdded(LimeReport::PageDesignIntf* page, LimeReport::BandDesignIntf* band);

View File

@ -360,26 +360,29 @@ QGraphicsView* ReportDesignWidget::activeView(){
void ReportDesignWidget::connectPage(PageDesignIntf *page)
{
connect(page,SIGNAL(itemInserted(LimeReport::PageDesignIntf*,QPointF,QString)),this,SIGNAL(itemInserted(LimeReport::PageDesignIntf*,QPointF,QString)));
connect(page,SIGNAL(itemInsertCanceled(QString)),this,SIGNAL(itemInsertCanceled(QString)));
connect(page,SIGNAL(itemPropertyChanged(QString,QString,QVariant,QVariant)),this,SIGNAL(itemPropertyChanged(QString,QString,QVariant,QVariant)));
connect(page,SIGNAL(selectionChanged()),this,SLOT(slotSelectionChanged()));
connect(page,SIGNAL(insertModeStarted()),this,SIGNAL(insertModeStarted()));
connect(page,SIGNAL(commandHistoryChanged()),this,SIGNAL(commandHistoryChanged()));
connect(page,SIGNAL(sceneRectChanged(QRectF)),this,SLOT(slotSceneRectChanged(QRectF)));
connect(page,SIGNAL(itemAdded(LimeReport::PageDesignIntf*,LimeReport::BaseDesignIntf*)),
this, SIGNAL(itemAdded(LimeReport::PageDesignIntf*,LimeReport::BaseDesignIntf*)));
connect(page,SIGNAL(itemRemoved(LimeReport::PageDesignIntf*,LimeReport::BaseDesignIntf*)),
this,SIGNAL(itemDeleted(LimeReport::PageDesignIntf*,LimeReport::BaseDesignIntf*)));
connect(page,SIGNAL(bandAdded(LimeReport::PageDesignIntf*,LimeReport::BandDesignIntf*)),
this, SIGNAL(bandAdded(LimeReport::PageDesignIntf*,LimeReport::BandDesignIntf*)));
connect(page, SIGNAL(bandRemoved(LimeReport::PageDesignIntf*,LimeReport::BandDesignIntf*)),
this, SIGNAL(bandDeleted(LimeReport::PageDesignIntf*,LimeReport::BandDesignIntf*)));
connect(page, SIGNAL(itemInserted(LimeReport::PageDesignIntf*, QPointF, QString)),
this, SIGNAL(itemInserted(LimeReport::PageDesignIntf*, QPointF, QString)));
connect(page, SIGNAL(itemInsertCanceled(QString)),this,SIGNAL(itemInsertCanceled(QString)));
connect(page, SIGNAL(itemPropertyChanged(QString, QString, QVariant, QVariant)),
this, SIGNAL(itemPropertyChanged(QString, QString, QVariant, QVariant)));
connect(page, SIGNAL(itemPropertyObjectNameChanged(QString, QString)),
this, SLOT(slotItemPropertyObjectNameChanged(QString, QString)));
connect(page, SIGNAL(selectionChanged()), this, SLOT(slotSelectionChanged()));
connect(page, SIGNAL(insertModeStarted()), this, SIGNAL(insertModeStarted()));
connect(page, SIGNAL(commandHistoryChanged()), this, SIGNAL(commandHistoryChanged()));
connect(page, SIGNAL(sceneRectChanged(QRectF)), this, SLOT(slotSceneRectChanged(QRectF)));
connect(page, SIGNAL(itemAdded(LimeReport::PageDesignIntf*, LimeReport::BaseDesignIntf*)),
this, SIGNAL(itemAdded(LimeReport::PageDesignIntf*, LimeReport::BaseDesignIntf*)));
connect(page, SIGNAL(itemRemoved(LimeReport::PageDesignIntf*, LimeReport::BaseDesignIntf*)),
this, SIGNAL(itemDeleted(LimeReport::PageDesignIntf*, LimeReport::BaseDesignIntf*)));
connect(page, SIGNAL(bandAdded(LimeReport::PageDesignIntf*, LimeReport::BandDesignIntf*)),
this, SIGNAL(bandAdded(LimeReport::PageDesignIntf*, LimeReport::BandDesignIntf*)));
connect(page, SIGNAL(bandRemoved(LimeReport::PageDesignIntf*, LimeReport::BandDesignIntf*)),
this, SIGNAL(bandDeleted(LimeReport::PageDesignIntf*, LimeReport::BandDesignIntf*)));
connect(page, SIGNAL(pageUpdateFinished(LimeReport::PageDesignIntf*)),
this, SIGNAL(activePageUpdated(LimeReport::PageDesignIntf*)));
connect(page->pageItem(), SIGNAL(propertyObjectNameChanged(QString,QString)),
this, SLOT(slotPagePropertyObjectNameChanged(QString,QString)));
connect(page->pageItem(), SIGNAL(propertyObjectNameChanged(QString, QString)),
this, SLOT(slotPagePropertyObjectNameChanged(QString, QString)));
emit activePageChanged();
}
@ -964,6 +967,18 @@ void ReportDesignWidget::slotScriptTextChanged()
m_report->scriptContext()->setInitScript(m_scriptEditor->toPlainText());
}
void ReportDesignWidget::slotItemPropertyObjectNameChanged(const QString& oldName, const QString& newName)
{
PageDesignIntf* page = qobject_cast<PageDesignIntf*>(sender());
if (page){
ITranslationContainer* tc = dynamic_cast<ITranslationContainer*>(report());
for (int i = 0; i < tc->translations()->values().count(); ++i){
PageTranslation* pt = tc->translations()->values().at(i)->findPageTranslation(page->pageItem()->objectName());
if (pt) pt->renameItem(oldName, newName);
}
}
}
#ifdef HAVE_QTDESIGNER_INTEGRATION
void ReportDesignWidget::addNewDialog()
@ -995,6 +1010,11 @@ void ReportDesignWidget::slotDialogNameChanged(QString oldName, QString newName)
void ReportDesignWidget::slotPagePropertyObjectNameChanged(const QString &oldValue, const QString &newValue)
{
ITranslationContainer* tc = dynamic_cast<ITranslationContainer*>(report());
foreach(ReportTranslation* translation, tc->translations()->values()){
translation->renamePage(oldValue, newValue);
}
for (int i = 0; i < m_tabWidget->count(); ++i ){
if (m_tabWidget->tabText(i).compare(oldValue) == 0){
QGraphicsView* view = dynamic_cast<QGraphicsView*>(m_tabWidget->widget(i));

View File

@ -216,6 +216,7 @@ private slots:
void slotCurrentTabChanged(int index);
void slotReportLoaded();
void slotScriptTextChanged();
void slotItemPropertyObjectNameChanged(const QString& oldName, const QString& newName);
#ifdef HAVE_QTDESIGNER_INTEGRATION
void slotDialogChanged(QString);
void slotDialogNameChanged(QString oldName, QString newName);

View File

@ -224,9 +224,11 @@ void ReportEnginePrivate::showError(QString message)
void ReportEnginePrivate::updateTranslations()
{
foreach(ReportTranslation* translation, m_translations.values()){
translation->invalidatePages();
foreach(PageDesignIntf* page, m_pages){
translation->updatePageTranslation(page);
}
translation->clearInvalidPages();
}
}
@ -500,7 +502,7 @@ bool ReportEnginePrivate::exportReport(QString exporterName, const QString &file
return false;
}
bool ReportEnginePrivate::showPreviewWindow(ReportPages pages, PreviewHints hints)
bool ReportEnginePrivate::showPreviewWindow(ReportPages pages, PreviewHints hints, QPrinter* printer)
{
if (pages.count()>0){
Q_Q(ReportEngine);
@ -515,6 +517,7 @@ bool ReportEnginePrivate::showPreviewWindow(ReportPages pages, PreviewHints hint
w->setPages(pages);
w->setLayoutDirection(m_previewLayoutDirection);
w->setStyleSheet(styleSheet());
// w->setDefaultPrinter()
if (!dataManager()->errorsList().isEmpty()){
w->setErrorMessages(dataManager()->errorsList());
@ -550,14 +553,13 @@ void ReportEnginePrivate::previewReport(PreviewHints hints)
previewReport(0, hints);
}
void ReportEnginePrivate::previewReport(QPrinter *printer, PreviewHints hints)
void ReportEnginePrivate::previewReport(QPrinter* printer, PreviewHints hints)
{
// QTime start = QTime::currentTime();
try{
dataManager()->setDesignTime(false);
ReportPages pages = renderToPages();
dataManager()->setDesignTime(true);
showPreviewWindow(pages, hints);
showPreviewWindow(pages, hints, printer);
} catch (ReportError &exception){
saveError(exception.what());
showError(exception.what());
@ -980,7 +982,12 @@ IPreparedPages *ReportEnginePrivate::preparedPages(){
bool ReportEnginePrivate::showPreparedPages(PreviewHints hints)
{
return showPreviewWindow(m_preparedPages, hints);
return showPreparedPages(0, hints);
}
bool ReportEnginePrivate::showPreparedPages(QPrinter* defaultPrinter, PreviewHints hints)
{
return showPreviewWindow(m_preparedPages, hints, defaultPrinter);
}
bool ReportEnginePrivate::prepareReportPages()

View File

@ -246,6 +246,7 @@ public:
void clearWatermarks();
IPreparedPages* preparedPages();
bool showPreparedPages(PreviewHints hints);
bool showPreparedPages(QPrinter *defaultPrinter, PreviewHints hints);
bool prepareReportPages();
bool printPreparedPages();
signals:
@ -273,7 +274,7 @@ public slots:
void cancelRender();
protected:
PageDesignIntf* createPage(const QString& pageName="", bool preview = false);
bool showPreviewWindow(ReportPages pages, PreviewHints hints);
bool showPreviewWindow(ReportPages pages, PreviewHints hints, QPrinter *printer);
protected slots:
void slotDataSourceCollectionLoaded(const QString& collectionName);
private slots:

View File

@ -189,7 +189,7 @@ void ReportRender::initDatasource(const QString& name){
}
}
void ReportRender::renderPage(PageItemDesignIntf* patternPage, bool isTOC, bool isFirst, bool resetPageNumbers)
void ReportRender::renderPage(PageItemDesignIntf* patternPage, bool isTOC, bool /*isFirst*/, bool /*resetPageNumbers*/)
{
m_currentNameIndex = 0;
m_patternPageItem = patternPage;

View File

@ -116,7 +116,7 @@ private:
void initGroups();
void clearPageMap();
void renderPage(PageItemDesignIntf *patternPage, bool isTOC = false, bool isFirst = false, bool resetPageNumbers = false);
void renderPage(PageItemDesignIntf *patternPage, bool isTOC = false, bool isFirst = false, bool = false);
BandDesignIntf* renderBand(BandDesignIntf *patternBand, BandDesignIntf *bandData, DataRenderMode mode = NotStartNewPage, bool isLast = false);
void renderDataBand(BandDesignIntf* dataBand);
void renderPageHeader(PageItemDesignIntf* patternPage);

View File

@ -32,6 +32,7 @@ ReportTranslation::~ReportTranslation()
PageTranslation* ReportTranslation::createPageTranslation(PageDesignIntf* page)
{
PageTranslation* pageTranslation = new PageTranslation;
pageTranslation->checked = true;
pageTranslation->pageName = page->pageItem()->objectName();
foreach(BaseDesignIntf* item, page->pageItem()->allChildBaseItems()){
createItemTranslation(item, pageTranslation);
@ -43,6 +44,7 @@ void ReportTranslation::createItemTranslation(BaseDesignIntf* item, PageTranslat
QMap<QString,QString> stringsForTranslation = item->getStringForTranslation();
if (!stringsForTranslation.isEmpty()){
ItemTranslation* itemTranslation = new ItemTranslation;
itemTranslation->checked = true;
itemTranslation->itemName = item->objectName();
foreach(QString propertyName, stringsForTranslation.keys()){
PropertyTranslation* propertyTranslation = new PropertyTranslation;
@ -57,16 +59,42 @@ void ReportTranslation::createItemTranslation(BaseDesignIntf* item, PageTranslat
}
}
PageTranslation* ReportTranslation::findPageTranslation(const QString& page_name)
PageTranslation* ReportTranslation::findPageTranslation(const QString& pageName)
{
foreach(PageTranslation* page, m_pagesTranslation){
if (page->pageName.compare(page_name) == 0){
if (page->pageName.compare(pageName) == 0){
return page;
}
}
return 0;
}
void ReportTranslation::renamePage(const QString &oldName, const QString &newName)
{
PageTranslation* page = findPageTranslation(oldName);
if (page){
page->pageName = newName;
}
}
void ReportTranslation::invalidatePages()
{
foreach(PageTranslation* page, m_pagesTranslation){
page->checked = false;
}
}
void ReportTranslation::clearInvalidPages()
{
QList<PageTranslation*>::Iterator it = m_pagesTranslation.begin();
while (it != m_pagesTranslation.end()){
if (!(*it)->checked){
delete *it;
it = m_pagesTranslation.erase(it);
} else ++it;
}
}
void ReportTranslation::updatePageTranslation(PageDesignIntf* page)
{
PageTranslation* pageTranslation = findPageTranslation(page->pageItem()->objectName());
@ -75,6 +103,10 @@ void ReportTranslation::updatePageTranslation(PageDesignIntf* page)
m_pagesTranslation.append(pageTranslation);
}
if (pageTranslation){
pageTranslation->checked = true;
foreach(ItemTranslation* item, pageTranslation->itemsTranslation){
item->checked = false;
}
foreach(BaseDesignIntf* item, page->pageItem()->allChildBaseItems()){
QMap<QString,QString> stringsForTranslation = item->getStringForTranslation();
if (!stringsForTranslation.isEmpty()){
@ -90,15 +122,23 @@ void ReportTranslation::updatePageTranslation(PageDesignIntf* page)
propertyTranslation->sourceValue = stringsForTranslation.value(propertyName);
if (!translated) propertyTranslation->value = propertyTranslation->sourceValue;
}
itemTranslation->checked = true;
} else {
createItemTranslation(item, pageTranslation);
}
}
}
QHash<QString, ItemTranslation*>::Iterator it = pageTranslation->itemsTranslation.begin();
while( it != pageTranslation->itemsTranslation.end()){
if (!it.value()->checked) {
delete it.value();
it = pageTranslation->itemsTranslation.erase(it);
} else ++it;
}
}
}
QList<PageTranslation*> ReportTranslation::pagesTranslation() const
QList<PageTranslation*>& ReportTranslation::pagesTranslation()
{
return m_pagesTranslation;
}
@ -139,4 +179,14 @@ PageTranslation::~PageTranslation()
}
}
void PageTranslation::renameItem(const QString &oldName, const QString &newName)
{
ItemTranslation* item = itemsTranslation.value(oldName);
if (item){
itemsTranslation.remove(oldName);
item->itemName = newName;
itemsTranslation[newName] = item;
}
}
} //namespace LimeReport

View File

@ -31,6 +31,7 @@ struct PropertyTranslation{
struct ItemTranslation{
QString itemName;
bool checked;
PropertyTranslation* findProperty(const QString& propertyName);
~ItemTranslation();
QList<PropertyTranslation*> propertyesTranslation;
@ -38,8 +39,10 @@ struct ItemTranslation{
struct PageTranslation{
QString pageName;
bool checked;
~PageTranslation();
QHash<QString,ItemTranslation*> itemsTranslation;
void renameItem(const QString& oldName, const QString& newName);
QHash<QString, ItemTranslation*> itemsTranslation;
};
class ReportTranslation{
@ -49,12 +52,15 @@ public:
ReportTranslation(const ReportTranslation& reportTranslation);
~ReportTranslation();
QLocale::Language language() const;
QList<PageTranslation*> pagesTranslation() const;
QList<PageTranslation *> &pagesTranslation();
PageTranslation* createEmptyPageTranslation();
void updatePageTranslation(PageDesignIntf* page);
PageTranslation* findPageTranslation(const QString& page_name);
void createItemTranslation(BaseDesignIntf* item, PageTranslation* pageTranslation);
PageTranslation* findPageTranslation(const QString& pageName);
void renamePage(const QString& oldName, const QString& newName);
void invalidatePages();
void clearInvalidPages();
private:
void createItemTranslation(BaseDesignIntf* item, PageTranslation* pageTranslation);
PageTranslation* createPageTranslation(PageDesignIntf* page);
private:
QLocale::Language m_language;

View File

@ -11,7 +11,8 @@ namespace LimeReport {
TranslationEditor::TranslationEditor(QWidget *parent) :
QWidget(parent),
ui(new Ui::TranslationEditor), m_translationContainer(0),
m_currentReportTranslation(0), m_currentPageTranslation(0), m_currentPropertyTranslation(0)
m_currentReportTranslation(0), m_currentPageTranslation(0),
m_currentPropertyTranslation(0), m_translationChanging(false)
{
ui->setupUi(this);
ui->splitter_3->setStretchFactor(1,10);
@ -78,11 +79,10 @@ void TranslationEditor::updateUi()
ui->lvLanguages->addItem(QLocale::languageToString(language));
}
if (!translations->keys().isEmpty()){
if (ui->lvLanguages->count()!=0){
if (ui->lvLanguages->count() != 0){
ui->lvLanguages->item(0)->setSelected(true);
activateLanguage(getLanguageByName(ui->lvLanguages->item(0)->text()));
} else {
//activateLanguage(QLocale::AnyLanguage);
ui->twPages->clear();
ui->tbStrings->setRowCount(0);
}
@ -93,7 +93,9 @@ void TranslationEditor::updateUi()
void TranslationEditor::activateLanguage(QLocale::Language language)
{
m_translationChanging = true;
ui->teTranslation->setEnabled(false);
ui->teTranslation->setPlainText("");
ui->cbChecked->setEnabled(false);
ui->twPages->clear();
Translations* translations = m_translationContainer->translations();
@ -113,6 +115,7 @@ void TranslationEditor::activateLanguage(QLocale::Language language)
activatePage(m_currentReportTranslation->findPageTranslation(ui->twPages->topLevelItem(0)->text(0)));
}
}
m_translationChanging = false;
}
void TranslationEditor::activatePage(PageTranslation* pageTranslation)
@ -171,13 +174,13 @@ void TranslationEditor::activateTranslation(const QString& itemName, const QStri
void TranslationEditor::on_tbStrings_itemSelectionChanged()
{
if (m_currentPageTranslation)
if (m_currentPageTranslation && !m_translationChanging)
activateTranslation(ui->tbStrings->item(ui->tbStrings->currentRow(),1)->text(), ui->tbStrings->item(ui->tbStrings->currentRow(),2)->text());
}
void TranslationEditor::on_teTranslation_textChanged()
{
if (m_currentPropertyTranslation)
if (m_currentPropertyTranslation && !m_translationChanging)
m_currentPropertyTranslation->value = ui->teTranslation->toPlainText();
}
@ -200,16 +203,23 @@ void TranslationEditor::on_tbAddLanguage_clicked()
{
LanguageSelectDialog dialog;
if (dialog.exec()){
m_translationChanging = true;
m_translationContainer->addTranslationLanguage(dialog.getSelectedLanguage());
updateUi();
activateLanguage(dialog.getSelectedLanguage());
foreach (QListWidgetItem* item, ui->lvLanguages->findItems(QLocale::languageToString(dialog.getSelectedLanguage()), Qt::MatchExactly)){
item->setSelected(true);
}
m_translationChanging = false;
}
}
void TranslationEditor::on_tbDeleteLanguage_clicked()
{
m_translationChanging = true;
m_translationContainer->removeTranslationLanguage(m_currentReportTranslation->language());
updateUi();
m_translationChanging = false;
}
void TranslationEditor::slotItemChecked()

View File

@ -45,6 +45,7 @@ private:
ReportTranslation* m_currentReportTranslation;
PageTranslation* m_currentPageTranslation;
PropertyTranslation* m_currentPropertyTranslation;
bool m_translationChanging;
};
} //namespace LimeReport