MainWindow::MainWindow() { mainWindow.setupUi(this); chartWidget = new ResultsChartWidget(mainWindow.centralwidget); chartWidget->setObjectName(QString::fromUtf8("widget")); chartWidget->setGeometry(QRect(10, 280, 780, 300)); chartWidget->setChartType(histogram); mainWindow.timeHistogram->setChecked(true); QObject::connect(mainWindow.About_StringMatching, SIGNAL(triggered()), this, SLOT(showAboutDialog())); QObject::connect(mainWindow.chooseFileButton, SIGNAL(clicked()), this, SLOT(chooseTextFile())); QObject::connect(mainWindow.processButton, SIGNAL(clicked()), this, SLOT(processFile())); QObject::connect(mainWindow.timeHistogram, SIGNAL(clicked()), this, SLOT(setChartType())); QObject::connect(mainWindow.pattVsFileVsTime, SIGNAL(clicked()), this, SLOT(setChartType())); QObject::connect(mainWindow.clearResultsButton, SIGNAL(clicked()), this, SLOT(clearResults())); fileLoaded = false; generalLock = false; }
ChartShape::ChartShape(KoDocumentResourceManager *resourceManager) : KoFrameShape(KoXmlNS::draw, "object") , KoShapeContainer(new ChartLayout) , d (new Private(this)) { d->resourceManager = resourceManager; setShapeId(ChartShapeId); // Instantiated all children first d->proxyModel = new ChartProxyModel(this, &d->tableSource); d->plotArea = new PlotArea(this); d->document = new ChartDocument(this); d->legend = new Legend(this); // Configure the plotarea. // We need this as the very first step, because some methods // here rely on the d->plotArea pointer. addShape(d->plotArea); d->plotArea->plotAreaInit(); d->plotArea->setZIndex(0); setClipped(d->plotArea, true); setInheritsTransform(d->plotArea, true); // Configure the legend. d->legend->setVisible(true); d->legend->setZIndex(1); setClipped(d->legend, true); setInheritsTransform(d->legend, true); // A few simple defaults (chart type and subtype in this case) setChartType(BarChartType); setChartSubType(NormalChartSubtype); // Create the Title, which is a standard TextShape. KoShapeFactoryBase *textShapeFactory = KoShapeRegistry::instance()->value(TextShapeId); if (textShapeFactory) d->title = textShapeFactory->createDefaultShape(resourceManager); // Potential problem 1) No TextShape installed if (!d->title) { d->title = new TextLabelDummy; if (ENABLE_USER_INTERACTION) KMessageBox::error(0, i18n("The plugin needed for displaying text labels in a chart is not available."), i18n("Plugin Missing")); // Potential problem 2) TextShape incompatible } else if (dynamic_cast<TextLabelData*>(d->title->userData()) == 0 && ENABLE_USER_INTERACTION) KMessageBox::error(0, i18n("The plugin needed for displaying text labels is not compatible with the current version of the chart Flake shape."), i18n("Plugin Incompatible")); // In both cases we need a KoTextShapeData instance to function. This is // enough for unit tests, so there has to be no TextShape plugin doing the // actual text rendering, we just need KoTextShapeData which is in the libs. if (dynamic_cast<TextLabelData*>(d->title->userData()) == 0) { TextLabelData *dataDummy = new TextLabelData; KoTextDocumentLayout *documentLayout = new KoTextDocumentLayout(dataDummy->document()); dataDummy->document()->setDocumentLayout(documentLayout); d->title->setUserData(dataDummy); } // Start with a reasonable default size that we can base all following relative // positions of chart elements on. setSize(QSizeF(CM_TO_POINT(8), CM_TO_POINT(5))); // Add the title to the shape addShape(d->title); QFont font = titleData()->document()->defaultFont(); font.setPointSizeF(12.0); titleData()->document()->setDefaultFont(font); titleData()->document()->setHtml("<div align=\"center\">" + i18n("Title") + "</font></div>"); // Position the title center at the very top. d->title->setSize(QSizeF(CM_TO_POINT(5), CM_TO_POINT(0.7))); d->title->setPosition(QPointF(size().width() / 2.0 - d->title->size().width() / 2.0, 0.0)); d->title->setVisible(false); d->title->setZIndex(2); setClipped(d->title, true); setInheritsTransform(d->title, true); // Create the Subtitle and add it to the shape. if (textShapeFactory) d->subTitle = textShapeFactory->createDefaultShape(resourceManager); if (!d->subTitle) { d->subTitle = new TextLabelDummy; } if (dynamic_cast<TextLabelData*>(d->subTitle->userData()) == 0) { TextLabelData *dataDummy = new TextLabelData; KoTextDocumentLayout *documentLayout = new KoTextDocumentLayout(dataDummy->document()); dataDummy->document()->setDocumentLayout(documentLayout); d->subTitle->setUserData(dataDummy); } addShape(d->subTitle); font = subTitleData()->document()->defaultFont(); font.setPointSizeF(10.0); subTitleData()->document()->setDefaultFont(font); subTitleData()->document()->setHtml("<div align=\"center\">" + i18n("Subtitle") + "</div>"); // Position it in the center, just below the title. d->subTitle->setSize(QSizeF(CM_TO_POINT(5), CM_TO_POINT(0.6))); d->subTitle->setPosition(QPointF(size().width() / 2.0 - d->title->size().width() / 2.0, d->title->size().height())); d->subTitle->setVisible(false); d->subTitle->setZIndex(3); setClipped(d->subTitle, true); setInheritsTransform(d->subTitle, true); // Create the Footer and add it to the shape. if (textShapeFactory) d->footer = textShapeFactory->createDefaultShape(resourceManager); if (!d->footer) { d->footer = new TextLabelDummy; } if (dynamic_cast<TextLabelData*>(d->footer->userData()) == 0) { TextLabelData *dataDummy = new TextLabelData; KoTextDocumentLayout *documentLayout = new KoTextDocumentLayout(dataDummy->document()); dataDummy->document()->setDocumentLayout(documentLayout); d->footer->setUserData(dataDummy); } addShape(d->footer); font = footerData()->document()->defaultFont(); font.setPointSizeF(10.0); footerData()->document()->setDefaultFont(font); footerData()->document()->setHtml("<div align=\"center\">" + i18n("Footer") + "</div>"); // Position the footer in the center, at the bottom. d->footer->setSize(QSizeF(CM_TO_POINT(5), CM_TO_POINT(0.6))); d->footer->setPosition(QPointF(size().width() / 2.0 - d->footer->size().width() / 2.0, size().height() - d->footer->size().height())); d->footer->setVisible(false); d->footer->setZIndex(4); setClipped(d->footer, true); setInheritsTransform(d->footer, true); // Set default contour (for how text run around is done around this shape) // to prevent a crash in LO setTextRunAroundContour(KoShape::ContourBox); // Enable auto-resizing of chart labels foreach(KoShape *label, labels()) { TextLabelData *labelData = qobject_cast<TextLabelData*>(label->userData()); KoTextDocument doc(labelData->document()); //FIXME doc.setResizeMethod(KoTextDocument::AutoResize); }